Inventory_Presser_Location_Address::form( array $instance )
form
Contents
Description Description
Outputs the widget settings form that is shown in the dashboard.
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( 'location', array( '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">Select Addresses to Display</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>', $this->get_field_id( 'cb_title' ), $this->get_field_name( 'cb_display[]' ), $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, nl2br( $term_object->description ) ); } $address_table .= '</tbody></table>'; // Widget admin form ?> <p> <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( '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> <input type="checkbox" id="<?php echo $this->get_field_id( 'cb_single_line' ); ?>" name="<?php echo $this->get_field_name( 'cb_single_line' ); ?>" value="true"<?php checked( ( isset( $instance['cb_single_line'] ) && $instance['cb_single_line'] == 'true' ) ); ?>> <label for="<?php echo $this->get_field_id( 'cb_single_line' ); ?>"><?php _e( 'Single Line Display', 'inventory-presser' ); ?></label> </p> <p><?php echo $address_table; ?></p> <?php }
Expand full source code Collapse full source code View on Github