__('A cloud of your most used tags.', 'elessi-theme'), 'customize_selective_refresh' => true, 'title' => __('Tags', 'elessi-theme'), 'show_items' => 'All' ); parent::__construct('nasa_tag_cloud', 'Nasa - Tag Cloud', $widget_ops); } /** * @param array $args * @param array $instance */ public function widget($args, $instance) { $class = 'tagcloud'; if (isset($instance['taxonomy']) && in_array($instance['taxonomy'], array('product_cat', 'product_tag'))) { $class .= ' nasa-tag-cloud'; $class .= $instance['taxonomy'] == 'product_tag' ? ' nasa-tag-products-cloud' : ''; } $current_taxonomy = $this->_get_current_taxonomy($instance); $title_widget = !empty($instance['title']) ? $instance['title'] : ('post_tag' == $current_taxonomy ? esc_html__('Tags', 'elessi-theme') : get_taxonomy($current_taxonomy)->labels->name); /** This filter is documented in wp-includes/default-widgets.php */ $title = apply_filters('widget_title', $title_widget, $instance, $this->id_base); echo $args['before_widget']; echo $title ? $args['before_title'] . $title . $args['after_title'] : ''; echo '
' . '' . '' . '
'; $taxonomies = get_taxonomies(array('show_tagcloud' => true), 'object'); $id = esc_attr($this->get_field_id('taxonomy')); $name = esc_attr($this->get_field_name('taxonomy')); $input = ''; switch (count($taxonomies)) { // No tag cloud supporting taxonomies found, display error message case 0: echo '' . esc_html__('The tag cloud will not be displayed since there are no taxonomies that support the tag cloud widget.', 'elessi-theme') . '
'; printf($input, ''); break; // Just a single tag cloud supporting taxonomy found, no need to display options case 1: $keys = array_keys($taxonomies); $taxonomy = reset($keys); printf($input, esc_attr($taxonomy)); break; // More than one tag cloud supporting taxonomy found, display options default: printf( ''; } $show_items = $this->get_field_id('show_items'); $val_show = (isset($instance['show_items']) && is_numeric($instance['show_items']) ? $instance['show_items'] : esc_attr__('All', 'elessi-theme')); echo '' . '' . '' . '
'; } /** * Retrieves the taxonomy for the current Tag cloud widget instance. * * @since 4.4.0 * @access public * * @param array $instance Current settings. * @return string Name of the current taxonomy if set, otherwise 'post_tag'. */ public function _get_current_taxonomy($instance) { if (!empty($instance['taxonomy']) && taxonomy_exists($instance['taxonomy'])) { return $instance['taxonomy']; } return 'post_tag'; } }