Inventory_Presser_Google_Maps_Widget_V3::form( array $instance )

Outputs the widget settings form that is shown in the dashboard.

On This Page


Parameters Parameters

$instance

(array) (Required)


Top ↑

Return Return

(void)


Top ↑

Source Source

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

	public function form( $instance ) {

		$title   = $instance['title'] ?? '';
		$api_key = $instance['api_key'] ?? '';

		// Title. ?><p>
			<label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_html_e( 'Title:', 'inventory-presser' ); ?></label>
			<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
		</p>
		<?php

		// API Key.
		?>
		<p>
			<label for="<?php echo esc_attr( $this->get_field_id( 'api_key' ) ); ?>"><?php esc_html_e( 'API Key:', 'inventory-presser' ); ?></label>
			<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'api_key' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'api_key' ) ); ?>" type="text" value="<?php echo esc_attr( $api_key ); ?>" />
			<p class="description">
			<?php

				printf(
					'%s <a href="https://developers.google.com/maps/documentation/javascript/get-api-key">%s</a>',
					esc_html__( 'Obtain an API key at', 'inventory-presser' ),
					esc_html__( 'Google Cloud Console', 'inventory-presser' )
				);

			?>
									</p>
		</p>
		<p><?php esc_html_e( 'Choose addresses to mark:', 'inventory-presser' ); ?></p>
												<?php

													// get all location terms.
													$location_terms = get_terms(
														array(
															'taxonomy'   => 'location',
															'hide_empty' => false,
														)
													);

													$location_slugs = isset( $instance['location_slugs'] ) ? $instance['location_slugs'] : array();
												if ( ! is_array( $location_slugs ) ) {
													$location_slugs = array( $location_slugs );
												}

													// loop through each location, set up form.
												foreach ( $location_terms as $index => $term_object ) {
													printf(
														'<p><input id="%1$s" name="%2$s[]" value="%3$s" type="checkbox"%4$s> <label for="%1$s">%5$s</label></p>',
														esc_attr( $this->get_field_id( $term_object->slug ) ),
														esc_attr( $this->get_field_name( 'location_slugs' ) ),
														esc_attr( $term_object->slug ),
														checked( in_array( $term_object->slug, $location_slugs, true ), true, false ),
														esc_html( $term_object->description )
													);
												}
	}