FacebookReviews_Widget

Class FacebookReviews_Widget.


Description Description

See also See also


Top ↑

Source Source

File: mortgage-facebook-review/inc/FacebookReviews_Widget.php

class FacebookReviews_Widget extends \WP_Widget{


	/**
	 * FacebookReviews_Widgets constructor.
	 * @since  1.0.0
	 * @access public
	 */
	public function __construct() {
		parent::__construct(
			'mortgage_facebook_widget',
			__( 'Mortgage Facebook Reviews', 'FacebookReviewsWidget' ),
			array( 'description' => __( 'Mortgage Facebook Reviews', 'FacebookReviewsWidget' ) )
		);
	}

	/**
	 * Widget init.
	 * @since  1.0.0
	 * @access public
	 *
	 * @param array $args     arguments
	 * @param array $instance instance
	 */
	public function widget( $args, $instance ) {

		extract( $args );
		/**
		 * Widget title filter.
		 *
		 * @param mixed $instance ['title'] title
		 */
		$title = apply_filters( 'widget_title', $instance['title'] );
		// before and after widget arguments are defined by themes

		echo  $args['before_widget'] ;
		if ( $title ) {
			echo $before_title  . esc_html( $title ) . $after_title ;
		}

		$atts = array(
			'style' => $instance['style'],
			'count' => $instance['count'],
		);
		$shortcode = new FacebookReviews_Shortcode();
		echo $shortcode->shortcode($atts);


		echo $args['after_widget'] ;

	}

	/**
	 * Widget Backend.
	 * @since  1.0.0
	 * @access public
	 *
	 * @param array $instance instance
	 */
	public function form( $instance ) {

		$defaults = array(
			'title'         => ' ',
			'count'         => '3',
			'style' => 'list'
		);
		$instance = wp_parse_args( (array) $instance, $defaults );
		?>
		<p>
			<label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php echo esc_html__( 'Title', 'FacebookReviewsWidget' ); ?></label>
			<input id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"
			       name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>"
			       value="<?php echo esc_attr( $instance['title'] ); ?>" class="widefat" type="text"/>
		</p>

        <p>
            <label for="<?php echo esc_attr( $this->get_field_id( 'count' ) ); ?>"><?php echo esc_html__( 'Count', 'FacebookReviewsWidget' ); ?></label>
            <input id="<?php echo esc_attr( $this->get_field_id( 'count' ) ); ?>"
                   name="<?php echo esc_attr( $this->get_field_name( 'count' ) ); ?>"
                   value="<?php echo esc_attr( $instance['count'] ); ?>" class="widefat" type="number" min="0" max="10" step="1"/>
        </p>

		<p>
			<label for="<?php echo esc_attr( $this->get_field_id( 'style' ) ); ?>"><?php echo esc_html__( 'Style', 'FacebookReviewsWidget' ); ?></label>
			<select id="<?php echo $this->get_field_id('style'); ?>" class="widefat" name="<?php echo esc_attr( $this->get_field_name( 'style' ) ); ?>">
				<option <?php selected( $instance['style'], 'list' ); ?> value="list"><?php echo esc_html__( 'List', 'FacebookReviewsWidget' ); ?></option>
				<option <?php selected( $instance['style'], 'grid' ); ?> value="grid"><?php echo esc_html__( 'Grid', 'FacebookReviewsWidget' ); ?></option>
				<option <?php selected( $instance['style'], 'slider' ); ?> value="slider"><?php echo esc_html__( 'Slider', 'FacebookReviewsWidget' ); ?></option>
			</select>
		</p>
		<?php
	}


	/**
	 * Updating widget replacing old instances with new.
	 * @since  1.0.0
	 * @access public
	 *
	 * @param array $new_instance new instance
	 * @param array $old_instance old instance
	 *
	 * @return array
	 */
	public function update( $new_instance, $old_instance ) {
		$instance                  = $old_instance;
		$instance['title']         = ( ! empty( $new_instance['title'] ) ) ? sanitize_text_field( $new_instance['title'] ) : '';
		$instance['count'] = stripslashes( $new_instance['count'] );
		$instance['style'] = stripslashes( $new_instance['style'] );

		return $instance;
	}


}

Top ↑

Methods Methods

  • __construct — FacebookReviews_Widgets constructor.
  • form — Widget Backend.
  • update — Updating widget replacing old instances with new.
  • widget — Widget init.

Top ↑

Changelog Changelog

Changelog
Version Description
1.0.0 Introduced.