ZillowReviews_Widget

Class ZillowReviews_Widget


Description Description

See also See also


Top ↑

Source Source

File: mortgage-zillow-review/inc/ZillowReviews_Widget.php

class ZillowReviews_Widget extends \WP_Widget
{


    /**
     * ZillowReviews_Widgets constructor.
     * @since  1.0.0
     * @access public
     */
    public function __construct()
    {
        parent::__construct(
            'mortgage_zillow_widget',
            __('Mortgage Zillow Reviews', 'ZillowReviewsWidget'),
            array( 'description' => __('Mortgage Zillow Reviews', 'ZillowReviewsWidget') )
        );
    }

    /**
     * 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(
            'type' => $instance['type'],
            'count' => $instance['count'],
            'style' => $instance['style'],
        );
        $shortcode = new ZillowReviews_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'         => ' ',
            'type' => 'profile',
            'count' => '10',
            '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', 'ZillowReviewsWidget'); ?></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('type')); ?>"><?php echo esc_html__('Type', 'ZillowReviewsWidget'); ?></label>
            <select id="<?php echo $this->get_field_id('type'); ?>" class="widefat" name="<?php echo esc_attr($this->get_field_name('type')); ?>">
                <option <?php selected($instance['type'], 'profile'); ?> value="profile_review"><?php echo esc_html__('Profile reviews', 'ZillowReviewsWidget'); ?></option>
                <option <?php selected($instance['type'], 'individual'); ?> value="individual_type"><?php echo esc_html__('Individual reviews', 'ZillowReviewsWidget'); ?></option>
                <option <?php selected($instance['type'], 'company'); ?> value="company_type"><?php echo esc_html__('Company reviews', 'ZillowReviewsWidget'); ?></option>
            </select>
        </p>

        <p>
            <label for="<?php echo esc_attr($this->get_field_id('count')); ?>"><?php echo esc_html__('Count', 'ZillowReviewsWidget'); ?></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', 'ZillowReviewsWidget'); ?></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', 'ZillowReviewsWidget'); ?></option>
				<option <?php selected($instance['style'], 'grid'); ?> value="grid"><?php echo esc_html__('Grid', 'ZillowReviewsWidget'); ?></option>
				<option <?php selected($instance['style'], 'slider'); ?> value="slider"><?php echo esc_html__('Slider', 'ZillowReviewsWidget'); ?></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['type'] = stripslashes($new_instance['type']);
        $instance['count'] = stripslashes($new_instance['count']);
        $instance['style'] = stripslashes($new_instance['style']);

        return $instance;
    }
}

Top ↑

Methods Methods

  • __construct — ZillowReviews_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.