woothemes_widget_cssclass = 'widget_woothemes_testimonials'; $this->woothemes_widget_description = __( 'Recent testimonials on your site.', WFT_DOMAIN ); $this->woothemes_widget_idbase = 'woothemes_testimonials'; $this->woothemes_widget_title = __( 'Testimonials', WFT_DOMAIN ); /* Widget settings. */ $widget_ops = array( 'classname' => $this->woothemes_widget_cssclass, 'description' => $this->woothemes_widget_description ); /* Widget control settings. */ $control_ops = array( 'width' => 250, 'height' => 350, 'id_base' => $this->woothemes_widget_idbase ); /* Create the widget. */ $this->WP_Widget( $this->woothemes_widget_idbase, $this->woothemes_widget_title, $widget_ops, $control_ops ); } // End __construct() /** * Display the widget on the frontend. * @since 1.0.0 * @param array $args Widget arguments. * @param array $instance Widget settings for this instance. * @return void */ public function widget( $args, $instance ) { extract( $args, EXTR_SKIP ); /* Our variables from the widget settings. */ $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base ); /* Before widget (defined by themes). */ $args = array(); $args['before'] = $before_widget; $args['after'] = $after_widget; /* Display the widget title if one was input (before and after defined by themes). */ if ( $title ) { $args['before_title'] = $before_title; $args['title'] = $title; $args['after_title'] = $after_title; } /* Widget content. */ // Add actions for plugins/themes to hook onto. do_action( $this->woothemes_widget_cssclass . '_top' ); // Integer values. if ( isset( $instance['limit'] ) && ( 0 < count( $instance['limit'] ) ) ) { $args['limit'] = intval( $instance['limit'] ); } if ( isset( $instance['specific_id'] ) && ( 0 < count( $instance['specific_id'] ) ) ) { $args['id'] = intval( $instance['specific_id'] ); } if ( isset( $instance['size'] ) && ( 0 < count( $instance['size'] ) ) ) { $args['size'] = intval( $instance['size'] ); } if ( isset( $instance['category'] ) && is_numeric( $instance['category'] ) ) $args['category'] = intval( $instance['category'] ); // Boolean values. if ( isset( $instance['display_author'] ) && ( 1 == $instance['display_author'] ) ) { $args['display_author'] = true; } else { $args['display_author'] = false; } if ( isset( $instance['display_avatar'] ) && ( 1 == $instance['display_avatar'] ) ) { $args['display_avatar'] = true; } else { $args['display_avatar'] = false; } if ( isset( $instance['display_url'] ) && ( 1 == $instance['display_url'] ) ) { $args['display_url'] = true; } else { $args['display_url'] = false; } if ( isset( $instance['navigation'] ) && ( 1 == $instance['navigation'] ) ) { $args['navigation'] = true; } else { $args['navigation'] = false; } // Select boxes. if ( isset( $instance['orderby'] ) && in_array( $instance['orderby'], array_keys( $this->get_orderby_options() ) ) ) { $args['orderby'] = $instance['orderby']; } if ( isset( $instance['order'] ) && in_array( $instance['order'], array_keys( $this->get_order_options() ) ) ) { $args['order'] = $instance['order']; } // Display the testimonials. woothemes_testimonials( $args ); // Add actions for plugins/themes to hook onto. do_action( $this->woothemes_widget_cssclass . '_bottom' ); } // End widget() /** * Method to update the settings from the form() method. * @since 1.0.0 * @param array $new_instance New settings. * @param array $old_instance Previous settings. * @return array Updated settings. */ public function update ( $new_instance, $old_instance ) { $instance = $old_instance; /* Strip tags for title and name to remove HTML (important for text inputs). */ $instance['title'] = strip_tags( $new_instance['title'] ); /* Make sure the integer values are definitely integers. */ $instance['limit'] = intval( $new_instance['limit'] ); $instance['specific_id'] = intval( $new_instance['specific_id'] ); $instance['size'] = intval( $new_instance['size'] ); $instance['category'] = intval( $new_instance['category'] ); /* The select box is returning a text value, so we escape it. */ $instance['orderby'] = esc_attr( $new_instance['orderby'] ); $instance['order'] = esc_attr( $new_instance['order'] ); /* The checkbox is returning a Boolean (true/false), so we check for that. */ $instance['display_author'] = (bool) esc_attr( $new_instance['display_author'] ); $instance['display_avatar'] = (bool) esc_attr( $new_instance['display_avatar'] ); $instance['display_url'] = (bool) esc_attr( $new_instance['display_url'] ); $instance['navigation'] = (bool) esc_attr( $new_instance['navigation'] ); return $instance; } // End update() /** * The form on the widget control in the widget administration area. * Make use of the get_field_id() and get_field_name() function when creating your form elements. This handles the confusing stuff. * @since 1.0.0 * @param array $instance The settings for this instance. * @return void */ public function form( $instance ) { /* Set up some default widget settings. */ /* Make sure all keys are added here, even with empty string values. */ $defaults = array( 'title' => '', 'limit' => 5, 'orderby' => 'menu_order', 'order' => 'DESC', 'specific_id' => '', 'display_author' => true, 'display_avatar' => true, 'display_url' => true, 'effect' => 'fade', // Options: 'fade', 'none' 'pagination' => false, 'size' => 50, 'navigation' => true, 'category' => 0 ); $instance = wp_parse_args( (array) $instance, $defaults ); ?>
/>
/>
/>
/>
'testimonial-category', 'class' => 'widefat', 'show_option_all' => __( 'All', WFT_DOMAIN ), 'id' => $this->get_field_id( 'category' ), 'name' => $this->get_field_name( 'category' ), 'selected' => $instance['category'] ); wp_dropdown_categories( $dropdown_args ); ?>
__( 'No Order', WFT_DOMAIN ), 'ID' => __( 'Entry ID', WFT_DOMAIN ), 'title' => __( 'Title', WFT_DOMAIN ), 'date' => __( 'Date Added', WFT_DOMAIN ), 'menu_order' => __( 'Specified Order Setting', WFT_DOMAIN ), 'rand' => __( 'Random Order', WFT_DOMAIN ) ); } // End get_orderby_options() /** * Get an array of the available order options. * @since 1.0.0 * @return array */ protected function get_order_options () { return array( 'ASC' => __( 'Ascending', WFT_DOMAIN ), 'DESC' => __( 'Descending', WFT_DOMAIN ) ); } // End get_order_options() } // End Class /* Register the widget. */ add_action( 'widgets_init', create_function( '', 'return register_widget("Woothemes_Widget_Testimonials");' ), 1 ); ?>