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 wp_kses_post( $args['before_widget'] );
$title = apply_filters( 'widget_title', $instance['title'] );
if ( ! empty( $title ) ) {
echo wp_kses_post( $args['before_title'] ) . esc_html( $title ) . wp_kses_post( $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',
esc_attr( $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 );
$html = '';
$description = '';
if ( $this->formats()[ $format ]['uses_labels'] ) {
$description = get_term_meta( $term_id, 'phone_' . $p . '_description', true );
$html .= sprintf( $this->formats()[ $format ]['repeater'], esc_html( $description ), INVP::prepare_phone_number_for_link( $number ), esc_html( $number ) );
} else {
$html .= sprintf( $this->formats()[ $format ]['repeater'], INVP::prepare_phone_number_for_link( $number ), esc_html( $number ) );
}
echo wp_kses_post( apply_filters( 'invp_phone_number_widget_html', $html, $term_id, $phone_uid, $number, $description, $this->formats()[ $format ] ) );
}
}
}
echo $this->formats()[ $format ]['after']
. '</div>'
. wp_kses_post( $args['after_widget'] );
}
Expand full source codeCollapse full source codeView on Github