Inventory_Presser_Location_Hours::form( array $instance )
Outputs the widget settings form that is shown in the dashboard.
On This Page
Parameters Parameters
- $instance
-
(array) (Required)
Return Return
(void)
Source Source
File: includes/widget/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(
array(
'taxonomy' => 'location',
'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>',
esc_html( $name ),
esc_html__( 'Display', 'inventory-presser' ),
esc_html__( '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 />',
esc_attr( $this->get_field_id( 'cb_display_' . $hours_uid ) ),
esc_attr( $this->get_field_name( 'cb_display[' . $term_id . '][]' ) ),
esc_attr( $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 />',
esc_attr( $this->get_field_id( 'cb_title_' . $hours_uid ) ),
esc_attr( $this->get_field_name( 'cb_title[' . $term_id . '][]' ) ),
esc_attr( $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>',
esc_html( $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
}
Expand full source codeCollapse full source codeView on Github