Inventory_Presser_Carfax_Widget::widget( array $args, array $instance )
Outputs the content of the widget
On This Page
Parameters Parameters
- $args
-
(array) (Required)
- $instance
-
(array) (Required)
Source Source
File: includes/widget/class-widget-carfax.php
public function widget( $args, $instance ) {
$image_keys = array_keys( $this->images() );
$image = $image_keys[0];
if ( ! empty( $instance['image'] ) && in_array( $instance['image'], $image_keys, true ) ) {
$image = $instance['image'];
}
$path = dirname( INVP_PLUGIN_FILE_PATH ) . '/images/' . $this->images()[ $image ]['img'];
if ( ! file_exists( $path ) ) {
return;
}
$title = apply_filters( 'widget_title', $instance['title'] );
// before and after widget arguments are defined by themes.
echo wp_kses_post( $args['before_widget'] );
if ( ! empty( $title ) ) {
echo wp_kses_post( $args['before_title'] ) . esc_html( $title ) . wp_kses_post( $args['after_title'] );
}
echo wp_kses_post( wpautop( $instance['before_image'] ) );
if ( 'svg' === strtolower( pathinfo( $this->images()[ $image ]['img'], PATHINFO_EXTENSION ) ) ) {
// Include the SVG inline instead of using an <img> element.
$svg = file_get_contents( $path );
printf(
'<a href="%s">%s</a>',
esc_url( get_post_type_archive_link( INVP::POST_TYPE ) ),
$svg
);
} else {
printf(
'<a href="%s"><img src="%s"></a>',
esc_url( get_post_type_archive_link( INVP::POST_TYPE ) ),
esc_url( plugins_url( '/images/' . $this->images()[ $image ]['img'], INVP_PLUGIN_FILE_PATH ) )
);
}
echo wp_kses_post( wpautop( $instance['after_image'] ) ) . wp_kses_post( $args['after_widget'] );
}
Expand full source codeCollapse full source codeView on Github