function enp_popular_posts($atts) { $atts = shortcode_atts(array('slug' => false, 'type' => false, 'how-many' => 5), $atts); // set the value $posts_html = ''; // if no slug was passed, get all of the posts if ($atts['slug'] === false) { $enp_btn_slugs = get_option('enp_button_slugs'); if (!empty($enp_btn_slugs)) { foreach ($enp_btn_slugs as $slug) { $atts['slug'] = $slug; $posts_html .= enp_popular_posts_HTML($atts); } } } else { $posts_html .= enp_popular_posts_HTML($atts); } return $posts_html; }
/** * Front-end display of widget. * * @see WP_Widget::widget() * * @param array $args Widget arguments. * @param array $instance Saved values from database. */ public function widget($args, $instance) { echo $args['before_widget']; if (!empty($instance['title'])) { echo $args['before_title'] . apply_filters('widget_title', $instance['title']) . $args['after_title']; } $atts = array(); $defaults = array('slug' => false, 'type' => false, 'how-many' => 5); $atts['slug'] = !empty($instance['slug']) ? $instance['slug'] : ''; $atts['type'] = !empty($instance['type']) ? $instance['type'] : 'all'; $atts['how-many'] = !empty($instance['how_many']) ? $instance['how_many'] : '5'; // if we don't have a slug, something is wrong if (empty($atts['slug'])) { return false; } add_filter('enp_popular_widget_posts_loop_before_html', array($this, 'widget_popular_posts_before'), 10, 2); add_filter('enp_popular_widget_post_html', 'enp_default_pop_post_html', 10, 4); add_filter('enp_popular_widget_posts_loop_after_html', 'enp_default_pop_posts_loop_after', 10, 2); echo enp_popular_posts_HTML($atts, 'widget_'); echo $args['after_widget']; }