Inventory_Presser_Map_Widget::form( array $instance )

form


Description Description

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


Top ↑

Parameters Parameters

$instance

(array) (Required)


Top ↑

Return Return

(void)


Top ↑

Source Source

File: includes/class-widget-map.php

	public function form( $instance ) {

		$title = isset( $instance['title'] ) ? $instance['title'] : '';

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

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

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

		// loop through each location, set up form
		foreach( $location_terms as $index => $term_object ) {
			printf(
				'<p><input id="%s" name="%s[]" value="%s" type="checkbox"%s> <label for="%s">%s</label></p>',
				$this->get_field_id( $term_object->slug ),
				$this->get_field_name('location_slug'),
				$term_object->slug,
				checked( true, in_array( $term_object->slug, $location_slug ), false ),
				$this->get_field_id( $term_object->slug ),
				str_replace( "\r", '', str_replace( PHP_EOL, ', ', $term_object->description ) )
			);
		}

		//Only show this if the API key is missing
		$settings = INVP::settings();
		if( empty( $settings['mapbox_public_token'] ) )
		{
			printf( '<p>%s</p>', __( 'An API token from mapbox.com is required for this widget to work. Obtain a key at mapbox.com and save it on the Inventory Presser Options page.', 'inventory-presser' ) );
		}
	}