defaults = array( 'title' => esc_attr__( 'Categories', 'essential-widgets' ), 'taxonomy' => 'category', 'style' => 'list', 'include' => '', 'exclude' => '', 'exclude_tree' => '', 'child_of' => '', 'current_category' => '', 'search' => '', 'hierarchical' => true, 'hide_empty' => true, 'order' => 'ASC', 'orderby' => 'name', 'depth' => 0, 'number' => '', 'feed' => '', 'feed_type' => '', 'feed_image' => '', 'use_desc_for_title' => false, 'show_count' => false, ); $widget_ops = array( 'classname' => 'essential-widgets widget_categories ew-category ewcategory', 'description' => esc_html__( 'Displays a list of categories', 'essential-widgets' ), ); $control_ops = array( 'id_base' => 'ew-category' ); parent::__construct( 'ew-category', // Base ID __( 'EW: Categories', 'essential-widgets' ), // Name $widget_ops, $control_ops ); } function form($instance) { // Merge the user-selected arguments with the defaults. $instance = wp_parse_args( (array) $instance, $this->defaults ); //

 
defaults ); // Set the $title_li and $echo arguments to false. $instance['title_li'] = false; $instance['echo'] = false; // Output the args's $before_widget wrapper. echo $args['before_widget']; // If a title was input by the user, display it. if ( ! empty( $instance['title'] ) ) echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ) . $args['after_title']; // Get the categories list. $categories = str_replace( array( "\r", "\n", "\t" ), '', wp_list_categories( $instance ) ); $categories = str_replace(' (', ' (', $categories); $categories = str_replace(')', ')', $categories); // If 'list' is the user-selected style, wrap the categories in an unordered list. if ( 'list' == $instance['style'] ) $categories = ''; // If no style is given, wrap in a

tag for formatting. else $categories = '

' . $categories . '

'; // Output the categories list. echo $categories; // Close the args's widget wrapper. echo $args['after_widget']; } }// end Category_Widget class /** * Intiate Category_Widget Class. * * @since 1.0.0 */ function ew_categories_register() { register_widget( 'EW_Categories' ); } add_action( 'widgets_init', 'ew_categories_register' );