Inventory_Presser_Location_Phones::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-phones.php

	public function form( $instance )
	{
		$cb_display = isset($instance['cb_display']) ? $instance['cb_display'] : array();
		// get all locations
		$location_info = get_terms('location', array('fields'=>'id=>name', 'hide_empty'=>false));
		$phones_table = '<table><tbody>';

		// loop through each location, set up form
		foreach( $location_info as $term_id => $name )
		{
			//Output a checkbox for every phone number in this location
			for( $p=1; $p<=Inventory_Presser_Taxonomies::LOCATION_MAX_PHONES; $p++ )
			{
				//Is there a phone number in this slot?
				$phone_uid = get_term_meta( $term_id, 'phone_' . $p . '_uid', true );
				if( ! $phone_uid )
				{
					//No, we're done with this location
					break;
				}

				//Only do this once per location
				if( 1 == $p )
				{
					$phones_table .= sprintf('<tr><td colspan="3"><strong>%s</strong></td></tr>', $name);
				}

				$number = get_term_meta( $term_id, 'phone_' . $p . '_number', true );
				$description = get_term_meta( $term_id, 'phone_' . $p . '_description', true );
				$checkbox_id = $this->get_field_id( 'cb_display_' . $phone_uid );

				$cb_display_text = sprintf(
					'<input type="checkbox" id="%s" name="%s" value="%s"%s />',
					$checkbox_id,
					$this->get_field_name( 'cb_display[' . $term_id . '][]' ),
					$phone_uid,
					checked( (isset($cb_display[$term_id]) && is_array($cb_display[$term_id]) && in_array($phone_uid, $cb_display[$term_id])), true, false )
				);

				$phones_table .= sprintf(
					'<tr><td>%s</td><td><label for="%s">%s</label></td><td><label for="%s">%s</label></td></tr>',
					$cb_display_text,
					$checkbox_id,
					$description,
					$checkbox_id,
					$number
				);
			}
		}

		$phones_table .= '</tbody></table>';

		// Widget admin form
		$title = isset($instance['title']) ? $instance['title'] : '';
		?>
		<p>
			<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title (optional):', '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>
			<label for="<?php echo $this->get_field_id('format'); ?>"><?php _e( 'Display Format:', 'inventory-presser' ); ?></label>
			<select class="widefat" id="<?php echo $this->get_field_id('format'); ?>" name="<?php echo $this->get_field_name('format'); ?>">
			<?php
			$format = isset($instance['format']) ? $instance['format'] : current( array_keys( $this->formats() ) );
			foreach ($this->formats() as $key => $format_array) {
				printf(
					'<option value="%s"%s>%s</option>',
					$key,
					selected( $format == $key, true, false ),
					$format_array['selector']
				);
			}
			?>
			</select>
		</p>
		<p><?php echo $phones_table; ?></p>
		<?php
	}