Inventory_Presser_Location_Phones::widget( array $args, array $instance )
Outputs the widget front-end HTML
On This Page
Parameters Parameters
- $args
-
(array) (Required)
- $instance
-
(array) (Required)
Return Return
(void)
Source Source
File: includes/widget/class-widget-phones.php
public function widget( $args, $instance ) { if ( empty( $instance['cb_display'] ) || ! is_array( $instance['cb_display'] ) ) { return; } // before and after widget arguments are defined by themes. echo $args['before_widget']; $title = apply_filters( 'widget_title', $instance['title'] ); if ( ! empty( $title ) ) { echo $args['before_title'] . $title . $args['after_title']; } $format_slugs = array_keys( $this->formats() ); $format = in_array( $instance['format'], $format_slugs ) ? $instance['format'] : $format_slugs[0]; printf( '<div class="invp-%s">%s', $format, $this->formats()[ $format ]['before'] ); // loop through each location. $location_info = get_terms( array( 'taxonomy' => 'location', 'fields' => 'id=>name', 'hide_empty' => false, ) ); foreach ( $location_info as $term_id => $name ) { // Does this address even have a phone number displayed by this instance of this widget? if ( empty( $instance['cb_display'][ $term_id ] ) ) { // No. continue; } for ( $p = 1; $p <= INVP::LOCATION_MAX_PHONES; $p++ ) { $phone_uid = get_term_meta( $term_id, 'phone_' . $p . '_uid', true ); if ( ! $phone_uid ) { break; } // There is a phone number is slot $p, has the user configured this widget to display it? if ( in_array( $phone_uid, $instance['cb_display'][ $term_id ], true ) ) { // Yes, output this number. $number = get_term_meta( $term_id, 'phone_' . $p . '_number', true ); if ( $this->formats()[ $format ]['uses_labels'] ) { $description = get_term_meta( $term_id, 'phone_' . $p . '_description', true ); printf( $this->formats()[ $format ]['repeater'], $description, INVP::prepare_phone_number_for_link( $number ), $number ); } else { printf( $this->formats()[ $format ]['repeater'], INVP::prepare_phone_number_for_link( $number ), $number ); } } } } echo $this->formats()[ $format ]['after'] . '</div>' . $args['after_widget']; }
Expand full source codeCollapse full source codeView on Github