Changeset 2752469
- Timestamp:
- 07/06/2022 09:50:52 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
list-categories-widget/trunk/includes/widgets/woo-cat.php
r2680879 r2752469 3 3 class Custom_Post_Type_Widgets 4 4 { 5 6 5 /** 7 6 * Sets up a new widget instance … … 11 10 add_action('widgets_init', array($this, 'init')); 12 11 } 13 14 15 12 public function init() 16 13 { 17 18 14 register_widget('WP_Custom_Post_Type_Widgets_Categories'); 19 15 } 20 16 } 21 22 17 class WP_Custom_Post_Type_Widgets_Categories extends WP_Widget 23 18 { … … 34 29 { 35 30 $title = !empty($instance['title']) ? $instance['title'] : esc_html('Categories', 'category-widget'); 36 37 31 /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ 38 32 $title = apply_filters('widget_title', $title, $instance, $this->id_base); 39 40 33 $taxonomy = !empty($instance['taxonomy']) ? $instance['taxonomy'] : 'category'; 41 34 $c = !empty($instance['count']) ? (bool) $instance['count'] : false; 42 35 $h = !empty($instance['hierarchical']) ? (bool) $instance['hierarchical'] : false; 43 44 45 36 echo wp_kses_post($args['before_widget']); 46 37 if ($title) 47 38 { 48 39 echo wp_kses_post($args['before_title']) . esc_html($title) . wp_kses_post($args['after_title']); 49 50 40 } 51 52 53 41 $cat_args = array( 54 42 'orderby' => 'name', … … 58 46 'sanitize_links' => 1, 59 47 'walker' => new List_Category_Images 60 61 48 );?> 62 63 49 <ul> 64 <?php 65 $cat_args['title_li'] = ''; 66 67 wp_list_categories( 68 apply_filters( 69 'custom_post_type_widgets/categories/widget_categories_args', 70 $cat_args, 71 $instance, 72 $this->id, 73 $taxonomy 74 ) 75 ); 76 ?> 50 <?php 51 $cat_args['title_li'] = ''; 52 wp_list_categories( 53 apply_filters( 54 'custom_post_type_widgets/categories/widget_categories_args', 55 $cat_args, 56 $instance, 57 $this->id, 58 $taxonomy 59 ) 60 ); 61 ?> 77 62 </ul> 78 63 <?php 79 80 64 echo wp_kses_post($args['after_widget']); 81 65 } 82 83 66 public function update($new_instance, $old_instance) 84 67 { … … 88 71 $instance['count'] = !empty($new_instance['count']) ? (bool) $new_instance['count'] : false; 89 72 $instance['hierarchical'] = !empty($new_instance['hierarchical']) ? (bool) $new_instance['hierarchical'] : false; 90 91 92 73 return $instance; 93 74 } 94 95 75 public function form($instance) 96 76 { … … 99 79 $count = isset($instance['count']) ? (bool) $instance['count'] : false; 100 80 $hierarchical = isset($instance['hierarchical']) ? (bool) $instance['hierarchical'] : false; 101 102 81 ?> 103 82 <p><label for="<?php echo esc_attr($this->get_field_id('title')); ?>"><?php esc_html_e('Title:', 'category-widget');?></label> 104 83 <input class="widefat" id="<?php echo esc_attr($this->get_field_id('title')); ?>" name="<?php echo esc_attr($this->get_field_name('title')); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></p> 105 106 84 <?php 107 $taxonomies = get_taxonomies(array(), 'objects'); 108 109 if ($taxonomies) { 110 printf( 111 '<p><label for="%1$s">%2$s</label>' . 112 '<select class="widefat" id="%1$s" name="%3$s">', 113 esc_attr($this->get_field_id('taxonomy')), 114 esc_html('Taxonomy:', 'category-widget'), 115 esc_html($this->get_field_name('taxonomy')) 116 ); 117 118 foreach ($taxonomies as $taxobjects => $value) { 119 if (!$value->hierarchical) { 120 continue; 85 $taxonomies = get_taxonomies(array(), 'objects'); 86 if ($taxonomies) { 87 printf( 88 '<p><label for="%1$s">%2$s</label>' . 89 '<select class="widefat" id="%1$s" name="%3$s">', 90 esc_attr($this->get_field_id('taxonomy')), 91 esc_html('Taxonomy:', 'category-widget'), 92 esc_html($this->get_field_name('taxonomy')) 93 ); 94 foreach ($taxonomies as $taxobjects => $value) { 95 if (!$value->hierarchical) { 96 continue; 97 } 98 if ('nav_menu' === $taxobjects || 'link_category' === $taxobjects || 'post_format' === $taxobjects) { 99 continue; 100 } 101 printf( 102 '<option value="%s"%s>%s</option>', 103 esc_attr($taxobjects), 104 selected($taxobjects, $taxonomy, false), 105 esc_html($value->label, 'category-widget') . ' ' . esc_html($taxobjects) 106 ); 121 107 } 122 if ('nav_menu' === $taxobjects || 'link_category' === $taxobjects || 'post_format' === $taxobjects) { 123 continue; 124 } 125 126 printf( 127 '<option value="%s"%s>%s</option>', 128 esc_attr($taxobjects), 129 selected($taxobjects, $taxonomy, false), 130 esc_html($value->label, 'category-widget') . ' ' . esc_html($taxobjects) 131 ); 108 echo '</select></p>'; 132 109 } 133 echo '</select></p>'; 134 } 135 ?> 136 110 ?> 137 111 <p> 138 139 140 112 <input type="checkbox" class="checkbox" id="<?php echo esc_attr($this->get_field_id('count')); ?>" name="<?php echo esc_attr($this->get_field_name('count')); ?>"<?php checked($count);?> /> 141 113 <label for="<?php echo esc_attr($this->get_field_id('count')); ?>"><?php esc_html_e('Show post counts', 'category-widget');?></label><br /> 142 143 114 <input type="checkbox" class="checkbox" id="<?php echo esc_attr($this->get_field_id('hierarchical')); ?>" name="<?php echo esc_attr($this->get_field_name('hierarchical')); ?>"<?php checked($hierarchical);?> /> 144 115 <label for="<?php echo esc_attr($this->get_field_id('hierarchical')); ?>"><?php esc_html_e('Show hierarchy', 'category-widget');?></label></p> 145 116 <?php 146 }147 }117 } 118 }
Note: See TracChangeset
for help on using the changeset viewer.