function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0)
 {
     $indent = $depth ? str_repeat("\t", $depth) : '';
     $class_names = $value = '';
     $classes = empty($item->classes) ? array() : (array) $item->classes;
     $classes[] = 'menu-item-' . $item->ID;
     $class_names = join(' ', apply_filters('nav_menu_css_class', array_filter($classes), $item, $args));
     $class_names = $class_names ? ' class="' . esc_attr($class_names) . '"' : '';
     $id = apply_filters('nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args);
     $id = $id ? ' id="' . esc_attr($id) . '"' : '';
     $output .= $indent . '<li' . $id . $value . $class_names . '>';
     $atts = array();
     $atts['title'] = !empty($item->attr_title) ? $item->attr_title : '';
     $atts['target'] = !empty($item->target) ? $item->target : '';
     $atts['rel'] = !empty($item->xfn) ? $item->xfn : '';
     $atts['href'] = !empty($item->url) ? $item->url : '';
     $atts = apply_filters('nav_menu_link_attributes', $atts, $item, $args);
     $attributes = '';
     foreach ($atts as $attr => $value) {
         if (!empty($value)) {
             $value = 'href' === $attr ? esc_url($value) : esc_attr($value);
             $attributes .= ' ' . $attr . '="' . $value . '"';
         }
     }
     $icon_args = array();
     $icon_args['icon_name'] = $item->icon_name;
     $icon_args['icon_set'] = $item->icon_set;
     $icon_args['icon_transform'] = $item->icon_transform;
     $icon_args['icon_size'] = $item->icon_size;
     $icon_args['icon_align'] = $item->icon_align;
     $icon_args['icon_custom_classes'] = $item->icon_custom_classes;
     $icon_args['icon_color'] = $item->icon_color;
     $icon_args['icon_position'] = $item->icon_position;
     // If hover effect selected, add "iconized-hover-trigger" class to link
     $plugin_instance = Iconize_WP::get_instance();
     $hovers = $plugin_instance->get_iconize_dialog_dropdown_options_for('hover');
     $hovers = array_keys($hovers);
     $link_class = '';
     if (!empty($icon_args['icon_transform']) && in_array($icon_args['icon_transform'], $hovers)) {
         $link_class = ' class="iconized-hover-trigger"';
     }
     $icon = iconize_get_icon($icon_args, 'menu_item');
     if ('after' === $icon_args['icon_position']) {
         $title = apply_filters('the_title', $item->title, $item->ID) . $icon;
     } else {
         $title = $icon . apply_filters('the_title', $item->title, $item->ID);
     }
     $item_output = $args->before;
     $item_output .= '<a' . $attributes . $link_class . '>';
     $item_output .= $args->link_before . $title . $args->link_after;
     $item_output .= '</a>';
     $item_output .= $args->after;
     $output .= apply_filters('walker_nav_menu_start_el', $item_output, $item, $depth, $args);
 }
コード例 #2
0
 /**
  * Start the element output.
  *
  * @see Walker::start_el()
  *
  * @since 1.1.0
  *
  * @uses iconize_get_term_icon_by()
  * @uses iconize_get_icon()
  *
  * @param string $output   Passed by reference. Used to append additional content.
  * @param object $category Category data object.
  * @param int    $depth    Depth of category in reference to parents. Default 0.
  * @param array  $args     An array of arguments. @see wp_list_categories()
  * @param int    $id       ID of the current category.
  */
 function start_el(&$output, $category, $depth = 0, $args = array(), $id = 0)
 {
     extract($args);
     // Retrive an array of settings for term icon configured in term edit screen if there is icon.
     $icon = iconize_get_term_icon_by('id', $category->term_id, $category->taxonomy);
     $term_icon_args = array();
     if (!empty($icon)) {
         $term_icon_args = iconize_get_term_icon_by('id', $category->term_id, $category->taxonomy, 'array');
     }
     // Validate custom settings passed with 'iconize' arg to wp_list_categories().
     $hover_effect = isset($iconized['hover_effect']) ? (string) $iconized['hover_effect'] : 'default';
     $color = isset($iconized['color']) ? (string) $iconized['color'] : 'default';
     $hover_effect_trigger = isset($iconized['hover_effect_trigger']) ? (string) $iconized['hover_effect_trigger'] : 'link';
     $hover_color_change = isset($iconized['hover_color_change']) ? (bool) $iconized['hover_color_change'] : false;
     $fallback_icon_args = isset($iconized['fallback_icon']) ? (array) $iconized['fallback_icon'] : array();
     $override_icons = isset($iconized['override_icons']) ? (bool) $iconized['override_icons'] : false;
     $style = isset($iconized['style']) ? (string) $iconized['style'] : 'default';
     $after_icon = isset($iconized['after_icon']) ? (string) $iconized['after_icon'] : '&nbsp;&nbsp;';
     // Determine which icon to display.
     if (true === $override_icons) {
         $icon_args = $fallback_icon_args;
     } else {
         $icon_args = $term_icon_args;
         if (empty($icon_args) && !empty($fallback_icon_args)) {
             $icon_args = $fallback_icon_args;
         }
     }
     // Modify icon args if needed.
     if (!empty($icon_args)) {
         if ('iconize' === $style) {
             $icon_args['icon_custom_classes'] .= !empty($icon_args['icon_custom_classes']) ? ',iconized-li' : 'iconized-li';
         }
         if (true === $hover_color_change && false === strpos($icon_args['icon_custom_classes'], 'hover-color-change')) {
             $icon_args['icon_custom_classes'] .= !empty($icon_args['icon_custom_classes']) ? ',hover-color-change' : 'hover-color-change';
         }
         // Override effect and color if needed
         if ('default' !== $hover_effect) {
             $icon_args['icon_transform'] = $hover_effect;
         }
         if ('default' !== $color) {
             $icon_args['icon_color'] = $color;
         }
     }
     // Generate icon html.
     $icon_html = iconize_get_icon($icon_args, $category->taxonomy, $after_icon);
     // Generate iconized link.
     $cat_name = esc_attr($category->name);
     $cat_name = apply_filters('list_cats', $cat_name, $category);
     $link = '<a href="' . esc_url(get_term_link($category)) . '" ';
     if (0 == $use_desc_for_title || empty($category->description)) {
         $link .= 'title="' . esc_attr(sprintf(__('View all posts filed under %s', 'iconize'), $cat_name)) . '"';
     } else {
         $link .= 'title="' . esc_attr(strip_tags(apply_filters('category_description', $category->description, $category))) . '"';
     }
     // Add hover effect class to link if needed.
     if ('link' === $hover_effect_trigger && !empty($icon_html) && !empty($icon_args['icon_transform']) && !empty($hover_effect)) {
         $link .= ' class="iconized-hover-trigger"';
     }
     $link .= '>';
     $link .= $icon_html;
     $link .= $cat_name . '</a>';
     // The rest
     if (!empty($feed_image) || !empty($feed)) {
         $link .= ' ';
         if (empty($feed_image)) {
             $link .= '(';
         }
         $link .= '<a href="' . esc_url(get_term_feed_link($category->term_id, $category->taxonomy, $feed_type)) . '"';
         if (empty($feed)) {
             $alt = ' alt="' . sprintf(__('Feed for all posts filed under %s', 'iconize'), $cat_name) . '"';
         } else {
             $title = ' title="' . $feed . '"';
             $alt = ' alt="' . $feed . '"';
             $name = $feed;
             $link .= $title;
         }
         $link .= '>';
         if (empty($feed_image)) {
             $link .= $name;
         } else {
             $link .= "<img src='{$feed_image}'{$alt}{$title}" . ' />';
         }
         $link .= '</a>';
         if (empty($feed_image)) {
             $link .= ')';
         }
     }
     if (!empty($show_count)) {
         $link .= ' (' . intval($category->count) . ')';
     }
     if ('list' === $args['style']) {
         $output .= "\t<li";
         $class = 'cat-item cat-item-' . $category->term_id;
         if (!empty($current_category)) {
             $_current_category = get_term($current_category, $category->taxonomy);
             if ($category->term_id == $current_category) {
                 $class .= ' current-cat';
             } elseif ($category->term_id == $_current_category->parent) {
                 $class .= ' current-cat-parent';
             }
         }
         $output .= ' class="' . $class . '"';
         $output .= ">{$link}\n";
     } else {
         $output .= "\t{$link}<br />\n";
     }
 }
コード例 #3
0
 /**
  * Generate iconized tag cloud
  *
  * Attached to "wp_generate_tag_cloud" filter, extends default wp_generate_tag_cloud() function.
  *
  * @since    1.1.0
  *
  * @uses Iconize_WP::get_iconize_support_for()
  * @uses Iconize_WP::iconize_get_term_icon_by()
  * @uses Iconize_WP::iconize_get_icon()
  */
 public function iconize_wp_generate_tag_cloud($return, $tags, $args)
 {
     // Modify default functionality
     $defaults = array('smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 0, 'format' => 'flat', 'separator' => "\n", 'orderby' => 'name', 'order' => 'ASC', 'topic_count_text' => null, 'topic_count_text_callback' => null, 'topic_count_scale_callback' => 'default_topic_count_scale', 'filter' => 1);
     // Insert "iconized" arg to defaults
     if (!isset($defaults['iconized'])) {
         /**
          * Let users decide wheather to display iconized tag cloud or default one on each wp_tag_cloud() usage.
          * Iconized tag cloud disabled by default
          */
         $iconized_defaults = array();
         // If in admin area, display icons - better for end user
         if (is_admin()) {
             $iconized_defaults = array('hover_effect' => 'default', 'color' => 'default', 'hover_effect_trigger' => 'link', 'hover_color_change' => false, 'fallback_icon' => array(), 'override_icons' => false, 'style' => 'default', 'after_icon' => '&nbsp;');
         }
         /**
          * Apply "iconize_tag_cloud_defaults" filter to allow users to change default value of "iconized" parameter.
          */
         $defaults['iconized'] = apply_filters('iconized_tag_cloud_defaults', $iconized_defaults, $args);
     }
     $args = wp_parse_args($args, $defaults);
     // Check if iconize is enabled on this taxonomy
     if (isset($args['taxonomy'])) {
         $tax_support = $this->get_iconize_support_for('taxonomy_' . $args['taxonomy']);
         $tax_icons_enabled = $tax_support['enabled'];
     } else {
         $tax_icons_enabled = false;
     }
     // Return output if no iconized arg or iconize is disabled
     if (false === (bool) $args['iconized'] || !$tax_icons_enabled) {
         return $return;
     }
     // Continue with default logic
     extract($args, EXTR_SKIP);
     $return = 'array' === $format ? array() : '';
     if (empty($tags)) {
         return $return;
     }
     // Juggle topic count tooltips:
     if (isset($args['topic_count_text'])) {
         // First look for nooped plural support via topic_count_text.
         $translate_nooped_plural = $args['topic_count_text'];
     } elseif (!empty($args['topic_count_text_callback'])) {
         // Look for the alternative callback style. Ignore the previous default.
         if ($args['topic_count_text_callback'] === 'default_topic_count_text') {
             $translate_nooped_plural = _n_noop('%s topic', '%s topics');
         } else {
             $translate_nooped_plural = false;
         }
     } elseif (isset($args['single_text']) && isset($args['multiple_text'])) {
         // If no callback exists, look for the old-style single_text and multiple_text arguments.
         $translate_nooped_plural = _n_noop($args['single_text'], $args['multiple_text']);
     } else {
         // This is the default for when no callback, plural, or argument is passed in.
         $translate_nooped_plural = _n_noop('%s topic', '%s topics');
     }
     $tags_sorted = apply_filters('tag_cloud_sort', $tags, $args);
     if (empty($tags_sorted)) {
         return $return;
     }
     if ($tags_sorted !== $tags) {
         $tags = $tags_sorted;
         unset($tags_sorted);
     } else {
         if ('RAND' === $order) {
             shuffle($tags);
         } else {
             // SQL cannot save you; this is a second (potentially different) sort on a subset of data.
             if ('name' === $orderby) {
                 uasort($tags, '_wp_object_name_sort_cb');
             } else {
                 uasort($tags, '_wp_object_count_sort_cb');
             }
             if ('DESC' === $order) {
                 $tags = array_reverse($tags, true);
             }
         }
     }
     if ($number > 0) {
         $tags = array_slice($tags, 0, $number);
     }
     $counts = array();
     $real_counts = array();
     // For the alt tag
     foreach ((array) $tags as $key => $tag) {
         $real_counts[$key] = $tag->count;
         $counts[$key] = $topic_count_scale_callback($tag->count);
     }
     $min_count = min($counts);
     $spread = max($counts) - $min_count;
     if ($spread <= 0) {
         $spread = 1;
     }
     $font_spread = $largest - $smallest;
     if ($font_spread < 0) {
         $font_spread = 1;
     }
     $font_step = $font_spread / $spread;
     // Validate custom settings passed with 'iconize' arg to wp_tag_cloud().
     $hover_effect = isset($iconized['hover_effect']) ? (string) $iconized['hover_effect'] : 'default';
     $color = isset($iconized['color']) ? (string) $iconized['color'] : 'default';
     $hover_effect_trigger = isset($iconized['hover_effect_trigger']) ? (string) $iconized['hover_effect_trigger'] : 'link';
     $hover_color_change = isset($iconized['hover_color_change']) ? (bool) $iconized['hover_color_change'] : false;
     $fallback_icon_args = isset($iconized['fallback_icon']) ? (array) $iconized['fallback_icon'] : array();
     $override_icons = isset($iconized['override_icons']) ? (bool) $iconized['override_icons'] : false;
     $style = isset($iconized['style']) ? (string) $iconized['style'] : 'default';
     $after_icon = isset($iconized['after_icon']) ? (string) $iconized['after_icon'] : '&nbsp;';
     $a = array();
     foreach ($tags as $key => $tag) {
         $count = $counts[$key];
         $real_count = $real_counts[$key];
         $tag_link = '#' != $tag->link ? esc_url($tag->link) : '#';
         $tag_id = isset($tags[$key]->id) ? $tags[$key]->id : $key;
         $tag_name = $tags[$key]->name;
         if ($translate_nooped_plural) {
             $title_attribute = sprintf(translate_nooped_plural($translate_nooped_plural, $real_count), number_format_i18n($real_count));
         } else {
             $title_attribute = call_user_func($topic_count_text_callback, $real_count, $tag, $args);
         }
         // Retrive an array of settings for term icon configured in term edit screen if there is an icon.
         $icon = iconize_get_term_icon_by('name', $tag_name, $taxonomy);
         $term_icon_args = array();
         if (!empty($icon)) {
             $term_icon_args = iconize_get_term_icon_by('name', $tag_name, $taxonomy, 'array');
         }
         // Determine which icon to display.
         if (true === $override_icons) {
             $icon_args = $fallback_icon_args;
         } else {
             $icon_args = $term_icon_args;
             if (empty($icon_args) && !empty($fallback_icon_args)) {
                 $icon_args = $fallback_icon_args;
             }
         }
         // Modify icon args if needed.
         if (!empty($icon_args)) {
             if (true === $hover_color_change && false === strpos($icon_args['icon_custom_classes'], 'hover-color-change')) {
                 $icon_args['icon_custom_classes'] .= !empty($icon_args['icon_custom_classes']) ? ',hover-color-change' : 'hover-color-change';
             }
             // Override effect and color if needed
             if ('default' !== $hover_effect) {
                 $icon_args['icon_transform'] = $hover_effect;
             }
             if ('default' !== $color) {
                 $icon_args['icon_color'] = $color;
             }
         }
         // Generate icon html.
         $icon_html = iconize_get_icon($icon_args, $taxonomy, $after_icon);
         // Add hover effect class to link if needed.
         $het_link = '';
         if ('link' === $hover_effect_trigger && !empty($icon_html) && !empty($icon_args['icon_transform']) && !empty($hover_effect)) {
             $het_link = ' iconized-hover-trigger';
         }
         // Generate link.
         $a[] = "<a href='{$tag_link}' class='{$style}-style iconized-tag-link{$het_link} tag-link-{$tag_id}' title='" . esc_attr($title_attribute) . "' style='font-size: " . str_replace(',', '.', $smallest + ($count - $min_count) * $font_step) . "{$unit};'>{$icon_html}{$tag_name}</a>";
     }
     switch ($format) {
         case 'array':
             $return =& $a;
             break;
         case 'list':
             $return = "<ul class='wp-tag-cloud'>\n\t<li>";
             $return .= join("</li>\n\t<li>", $a);
             $return .= "</li>\n</ul>\n";
             break;
         default:
             $return = join($separator, $a);
             break;
     }
     return $return;
 }
コード例 #4
0
/**
 * Function for retriving taxonomy icons configured using taxonomy edit screens
 *
 *
 * @since   1.1.0
 *
 * @param string $field Either 'slug', 'name' or 'id' (term_id)
 * @param string|int $value Search for this term value
 * @param string $taxonomy Taxonomy Name
 * @param boolean $format return html markup or array? Either 'html' or 'array'
 * @param string $after_icon
 *
 * @return string  $icon_html, array of settings or empty string on failure
 */
function iconize_get_term_icon_by($field = 'id', $value, $taxonomy, $format = 'html', $after_icon = '&nbsp;&nbsp;')
{
    $fields = array('name', 'slug', 'id');
    $after = !is_string($after_icon) ? '&nbsp;&nbsp;' : $after_icon;
    $format = !is_string($format) ? 'html' : $format;
    if (!taxonomy_exists($taxonomy) || !in_array($field, $fields)) {
        return '';
    }
    // get term object
    $term = get_term_by($field, $value, $taxonomy);
    if (!$term || is_wp_error($term)) {
        return '';
    }
    $term_id = $term->term_id;
    $icon_args = array();
    $icon_html = '';
    $opt_array = get_option('iconize_taxonomy_icons');
    if ($opt_array && array_key_exists($taxonomy, $opt_array) && array_key_exists($term_id, $opt_array[$taxonomy])) {
        $icon_args['icon_name'] = isset($opt_array[$taxonomy][$term_id]['icon_name']) ? $opt_array[$taxonomy][$term_id]['icon_name'] : '';
        $icon_args['icon_set'] = isset($opt_array[$taxonomy][$term_id]['icon_set']) ? $opt_array[$taxonomy][$term_id]['icon_set'] : '';
        $icon_args['icon_transform'] = isset($opt_array[$taxonomy][$term_id]['icon_transform']) ? $opt_array[$taxonomy][$term_id]['icon_transform'] : '';
        $icon_args['icon_size'] = isset($opt_array[$taxonomy][$term_id]['icon_size']) ? $opt_array[$taxonomy][$term_id]['icon_size'] : '';
        $icon_args['icon_align'] = isset($opt_array[$taxonomy][$term_id]['icon_align']) ? $opt_array[$taxonomy][$term_id]['icon_align'] : '';
        $icon_args['icon_custom_classes'] = isset($opt_array[$taxonomy][$term_id]['icon_custom_classes']) ? $opt_array[$taxonomy][$term_id]['icon_custom_classes'] : '';
        $icon_args['icon_color'] = isset($opt_array[$taxonomy][$term_id]['icon_color']) ? $opt_array[$taxonomy][$term_id]['icon_color'] : '';
        // Generate icon html
        $icon_html = iconize_get_icon($icon_args, $taxonomy, $after);
    }
    if ('array' === $format) {
        return $icon_args;
    } else {
        return $icon_html;
    }
}