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 ); } public function form( $instance ) { // Merge the user-selected arguments with the defaults. $instance = wp_parse_args( (array) $instance, $this->defaults ); //

 
defaults ); // 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']; } echo $this->shortcode( $instance ); // Close the args's widget wrapper. echo $args['after_widget']; } public function shortcode( $atts ) { // Set the $title_li and $echo arguments to false. $atts['title_li'] = false; $atts['echo'] = false; // Get the categories list. $categories = str_replace( array( "\r", "\n", "\t" ), '', wp_list_categories( $atts ) ); $categories = str_replace( ' (', ' (', $categories ); $categories = str_replace( ')', ')', $categories ); $ew_categories = ''; // Only show this title in block element and not on widget. if ( isset( $atts['is_block'] ) && true === $atts['is_block'] && !empty( $atts['title'] ) ) { $ew_categories .= '

' . $atts['title'] . '

'; } // If 'list' is the user-selected style, wrap the categories in an unordered list. if ( 'list' === $atts['style'] ) { $ew_categories .= ''; } // If no style is given, wrap in a

tag for formatting. else { $ew_categories .= '

' . $categories . '

'; } // Output the categories list. return $ew_categories; } } // end Category_Widget class endif; if ( ! function_exists( 'ew_categories_register' ) ) : /** * Intiate Category_Widget Class. * * @since 1.0.0 */ function ew_categories_register() { register_widget( 'EW_Categories' ); } add_action( 'widgets_init', 'ew_categories_register' ); endif;