Inventory_Presser_Location_Address::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-address.php
public function form( $instance ) {
$title = isset( $instance['title'] ) ? $instance['title'] : '';
// get all locations.
$location_terms = get_terms(
array(
'taxonomy' => 'location',
'hide_empty' => false,
)
);
// set.
if ( isset( $instance['cb_display'] ) ) {
$cb_display = $instance['cb_display'];
} else {
// majority of dealers will have one address, let's precheck it for them.
if ( count( $location_terms ) == 1 ) {
$cb_display = array( $location_terms[0]->term_id );
} else {
$cb_display = array();
}
}
$address_table = '<table><tbody>'
. '<tr><td colspan="2">'
. esc_html__( 'Select Addresses to Display', 'inventory-presser' )
. '</td></tr>';
// loop through each location, set up form.
foreach ( $location_terms as $index => $term_object ) {
$address_checkbox = sprintf(
'<input id="%s" name="%s" value="%s" type="checkbox"%s>',
esc_attr( $this->get_field_id( 'cb_title' ) ),
esc_attr( $this->get_field_name( 'cb_display[]' ) ),
esc_attr( $term_object->term_id ),
checked( ( in_array( $term_object->term_id, $cb_display ) ), true, false )
);
$address_table .= sprintf( '<tr><td>%s</td><td>%s</td></tr>', $address_checkbox, wp_kses_post( nl2br( $term_object->description ) ) );
}
$address_table .= '</tbody></table>';
// Widget admin form.
?>
<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_html_e( '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>
<input type="checkbox" id="<?php echo esc_attr( $this->get_field_id( 'cb_single_line' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'cb_single_line' ) ); ?>" value="true"<?php checked( ( isset( $instance['cb_single_line'] ) && 'true' === $instance['cb_single_line'] ) ); ?>>
<label for="<?php echo esc_attr( $this->get_field_id( 'cb_single_line' ) ); ?>"><?php esc_html_e( 'Single Line Display', 'inventory-presser' ); ?></label>
</p>
<p><?php echo wp_kses_post( $address_table ); ?></p>
<?php
}
Expand full source codeCollapse full source codeView on Github