Inventory_Presser_Location_Hours::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-hours.php

	public function form( $instance )
	{
		$cb_display = isset($instance['cb_display']) ? $instance['cb_display'] : array();
		$cb_title = isset($instance['cb_title']) ? $instance['cb_title'] : array();

		// get all locations
		$location_info = get_terms('location', array('fields'=>'id=>name', 'hide_empty'=>false));

		$hours_table = '<table><tbody>';

		// loop through each location, set up form
		foreach ( $location_info as $term_id => $name )
		{
			//Output a checkbox for every set of hours in this location
			for( $h=1; $h<=Inventory_Presser_Taxonomies::LOCATION_MAX_HOURS; $h++ )
			{
				//Are there hours in this slot?
				$hours_uid = get_term_meta( $term_id, 'hours_' . $h . '_uid', true );
				if( ! $hours_uid )
				{
					//No, we're done with this location
					break;
				}

				//Only do this once per location
				if( 1 == $h )
				{
					$hours_table .= sprintf(
						'<tr><td>%s</td><td>%s</td><td>%s</td></tr>',
						$name,
						__( 'Display', 'inventory-presser' ),
						__( 'Title', 'inventory-presser' )
					);
				}

				$title = get_term_meta( $term_id, 'hours_' . $h . '_title', true );
				if( empty( $title ) )
				{
					$title =  __( 'No title entered', 'inventory-presser' );
				}

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

				$cb_title_text = sprintf(
					'<input type="checkbox" id="%s" name="%s" value="%s"%s />',
					$this->get_field_id('cb_title_' . $hours_uid ),
					$this->get_field_name('cb_title['.$term_id.'][]'),
					$hours_uid,
					checked( true, (isset($cb_title[$term_id]) && is_array($cb_title[$term_id]) && in_array($hours_uid, $cb_title[$term_id])), false )
				);

				$hours_table .= sprintf(
					'<tr><td><strong>%s</strong></td><td>%s</td><td>%s</td></tr>',
					$title,
					$cb_display_text,
					$cb_title_text
				);
			}
		}

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

		// Widget admin form
		$title = isset($instance[ 'title' ]) ? $instance[ 'title' ] : __( 'Hours', 'inventory-presser' );
		?>
		<p>
		<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e( 'Main 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>
		<label for="<?php echo $this->get_field_id('cb_showclosed'); ?>"><?php _e( 'Show All Closed Days', 'inventory-presser' ); ?></label>
		<input type="checkbox" id="<?php echo $this->get_field_id('cb_showclosed'); ?>" name="<?php echo $this->get_field_name('cb_showclosed'); ?>" value="true"<?php checked( (isset($instance[ 'cb_showclosed' ]) && $instance[ 'cb_showclosed' ] == 'true') ); ?>>
		</p>
		<p><?php echo $hours_table; ?></p>
		<?php
	}