Inventory_Presser_Location_Phones::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-phones.php
public function form( $instance ) {
$cb_display = isset( $instance['cb_display'] ) ? $instance['cb_display'] : array();
// get all locations.
$location_info = get_terms(
array(
'taxonomy' => 'location',
'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 <= INVP::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>', esc_html( $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 />',
esc_attr( $checkbox_id ),
esc_attr( $this->get_field_name( 'cb_display[' . $term_id . '][]' ) ),
esc_attr( $phone_uid ),
checked( ( isset( $cb_display[ $term_id ] ) && is_array( $cb_display[ $term_id ] ) && in_array( $phone_uid, $cb_display[ $term_id ], true ) ), 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,
esc_attr( $checkbox_id ),
esc_html( $description ),
esc_attr( $checkbox_id ),
esc_html( $number )
);
}
}
$phones_table .= '</tbody></table>';
// Widget admin form.
$title = isset( $instance['title'] ) ? $instance['title'] : '';
?>
<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_html_e( 'Title (optional):', '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( 'format' ) ); ?>"><?php esc_html_e( 'Display Format:', 'inventory-presser' ); ?></label>
<select class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'format' ) ); ?>" name="<?php echo esc_attr( $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>',
esc_attr( $key ),
selected( $format == $key, true, false ),
esc_html( $format_array['selector'] )
);
}
?>
</select>
</p>
<p><?php echo wp_kses_post( $phones_table ); ?></p>
<?php
}
Expand full source codeCollapse full source codeView on Github