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/widget/class-widget-hours.php

				'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 <= INVP::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 ], true ) ), 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 ], true ) ), 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 esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_html_e( 'Main 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>

		<p>
		<label for="<?php echo esc_attr( $this->get_field_id( 'cb_showclosed' ) ); ?>"><?php esc_html_e( 'Show All Closed Days', 'inventory-presser' ); ?></label>
		<input type="checkbox" id="<?php echo esc_attr( $this->get_field_id( 'cb_showclosed' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'cb_showclosed' ) ); ?>" value="true"<?php checked( ( isset( $instance['cb_showclosed'] ) && 'true' === $instance['cb_showclosed'] ) ); ?>>
		</p>
		<p><?php echo $hours_table; ?></p>
		<?php
	}

	/**
	 * Saves the widget settings when a dashboard user clicks the Save button.
	 *
	 * @param  array $new_instance
	 * @param  array $old_instance
	 * @return array The updated array full of settings
	 */