Inventory_Presser_Carfax_Widget::widget( array $args, array $instance )

Outputs the content of the widget


Parameters

$args

(array) (Required)

$instance

(array) (Required)


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 ) ) {
			$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 $args['before_widget'];
		if ( ! empty( $title ) ) {
			echo $args['before_title'] . $title . $args['after_title'];
		}

		echo 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>',
				get_post_type_archive_link( INVP::POST_TYPE ),
				$svg
			);
		} else {
			printf(
				'<a href="%s"><img src="%s"></a>',
				get_post_type_archive_link( INVP::POST_TYPE ),
				plugins_url( '/images/' . $this->images()[ $image ]['img'], INVP_PLUGIN_FILE_PATH )
			);
		}
		echo wpautop( $instance['after_image'] ) . $args['after_widget'];
	}