get_id(); } public function get_description() { return ''; } /** * Sets up the widgets name etc. */ public function __construct() { $this->_default = $this->get_default(); $widget_ops = array( 'classname' => $this->get_classname(), 'description' => $this->get_description(), ); parent::__construct( $this->get_id(), $this->get_name(), $widget_ops ); } /** * Outputs the content of the widget. * * @param array $args * @param array $instance */ public function widget( $args, $instance ) {} /** * Outputs the options form on admin. * * @param array $instance The widget options. */ public function form( $instance ) {} /** * Processing widget options on save. * * @param array $new_instance The new options. * @param array $old_instance The previous options. */ public function update( $new_instance, $old_instance ) {} protected function _parse_instance( $instance ) { return wp_parse_args( $instance, $this->get_default() ); } } class Buzzo_Widget_Posts extends Buzzo_Widget { public function get_id() { return 'buzzo-posts'; } public function get_name() { return esc_html__( 'Buzzo: Posts', 'buzzo' ); } public function get_default() { return array( 'title' => '', 'number' => 5, 'cat' => '', 'tag' => '', 'orderby' => 'latest', 'order' => 'desc', 'columns' => 1, ); } /** * Outputs the content of the widget. * * @param array $args * @param array $instance */ public function widget( $args, $instance ) { $instance = $this->_parse_instance( $instance ); $query_args = $this->_get_query_args( $instance ); $query = new WP_Query( $query_args ); echo wp_kses_post( $args['before_widget'] ); if ( ! empty( $instance['title'] ) ) { echo wp_kses_post( $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ) . $args['after_title'] ); } $col_class = 'col-sm-' . ( 12 / intval( $instance['columns'] ) ); ?>
have_posts() ) : $query->the_post(); ?>
_parse_instance( $instance ); $option_cats = get_terms( array( 'taxonomy' => 'category', 'fields' => 'id=>name', ) ); $option_tags = get_terms( array( 'taxonomy' => 'post_tag', 'fields' => 'id=>name', ) ); ?>

_parse_instance( $new_instance ); $instance['title'] = wp_kses( $new_instance['title'], array() ); $instance['number'] = intval( $new_instance['number'] ); $instance['cat'] = intval( $new_instance['cat'] ); $instance['tag'] = intval( $new_instance['tag'] ); $instance['orderby'] = sanitize_text_field( $new_instance['orderby'] ); $instance['order'] = sanitize_text_field( $new_instance['order'] ); $instance['columns'] = intval( $new_instance['columns'] ); return $instance; } protected function _get_query_args( $instance ) { $query_args = array( 'posts_per_page' => intval( $instance['number'] ), 'ignore_sticky_posts' => true, ); if ( $instance['cat'] ) { $query_args['cat'] = intval( $instance['cat'] ); } if ( $instance['tag'] ) { $query_args['tag_id'] = intval( $instance['tag'] ); } if ( 'latest' != $instance['orderby'] ) { $query_args['orderby'] = $instance['orderby']; } if ( $instance['order'] ) { $query_args['order'] = $instance['order']; } return $query_args; } }