* * @wordpress-plugin * Plugin Name: Canuck Category Widget * Plugin URI: http://kevinsspace.ca/canuckdemo/ * Description: A widget for the Canuck Theme that allows the user to remove categories from the list * Version: 1.1.7 * Author: Kevin Archibald * Author URI: http://kevinsspace.ca/ * License: GPLv2 or later * License URI: http://www.gnu.org/licenses/gpl-2.0.txt */ /** * Use widgets_init action hook to execute custom function. */ add_action( 'widgets_init', 'canuck_register_recent_posts_widget' ); /** * Register our widget. */ function canuck_register_recent_posts_widget() { register_widget( 'canuck_recent_posts_widget' ); } /** * Recent_Posts widget w/ category exclude class. * This allows specific Category IDs to be removed from the Sidebar Recent Posts list */ class Canuck_Recent_Posts_Widget extends WP_Widget { /** * Sets up the widgets name etc. */ public function __construct() { $widget_ops = array( 'classname' => 'canuck_recent_posts', 'description' => esc_html__( 'Display recent posts, allow excluded categories', 'canuck' ), ); parent::__construct( 'canuck_recent_posts_widget', esc_html__( 'Canuck Recent Posts Widget', 'canuck' ), $widget_ops ); } /** * Outputs the options form on admin. * * @param array $instance The widget options. */ public function form( $instance ) { // Defaults. $canuck_recent_posts_defaults = array( 'canuck_title' => esc_html__( 'Recent Posts', 'canuck' ), 'canuck_count' => 5, ); $instance = wp_parse_args( (array) $instance, $canuck_recent_posts_defaults ); $title = $instance['canuck_title']; $count = $instance['canuck_count']; // Validate data. $count = is_int( $count ) ? $count : 5; ?>

id_base ); $c = ! empty( $instance['canuck_count'] ) ? intval( $instance['canuck_count'] ) : 5; $exclude_ids = canuck_exclude_category_validation(); $id_picks = array(); $id_picks = explode( ',', $exclude_ids ); $filtered_list = ''; $counter = 0; foreach ( $id_picks as $pick ) { if ( 1 < intval( $id_picks[ $counter ] ) ) { $filtered_list .= '-' . intval( $id_picks[ $counter ] ) . ','; } $counter++; } $exclude_ids = trim( $filtered_list, ',' ); $x = $exclude_ids; echo wp_kses_post( $args['before_widget'] ); if ( $title ) { echo wp_kses_post( $args['before_title'] ) . wp_kses_post( $title ) . wp_kses_post( $args['after_title'] ); } $post_args = array( 'numberposts' => $c, 'category' => $x, 'post_status' => 'publish', 'suppress_filters' => false, ); $recent_posts = wp_get_recent_posts( $post_args ); ?>