Inventory_Presser_Google_Maps_Widget::widget( array $args, array $instance )

widget

Description Description

Outputs the widget front-end HTML


Top ↑

Parameters Parameters

$args

(array) (Required)

$instance

(array) (Required)


Top ↑

Return Return

(void)


Top ↑

Source Source

File: includes/widget/class-widget-google-maps.php

	public function widget( $args, $instance ) {
		// abort if we don't have an address to show
		if ( empty( $instance['location_slug'] ) ) {
			return;
		}

		$location = get_term_by( 'slug', $instance['location_slug'], 'location' );
		if ( ! $location ) {
			return;
		}

		// before and after widget arguments are defined by themes
		echo $args['before_widget'];

		$title = apply_filters( 'widget_title', $instance['title'] );
		if ( ! empty( $title ) ) {
			echo $args['before_title'] . $title . $args['after_title'];
		}

		// remove line breaks from the term description
		$address_to_search = preg_replace( '#\R+#', ', ', $location->description );

		printf(
			'<div class="invp-google-maps"><iframe frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.com/maps?q=%s&t=m&z=%d&output=embed" aria-label="%s"></iframe></div>',
			rawurlencode( $address_to_search ),
			'13',
			esc_attr( $address_to_search )
		);

		echo $args['after_widget'];
	}