/** * Display tag cloud. * * The text size is set by the 'smallest' and 'largest' arguments, which will * use the 'unit' argument value for the CSS text size unit. The 'format' * argument can be 'flat' (default), 'list', 'nolink', or 'array'. The flat value for the * 'format' argument will separate tags with spaces. The list value for the * 'format' argument will format the tags in a UL HTML list. The nolink value for the * 'format' argument will display the tags without links. The array value for the * 'format' argument will return in PHP array type format. * * The 'orderby' argument will accept 'name' or 'count' and defaults to 'name'. * The 'order' is the direction to sort, defaults to 'ASC' and can be 'DESC'. * * The 'number' argument is how many tags to return. By default, the limit will * be to return the top 20 tags in the tag cloud list. * * The 'topic_count_text_callback' argument is a function, which, given the count * of the posts with that tag, returns a text for the tooltip of the tag link. * @see default_topic_count_text * * The 'exclude' and 'include' arguments are used for the {@link get_tags()} * function. Only one should be used, because only one will be used and the * other ignored, if they are both set. * * @since 2.3.0 * * @param array|string $args Optional. Override default arguments. * @return array Generated tag cloud, only if no failures and 'array' is set for the 'format' argument. */ function seo_tag_cloud($args = '') { $defaults = array('largest' => 10, 'number' => 20, 'format' => 'flat', 'orderby' => 'name', 'order' => 'ASC', 'exclude' => '', 'include' => '', 'link' => 'view', 'target' => ''); $args = wp_parse_args($args, $defaults); $tags = get_tags(array_merge($args, array('orderby' => 'count', 'order' => 'DESC'))); // Always query top tags if (empty($tags)) { return; } foreach ($tags as $key => $tag) { if ('edit' == $args['link']) { $link = get_edit_tag_link($tag->term_id); } else { $link = get_tag_link($tag->term_id); } if (is_wp_error($link)) { return false; } $tags[$key]->link = $link; $tags[$key]->id = $tag->term_id; } $return = seo_tag_cloud_generate($tags, $args); // Here's where those top tags get sorted according to $args $return = apply_filters('wp_tag_cloud', $return, $args); if ('array' == $args['format']) { return $return; } echo $return; }
/** * Display tag cloud. * * The text size is set by the 'smallest' and 'largest' arguments, which will * use the 'unit' argument value for the CSS text size unit. The 'format' * argument can be 'flat' (default), 'list', or 'array'. The flat value for the * 'format' argument will separate tags with spaces. The list value for the * 'format' argument will format the tags in a UL HTML list. The array value for * the 'format' argument will return in PHP array type format. * * The 'orderby' argument will accept 'name' or 'count' and defaults to 'name'. * The 'order' is the direction to sort, defaults to 'ASC' and can be 'DESC'. * * The 'number' argument is how many tags to return. By default, the limit will * be to return the top 45 tags in the tag cloud list. * * The 'topic_count_text_callback' argument is a function, which, given the count * of the posts with that tag, returns a text for the tooltip of the tag link. * * The 'exclude' and 'include' arguments are used for the {@link get_tags()} * function. Only one should be used, because only one will be used and the * other ignored, if they are both set. * * @since 2.3.0 * * @param array|string $args Optional. Override default arguments. * @return array Generated tag cloud, only if no failures and 'array' is set for the 'format' argument. */ function wp_tag_cloud($args = '') { $defaults = array('smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 45, 'format' => 'flat', 'separator' => "\n", 'orderby' => 'name', 'order' => 'ASC', 'exclude' => '', 'include' => '', 'link' => 'view', 'taxonomy' => 'post_tag', 'echo' => true); $args = wp_parse_args($args, $defaults); $tags = get_terms($args['taxonomy'], array_merge($args, array('orderby' => 'count', 'order' => 'DESC'))); // Always query top tags if (empty($tags) || is_wp_error($tags)) { return; } foreach ($tags as $key => $tag) { if ('edit' == $args['link']) { $link = get_edit_tag_link($tag->term_id, $tag->taxonomy); } else { $link = get_term_link(intval($tag->term_id), $tag->taxonomy); } if (is_wp_error($link)) { return false; } $tags[$key]->link = $link; $tags[$key]->id = $tag->term_id; } $return = wp_generate_tag_cloud($tags, $args); // Here's where those top tags get sorted according to $args $return = apply_filters('wp_tag_cloud', $return, $args); if ('array' == $args['format'] || empty($args['echo'])) { return $return; } echo $return; }
/** * Display or retrieve edit tag link with formatting. * * @since 2.7.0 * * @param string $link Optional. Anchor text. * @param string $before Optional. Display before edit link. * @param string $after Optional. Display after edit link. * @param int|object $tag Tag object or ID * @return string|null HTML content, if $echo is set to false. */ function edit_tag_link($link = '', $before = '', $after = '', $tag = null) { $tax = get_taxonomy('post_tag'); if (!current_user_can($tax->cap->edit_terms)) { return; } $tag = get_term($tag, 'post_tag'); if (empty($link)) { $link = __('Edit This'); } $link = '<a href="' . get_edit_tag_link($tag->term_id) . '" title="' . __('Edit Tag') . '">' . $link . '</a>'; echo $before . apply_filters('edit_tag_link', $link, $tag->term_id) . $after; }
/** * Display tag cloud. * * The text size is set by the 'smallest' and 'largest' arguments, which will * use the 'unit' argument value for the CSS text size unit. The 'format' * argument can be 'flat' (default), 'list', or 'array'. The flat value for the * 'format' argument will separate tags with spaces. The list value for the * 'format' argument will format the tags in a UL HTML list. The array value for * the 'format' argument will return in PHP array type format. * * The 'orderby' argument will accept 'name' or 'count' and defaults to 'name'. * The 'order' is the direction to sort, defaults to 'ASC' and can be 'DESC'. * * The 'number' argument is how many tags to return. By default, the limit will * be to return the top 45 tags in the tag cloud list. * * The 'topic_count_text_callback' argument is a function, which, given the count * of the posts with that tag, returns a text for the tooltip of the tag link. * * The 'exclude' and 'include' arguments are used for the {@link get_tags()} * function. Only one should be used, because only one will be used and the * other ignored, if they are both set. * * The 'single' parameters is used to display only a single post's tags inside * the loop. * * The 'categories' parameter will add categories to the tag cloud if set to 'Yes' * * The 'replace' paramter, if set to 'Yes', will change all blanks ' ' to * * The 'mincount' parameter will hide all tags that aren't used more often than * mincount. * * The 'separator' will be printed between tags. * * 'inject_count' will add a counter to the tags is set to 'Yes'. * 'inject_count_outside' will put this counter outside the tag link. * * @since 2.3.0 * * @param array|string $args Optional. Override default arguments. * @return array Generated tag cloud, only if no failures and 'array' is set for the 'format' argument. */ function nk_wp_tag_cloud($args = '') { $defaults = array('smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 45, 'format' => 'flat', 'orderby' => 'name', 'order' => 'ASC', 'exclude' => '', 'include' => '', 'link' => 'view', 'single' => 'No', 'categories' => 'No', 'replace' => 'No', 'mincount' => '0', 'separator' => '', 'hidelastseparator' => 'No', 'inject_count' => 'No', 'inject_count_outside' => 'Yes', 'post_id' => null, 'nofollow' => 'No', 'taxonomy' => 'post_tag'); $args = wp_parse_args($args, $defaults); if (intval($args['post_id']) != 0) { $my_query = new WP_Query("cat={$category}"); if ($my_query->have_posts()) { while ($my_query->have_posts()) { $my_query->the_post(); $tags = apply_filters('get_the_tags', get_the_terms(null, 'post_tag')); } } $GLOBALS['post'] = $GLOBALS['wp_query']->post; // restore $post } elseif ($args['single'] == 'Yes' || $args['single'] == 'yes') { $tags = apply_filters('get_the_tags', get_the_terms(null, $args['taxonomy'])); } else { $tags = get_terms($args['taxonomy'], array_merge($args, array('orderby' => 'count', 'order' => 'DESC'))); } // nkuttler if ($args['categories'] == 'Yes') { $tags = array_merge($tags, get_categories()); } if (empty($tags)) { return; } foreach ($tags as $key => $tag) { if ('edit' == $args['link']) { $link = get_edit_tag_link($tag->term_id); } else { if (isset($tag->cat_ID)) { $link = get_category_link($tag->term_id); } else { $link = get_term_link($tag, $args['taxonomy']); } } if (is_wp_error($link)) { return false; } $tags[$key]->link = $link; $tags[$key]->id = $tag->term_id; } $return = nk_wp_generate_tag_cloud($tags, $args); // Here's where those top tags get sorted according to $args $return = apply_filters('wp_tag_cloud', $return, $args); if ('array' == $args['format']) { return $return; } // nkuttler - always return return $return; //echo $return; }
function popular_tags_from_category($catid, $days, $limit = 15) { global $wpdb; $now = gmdate("Y-m-d H:i:s", time()); //$datelimit = gmdate("Y-m-d H:i:s",gmmktime(date("H"), date("i"), date("s"), date("m"),date("d")-30,date("Y"))); $popterms = "SELECT DISTINCT terms2.*, t2.count as count FROM {$wpdb->posts} as p1 LEFT JOIN {$wpdb->term_relationships} as r1 ON p1.ID = r1.object_ID LEFT JOIN {$wpdb->term_taxonomy} as t1 ON r1.term_taxonomy_id = t1.term_taxonomy_id LEFT JOIN {$wpdb->terms} as terms1 ON t1.term_id = terms1.term_id, {$wpdb->posts} as p2 LEFT JOIN {$wpdb->term_relationships} as r2 ON p2.ID = r2.object_ID LEFT JOIN {$wpdb->term_taxonomy} as t2 ON r2.term_taxonomy_id = t2.term_taxonomy_id \tLEFT JOIN {$wpdb->terms} as terms2 ON t2.term_id = terms2.term_id \tWHERE t1.taxonomy = 'category' AND p1.post_status = 'publish' AND p1.post_date <= '{$now}' AND p1.post_date > '" . date('Y-m-d H:i:s', strtotime('-' . $days . ' days')) . "' AND terms1.term_id = '{$catid}' AND t2.taxonomy = 'post_tag' AND p2.post_status = 'publish' AND p2.post_date <= '{$now}' AND \tp2.post_date > '" . date('Y-m-d H:i:s', strtotime('-' . $days . ' days')) . "' AND \tp1.ID = p2.ID ORDER BY count DESC LIMIT {$limit}"; $terms = $wpdb->get_results($popterms); if ($terms) { $args = array('smallest' => 18, 'largest' => 18, 'unit' => 'px', 'number' => $limit, 'format' => 'flat', 'separator' => "\n", 'orderby' => 'name', 'order' => 'ASC', 'link' => 'view', 'taxonomy' => 'post_tag', 'echo' => true); // Create links foreach ($terms as $key => $tag) { if ('edit' == $args['link']) { $link = get_edit_tag_link($tag->term_id, $args['taxonomy']); } else { $link = get_term_link(intval($tag->term_id), $args['taxonomy']); } if (is_wp_error($link)) { return false; } $tag_link = '#' != $tag->link ? esc_url($link) : '#'; $tag_id = isset($tag->term_id) ? $tag->term_id : $key; $tag_name = $terms[$key]->name; echo "<a href='{$tag_link}' class='tag-link-{$tag_id}' title='" . esc_attr($tag->count) . " posts'>{$tag_name}</a>"; } //echo wp_generate_tag_cloud( $terms, $args ); } }
/** * Display or retrieve edit tag link with formatting. * * @since 2.7.0 * * @param string $link Optional. Anchor text. * @param string $before Optional. Display before edit link. * @param string $after Optional. Display after edit link. * @param int|object $tag Tag object or ID * @return string|null HTML content, if $echo is set to false. */ function edit_tag_link( $link = '', $before = '', $after = '', $tag = null ) { $tag = get_term($tag, 'post_tag'); if ( !current_user_can('manage_categories') ) return; if ( empty($link) ) $link = __('Edit This'); $link = '<a href="' . get_edit_tag_link( $tag->term_id ) . '" title="' . __( 'Edit tag' ) . '">' . $link . '</a>'; echo $before . apply_filters( 'edit_tag_link', $link, $tag->term_id ) . $after; }
/** * The MLA Tag Cloud support function. * * This is an alternative to the WordPress wp_tag_cloud function, with additional * options to customize the hyperlink behind each term. * * @since 1.60 * * @param array $attr Attributes of the shortcode. * * @return string HTML content to display the tag cloud. */ public static function mla_tag_cloud($attr) { global $post; /* * These are the default parameters for tag cloud display */ $mla_item_specific_arguments = array('mla_link_attributes' => '', 'mla_link_class' => '', 'mla_link_style' => '', 'mla_link_href' => '', 'mla_link_text' => '', 'mla_nolink_text' => '', 'mla_rollover_text' => '', 'mla_caption' => ''); $mla_arguments = array_merge(array('mla_output' => 'flat', 'mla_style' => NULL, 'mla_markup' => NULL, 'mla_float' => is_rtl() ? 'right' : 'left', 'mla_itemwidth' => MLAOptions::mla_get_option('mla_tag_cloud_itemwidth'), 'mla_margin' => MLAOptions::mla_get_option('mla_tag_cloud_margin'), 'mla_target' => '', 'mla_debug' => false, 'term_id' => NULL, 'mla_end_size' => 1, 'mla_mid_size' => 2, 'mla_prev_text' => '« ' . __('Previous', 'media-library-assistant'), 'mla_next_text' => __('Next', 'media-library-assistant') . ' »', 'mla_page_parameter' => 'mla_cloud_current', 'mla_cloud_current' => NULL, 'mla_paginate_total' => NULL, 'mla_paginate_type' => 'plain'), $mla_item_specific_arguments); $defaults = array_merge(self::$mla_get_terms_parameters, array('smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'separator' => "\n", 'single_text' => '%d item', 'multiple_text' => '%d items', 'echo' => false, 'link' => 'view', 'current_item' => '', 'current_item_class' => 'mla_current_item', 'itemtag' => 'ul', 'termtag' => 'li', 'captiontag' => '', 'columns' => MLAOptions::mla_get_option('mla_tag_cloud_columns')), $mla_arguments); /* * The mla_paginate_current parameter can be changed to support multiple galleries per page. */ if (!isset($attr['mla_page_parameter'])) { $attr['mla_page_parameter'] = $defaults['mla_page_parameter']; } $mla_page_parameter = $attr['mla_page_parameter']; /* * Special handling of mla_page_parameter to make * "MLA pagination" easier. Look for this parameter in $_REQUEST * if it's not present in the shortcode itself. */ if (!isset($attr[$mla_page_parameter])) { if (isset($_REQUEST[$mla_page_parameter])) { $attr[$mla_page_parameter] = $_REQUEST[$mla_page_parameter]; } } // $instance supports multiple clouds in one page/post static $instance = 0; $instance++; /* * Some values are already known, and can be used in data selection parameters */ $upload_dir = wp_upload_dir(); $page_values = array('instance' => $instance, 'selector' => "mla_tag_cloud-{$instance}", 'site_url' => site_url(), 'base_url' => $upload_dir['baseurl'], 'base_dir' => $upload_dir['basedir'], 'id' => $post->ID, 'page_ID' => $post->ID, 'page_author' => $post->post_author, 'page_date' => $post->post_date, 'page_content' => $post->post_content, 'page_title' => $post->post_title, 'page_excerpt' => $post->post_excerpt, 'page_status' => $post->post_status, 'page_name' => $post->post_name, 'page_modified' => $post->post_modified, 'page_guid' => $post->guid, 'page_type' => $post->post_type, 'page_url' => get_page_link()); /* * Look for 'request' substitution parameters, * which can be added to any input parameter */ foreach ($attr as $attr_key => $attr_value) { /* * item-specific Display Content parameters must be evaluated * later, when all of the information is available. */ if (array_key_exists($attr_key, $mla_item_specific_arguments)) { continue; } $attr_value = str_replace('{+', '[+', str_replace('+}', '+]', $attr_value)); $replacement_values = MLAData::mla_expand_field_level_parameters($attr_value, NULL, $page_values); $attr[$attr_key] = MLAData::mla_parse_template($attr_value, $replacement_values); } $attr = apply_filters('mla_tag_cloud_attributes', $attr); $arguments = shortcode_atts($defaults, $attr); /* * $mla_page_parameter, if non-default, doesn't make it through the shortcode_atts filter, * so we handle it separately */ if (!isset($arguments[$mla_page_parameter])) { if (isset($attr[$mla_page_parameter])) { $arguments[$mla_page_parameter] = $attr[$mla_page_parameter]; } else { $arguments[$mla_page_parameter] = $defaults['mla_cloud_current']; } } /* * Process the pagination parameter, if present */ if (isset($arguments[$mla_page_parameter])) { $arguments['offset'] = $arguments['limit'] * ($arguments[$mla_page_parameter] - 1); } /* * Clean up the current_item to separate term_id from slug */ if (!empty($arguments['current_item']) && ctype_digit($arguments['current_item'])) { $arguments['current_item'] = absint($arguments['current_item']); } $arguments = apply_filters('mla_tag_cloud_arguments', $arguments); self::$mla_debug = !empty($arguments['mla_debug']) ? trim(strtolower($arguments['mla_debug'])) : false; if (self::$mla_debug) { if ('true' == self::$mla_debug) { MLA::mla_debug_mode('buffer'); } elseif ('log' == self::$mla_debug) { MLA::mla_debug_mode('log'); } else { self::$mla_debug = false; } } if (self::$mla_debug) { MLA::mla_debug_add('<strong>' . __('mla_debug attributes', 'media-library-assistant') . '</strong> = ' . var_export($attr, true)); MLA::mla_debug_add('<strong>' . __('mla_debug arguments', 'media-library-assistant') . '</strong> = ' . var_export($arguments, true)); } /* * Determine output type and templates */ $output_parameters = array_map('strtolower', array_map('trim', explode(',', $arguments['mla_output']))); if ($is_grid = 'grid' == $output_parameters[0]) { $default_style = MLAOptions::mla_get_option('default_tag_cloud_style'); $default_markup = MLAOptions::mla_get_option('default_tag_cloud_markup'); if (NULL == $arguments['mla_style']) { $arguments['mla_style'] = $default_style; } if (NULL == $arguments['mla_markup']) { $arguments['mla_markup'] = $default_markup; $arguments['itemtag'] = 'dl'; $arguments['termtag'] = 'dt'; $arguments['captiontag'] = 'dd'; } } if ($is_list = 'list' == $output_parameters[0]) { $default_style = 'none'; if (empty($arguments['captiontag'])) { $default_markup = 'tag-cloud-ul'; } else { $default_markup = 'tag-cloud-dl'; if ('dd' == $arguments['captiontag']) { $arguments['itemtag'] = 'dl'; $arguments['termtag'] = 'dt'; } } if (NULL == $arguments['mla_style']) { $arguments['mla_style'] = $default_style; } if (NULL == $arguments['mla_markup']) { $arguments['mla_markup'] = $default_markup; } } $is_pagination = in_array($output_parameters[0], array('previous_link', 'current_link', 'next_link', 'previous_page', 'next_page', 'paginate_links')); /* * Convert lists to arrays */ if (is_string($arguments['taxonomy'])) { $arguments['taxonomy'] = explode(',', $arguments['taxonomy']); } if (is_string($arguments['post_type'])) { $arguments['post_type'] = explode(',', $arguments['post_type']); } if (is_string($arguments['post_status'])) { $arguments['post_status'] = explode(',', $arguments['post_status']); } $tags = self::mla_get_terms($arguments); if (self::$mla_debug) { $cloud = MLA::mla_debug_flush(); } else { $cloud = ''; } /* * Invalid taxonomy names return WP_Error */ if (is_wp_error($tags)) { $cloud .= '<strong>' . __('ERROR', 'media-library-assistant') . ': ' . $tags->get_error_message() . '</strong>, ' . $tags->get_error_data($tags->get_error_code()); if ('array' == $arguments['mla_output']) { return array($cloud); } if (empty($arguments['echo'])) { return $cloud; } echo $cloud; return; } if (empty($tags)) { if (self::$mla_debug) { MLA::mla_debug_add('<strong>' . __('mla_debug empty cloud', 'media-library-assistant') . '</strong>, query = ' . var_export($arguments, true)); $cloud = MLA::mla_debug_flush(); } $cloud .= $arguments['mla_nolink_text']; if ('array' == $arguments['mla_output']) { return array($cloud); } if (empty($arguments['echo'])) { return $cloud; } echo $cloud; return; } /* * Fill in the item_specific link properties, calculate cloud parameters */ if (isset($tags['found_rows'])) { $found_rows = $tags['found_rows']; unset($tags['found_rows']); } else { $found_rows = count($tags); } $min_count = 0x7fffffff; $max_count = 0; $min_scaled_count = 0x7fffffff; $max_scaled_count = 0; foreach ($tags as $key => $tag) { $tag_count = isset($tag->count) ? $tag->count : 0; $tag->scaled_count = apply_filters('mla_tag_cloud_scale', round(log10($tag_count + 1) * 100), $attr, $arguments, $tag); if ($tag_count < $min_count) { $min_count = $tag_count; } if ($tag_count > $max_count) { $max_count = $tag_count; } if ($tag->scaled_count < $min_scaled_count) { $min_scaled_count = $tag->scaled_count; } if ($tag->scaled_count > $max_scaled_count) { $max_scaled_count = $tag->scaled_count; } $link = get_edit_tag_link($tag->term_id, $tag->taxonomy); if (!is_wp_error($link)) { $tags[$key]->edit_link = $link; $link = get_term_link(intval($tag->term_id), $tag->taxonomy); $tags[$key]->term_link = $link; } if (is_wp_error($link)) { $cloud = '<strong>' . __('ERROR', 'media-library-assistant') . ': ' . $link->get_error_message() . '</strong>, ' . $link->get_error_data($link->get_error_code()); if ('array' == $arguments['mla_output']) { return array($cloud); } if (empty($arguments['echo'])) { return $cloud; } echo $cloud; return; } if ('edit' == $arguments['link']) { $tags[$key]->link = $tags[$key]->edit_link; } else { $tags[$key]->link = $tags[$key]->term_link; } } // foreach tag /* * The default MLA style template includes "margin: 1.5%" to put a bit of * minimum space between the columns. "mla_margin" can be used to change * this. "mla_itemwidth" can be used with "columns=0" to achieve a * "responsive" layout. */ $columns = absint($arguments['columns']); $margin_string = strtolower(trim($arguments['mla_margin'])); if (is_numeric($margin_string) && 0 != $margin_string) { $margin_string .= '%'; // Legacy values are always in percent } if ('%' == substr($margin_string, -1)) { $margin_percent = (double) substr($margin_string, 0, strlen($margin_string) - 1); } else { $margin_percent = 0; } $width_string = strtolower(trim($arguments['mla_itemwidth'])); if ('none' != $width_string) { switch ($width_string) { case 'exact': $margin_percent = 0; // fallthru // fallthru case 'calculate': $width_string = $columns > 0 ? floor(1000 / $columns) / 10 - 2.0 * $margin_percent : 100 - 2.0 * $margin_percent; // fallthru // fallthru default: if (is_numeric($width_string) && 0 != $width_string) { $width_string .= '%'; // Legacy values are always in percent } } } // $use_width $float = strtolower($arguments['mla_float']); if (!in_array($float, array('left', 'none', 'right'))) { $float = is_rtl() ? 'right' : 'left'; } /* * Calculate cloud parameters */ $spread = $max_scaled_count - $min_scaled_count; if ($spread <= 0) { $spread = 1; } $font_spread = $arguments['largest'] - $arguments['smallest']; if ($font_spread < 0) { $font_spread = 1; } $font_step = $font_spread / $spread; $style_values = array_merge($page_values, array('mla_output' => $arguments['mla_output'], 'mla_style' => $arguments['mla_style'], 'mla_markup' => $arguments['mla_markup'], 'taxonomy' => implode('-', $arguments['taxonomy']), 'current_item' => $arguments['current_item'], 'itemtag' => tag_escape($arguments['itemtag']), 'termtag' => tag_escape($arguments['termtag']), 'captiontag' => tag_escape($arguments['captiontag']), 'columns' => $columns, 'itemwidth' => $width_string, 'margin' => $margin_string, 'float' => $float, 'found_rows' => $found_rows, 'min_count' => $min_count, 'max_count' => $max_count, 'min_scaled_count' => $min_scaled_count, 'max_scaled_count' => $max_scaled_count, 'spread' => $spread, 'smallest' => $arguments['smallest'], 'largest' => $arguments['largest'], 'unit' => $arguments['unit'], 'font_spread' => $font_spread, 'font_step' => $font_step, 'separator' => $arguments['separator'], 'single_text' => $arguments['single_text'], 'multiple_text' => $arguments['multiple_text'], 'echo' => $arguments['echo'], 'link' => $arguments['link'])); $style_template = $gallery_style = ''; $use_mla_tag_cloud_style = ($is_grid || $is_list) && 'none' != strtolower($style_values['mla_style']); if (apply_filters('use_mla_tag_cloud_style', $use_mla_tag_cloud_style, $style_values['mla_style'])) { $style_template = MLAOptions::mla_fetch_gallery_template($style_values['mla_style'], 'style'); if (empty($style_template)) { $style_values['mla_style'] = $default_style; $style_template = MLAOptions::mla_fetch_gallery_template($default_style, 'style'); } if (!empty($style_template)) { /* * Look for 'query' and 'request' substitution parameters */ $style_values = MLAData::mla_expand_field_level_parameters($style_template, $attr, $style_values); /* * Clean up the template to resolve width or margin == 'none' */ if ('none' == $margin_string) { $style_values['margin'] = '0'; $style_template = preg_replace('/margin:[\\s]*\\[\\+margin\\+\\][\\%]*[\\;]*/', '', $style_template); } if ('none' == $width_string) { $style_values['itemwidth'] = 'auto'; $style_template = preg_replace('/width:[\\s]*\\[\\+itemwidth\\+\\][\\%]*[\\;]*/', '', $style_template); } $style_values = apply_filters('mla_tag_cloud_style_values', $style_values); $style_template = apply_filters('mla_tag_cloud_style_template', $style_template); $gallery_style = MLAData::mla_parse_template($style_template, $style_values); $gallery_style = apply_filters('mla_tag_cloud_style_parse', $gallery_style, $style_template, $style_values); } // !empty template } // use_mla_tag_cloud_style $markup_values = $style_values; if ($is_grid || $is_list) { $open_template = MLAOptions::mla_fetch_gallery_template($markup_values['mla_markup'] . '-open', 'markup'); if (false === $open_template) { $markup_values['mla_markup'] = $default_markup; $open_template = MLAOptions::mla_fetch_gallery_template($default_markup, 'markup'); } if (empty($open_template)) { $open_template = ''; } if ($is_grid) { $row_open_template = MLAOptions::mla_fetch_gallery_template($markup_values['mla_markup'] . '-row-open', 'markup'); if (empty($row_open_template)) { $row_open_template = ''; } } else { $row_open_template = ''; } $item_template = MLAOptions::mla_fetch_gallery_template($markup_values['mla_markup'] . '-item', 'markup'); if (empty($item_template)) { $item_template = ''; } if ($is_grid) { $row_close_template = MLAOptions::mla_fetch_gallery_template($markup_values['mla_markup'] . '-row-close', 'markup'); if (empty($row_close_template)) { $row_close_template = ''; } } else { $row_close_template = ''; } $close_template = MLAOptions::mla_fetch_gallery_template($markup_values['mla_markup'] . '-close', 'markup'); if (empty($close_template)) { $close_template = ''; } /* * Look for gallery-level markup substitution parameters */ $new_text = $open_template . $row_open_template . $row_close_template . $close_template; $markup_values = MLAData::mla_expand_field_level_parameters($new_text, $attr, $markup_values); $markup_values = apply_filters('mla_tag_cloud_open_values', $markup_values); $open_template = apply_filters('mla_tag_cloud_open_template', $open_template); if (empty($open_template)) { $gallery_open = ''; } else { $gallery_open = MLAData::mla_parse_template($open_template, $markup_values); } $gallery_open = apply_filters('mla_tag_cloud_open_parse', $gallery_open, $open_template, $markup_values); $cloud .= $gallery_style . $gallery_open; } elseif ($is_pagination) { /* * Handle 'previous_page', 'next_page', and 'paginate_links' */ if (isset($attr['limit'])) { $attr['posts_per_page'] = $attr['limit']; } $pagination_result = self::_process_pagination_output_types($output_parameters, $markup_values, $arguments, $attr, $found_rows); if (false !== $pagination_result) { return $pagination_result; } /* * For "previous_link", "current_link" and "next_link", discard all of the $tags except the appropriate choice */ $link_type = $output_parameters[0]; if (!in_array($link_type, array('previous_link', 'current_link', 'next_link'))) { return ''; // unknown output type } $is_wrap = isset($output_parameters[1]) && 'wrap' == $output_parameters[1]; if (empty($arguments['term_id'])) { $target_id = -2; // won't match anything } else { $current_id = $arguments['term_id']; foreach ($tags as $id => $tag) { if ($tag->term_id == $current_id) { break; } } switch ($link_type) { case 'previous_link': $target_id = $id - 1; break; case 'next_link': $target_id = $id + 1; break; case 'current_link': default: $target_id = $id; } // link_type } $target = NULL; if (isset($tags[$target_id])) { $target = $tags[$target_id]; } elseif ($is_wrap) { switch ($link_type) { case 'previous_link': $target = array_pop($tags); break; case 'next_link': $target = array_shift($tags); } // link_type } // is_wrap if (isset($target)) { $tags = array($target); } elseif (!empty($arguments['mla_nolink_text'])) { return self::_process_shortcode_parameter($arguments['mla_nolink_text'], $markup_values) . '</a>'; } else { return ''; } } // is_pagination /* * Accumulate links for flat and array output */ $tag_links = array(); $column_index = 0; foreach ($tags as $key => $tag) { $item_values = $markup_values; /* * fill in item-specific elements */ $item_values['index'] = (string) 1 + $column_index; if ($item_values['columns'] > 0 && (1 + $column_index) % $item_values['columns'] == 0) { $item_values['last_in_row'] = 'last_in_row'; } else { $item_values['last_in_row'] = ''; } $item_values['key'] = $key; $item_values['term_id'] = $tag->term_id; $item_values['name'] = wptexturize($tag->name); $item_values['slug'] = wptexturize($tag->slug); $item_values['term_group'] = $tag->term_group; $item_values['term_taxonomy_id'] = $tag->term_taxonomy_id; $item_values['taxonomy'] = wptexturize($tag->taxonomy); $item_values['current_item_class'] = ''; $item_values['description'] = wptexturize($tag->description); $item_values['parent'] = $tag->parent; $item_values['count'] = isset($tag->count) ? $tag->count : 0; $item_values['scaled_count'] = $tag->scaled_count; $item_values['font_size'] = str_replace(',', '.', $item_values['smallest'] + ($item_values['scaled_count'] - $item_values['min_scaled_count']) * $item_values['font_step']); $item_values['link_url'] = $tag->link; $item_values['editlink_url'] = $tag->edit_link; $item_values['termlink_url'] = $tag->term_link; // Added in the code below: // 'caption', 'link_attributes', 'current_item_class', 'rollover_text', 'link_style', 'link_text', 'editlink', 'termlink', 'thelink' if (!empty($arguments['current_item'])) { if (is_integer($arguments['current_item'])) { if ($arguments['current_item'] == $tag->term_id) { $item_values['current_item_class'] = $arguments['current_item_class']; } } else { if ($arguments['current_item'] == $tag->slug) { $item_values['current_item_class'] = $arguments['current_item_class']; } } } /* * Add item_specific field-level substitution parameters */ $new_text = isset($item_template) ? $item_template : ''; foreach ($mla_item_specific_arguments as $index => $value) { $new_text .= str_replace('{+', '[+', str_replace('+}', '+]', $arguments[$index])); } $item_values = MLAData::mla_expand_field_level_parameters($new_text, $attr, $item_values); if ($item_values['captiontag']) { $item_values['caption'] = wptexturize($tag->description); if (!empty($arguments['mla_caption'])) { $item_values['caption'] = wptexturize(self::_process_shortcode_parameter($arguments['mla_caption'], $item_values)); } } else { $item_values['caption'] = ''; } if (!empty($arguments['mla_link_text'])) { $link_text = self::_process_shortcode_parameter($arguments['mla_link_text'], $item_values); } else { $link_text = false; } /* * Apply the Display Content parameters. */ if (!empty($arguments['mla_target'])) { $link_attributes = 'target="' . $arguments['mla_target'] . '" '; } else { $link_attributes = ''; } if (!empty($arguments['mla_link_attributes'])) { $link_attributes .= self::_process_shortcode_parameter($arguments['mla_link_attributes'], $item_values) . ' '; } if (!empty($arguments['mla_link_class'])) { $link_attributes .= 'class="' . self::_process_shortcode_parameter($arguments['mla_link_class'], $item_values) . '" '; } $item_values['link_attributes'] = $link_attributes; $item_values['rollover_text'] = sprintf(_n($item_values['single_text'], $item_values['multiple_text'], $item_values['count'], 'media-library-assistant'), number_format_i18n($item_values['count'])); if (!empty($arguments['mla_rollover_text'])) { $item_values['rollover_text'] = esc_attr(self::_process_shortcode_parameter($arguments['mla_rollover_text'], $item_values)); } if (!empty($arguments['mla_link_href'])) { $link_href = self::_process_shortcode_parameter($arguments['mla_link_href'], $item_values); $item_values['link_url'] = $link_href; } else { $link_href = ''; } if (!empty($arguments['mla_link_style'])) { $item_values['link_style'] = esc_attr(self::_process_shortcode_parameter($arguments['mla_link_style'], $item_values)); } else { $item_values['link_style'] = 'font-size: ' . $item_values['font_size'] . $item_values['unit']; } if (!empty($arguments['mla_link_text'])) { $item_values['link_text'] = esc_attr(self::_process_shortcode_parameter($arguments['mla_link_text'], $item_values)); } else { $item_values['link_text'] = $item_values['name']; } /* * Editlink, termlink and thelink */ $item_values['editlink'] = sprintf('<a %1$shref="%2$s" title="%3$s" style="%4$s">%5$s</a>', $link_attributes, $item_values['editlink_url'], $item_values['rollover_text'], $item_values['link_style'], $item_values['link_text']); $item_values['termlink'] = sprintf('<a %1$shref="%2$s" title="%3$s" style="%4$s">%5$s</a>', $link_attributes, $item_values['termlink_url'], $item_values['rollover_text'], $item_values['link_style'], $item_values['link_text']); if (!empty($link_href)) { $item_values['thelink'] = sprintf('<a %1$shref="%2$s" title="%3$s" style="%4$s">%5$s</a>', $link_attributes, $link_href, $item_values['rollover_text'], $item_values['link_style'], $item_values['link_text']); } elseif ('edit' == $arguments['link']) { $item_values['thelink'] = $item_values['editlink']; } elseif ('view' == $arguments['link']) { $item_values['thelink'] = $item_values['termlink']; } elseif ('span' == $arguments['link']) { $item_values['thelink'] = sprintf('<span %1$sstyle="%2$s">%3$s</a>', $link_attributes, $item_values['link_style'], $item_values['link_text']); } else { $item_values['thelink'] = $item_values['link_text']; } if ($is_grid || $is_list) { /* * Start of row markup */ if ($is_grid && ($markup_values['columns'] > 0 && $column_index % $markup_values['columns'] == 0)) { $markup_values = apply_filters('mla_tag_cloud_row_open_values', $markup_values); $row_open_template = apply_filters('mla_tag_cloud_row_open_template', $row_open_template); $parse_value = MLAData::mla_parse_template($row_open_template, $markup_values); $cloud .= apply_filters('mla_tag_cloud_row_open_parse', $parse_value, $row_open_template, $markup_values); } /* * item markup */ $column_index++; $item_values = apply_filters('mla_tag_cloud_item_values', $item_values); $item_template = apply_filters('mla_tag_cloud_item_template', $item_template); $parse_value = MLAData::mla_parse_template($item_template, $item_values); $cloud .= apply_filters('mla_tag_cloud_item_parse', $parse_value, $item_template, $item_values); /* * End of row markup */ if ($is_grid && ($markup_values['columns'] > 0 && $column_index % $markup_values['columns'] == 0)) { $markup_values = apply_filters('mla_tag_cloud_row_close_values', $markup_values); $row_close_template = apply_filters('mla_tag_cloud_row_close_template', $row_close_template); $parse_value = MLAData::mla_parse_template($row_close_template, $markup_values); $cloud .= apply_filters('mla_tag_cloud_row_close_parse', $parse_value, $row_close_template, $markup_values); } } elseif ($is_pagination) { return $item_values['thelink']; } else { $column_index++; $item_values = apply_filters('mla_tag_cloud_item_values', $item_values); $tag_links[] = apply_filters('mla_tag_cloud_item_parse', $item_values['thelink'], NULL, $item_values); } } // foreach tag if ($is_grid || $is_list) { /* * Close out partial row */ if ($is_grid && !($markup_values['columns'] > 0 && $column_index % $markup_values['columns'] == 0)) { $markup_values = apply_filters('mla_tag_cloud_row_close_values', $markup_values); $row_close_template = apply_filters('mla_tag_cloud_row_close_template', $row_close_template); $parse_value = MLAData::mla_parse_template($row_close_template, $markup_values); $cloud .= apply_filters('mla_tag_cloud_row_close_parse', $parse_value, $row_close_template, $markup_values); } $markup_values = apply_filters('mla_tag_cloud_close_values', $markup_values); $close_template = apply_filters('mla_tag_cloud_close_template', $close_template); $parse_value = MLAData::mla_parse_template($close_template, $markup_values); $cloud .= apply_filters('mla_tag_cloud_close_parse', $parse_value, $close_template, $markup_values); } else { switch ($markup_values['mla_output']) { case 'array': $cloud =& $tag_links; break; case 'flat': default: $cloud .= join($markup_values['separator'], $tag_links); break; } // switch format } //$cloud = wp_generate_tag_cloud( $tags, $arguments ); if ('array' == $arguments['mla_output'] || empty($arguments['echo'])) { return $cloud; } echo $cloud; }
/** * Adds an SEO admin bar menu with several options. If the current user is an admin he can also go straight to several settings menu's from here. */ function wpseo_admin_bar_menu() { // If the current user can't write posts, this is all of no use, so let's not output an admin menu. if (!current_user_can('edit_posts')) { return; } global $wp_admin_bar, $post; $admin_menu = current_user_can('manage_options'); if (!$admin_menu && is_multisite()) { $options = get_site_option('wpseo_ms'); $admin_menu = $options['access'] === 'superadmin' && is_super_admin(); } $focuskw = ''; $score = ''; $seo_url = ''; $analysis_seo = new WPSEO_Metabox_Analysis_SEO(); $analysis_readability = new WPSEO_Metabox_Analysis_Readability(); if ((is_singular() || is_admin() && in_array($GLOBALS['pagenow'], array('post.php', 'post-new.php'), true)) && isset($post) && is_object($post) && apply_filters('wpseo_use_page_analysis', true) === true) { $focuskw = WPSEO_Meta::get_value('focuskw', $post->ID); if ($analysis_seo->is_enabled()) { $score = wpseo_adminbar_seo_score(); } elseif ($analysis_readability->is_enabled()) { $score = wpseo_adminbar_content_score(); } $seo_url = get_edit_post_link($post->ID); } if (is_category() || is_tag() || WPSEO_Taxonomy::is_term_edit($GLOBALS['pagenow']) && !WPSEO_Taxonomy::is_term_overview($GLOBALS['pagenow']) || is_tax()) { if ($analysis_seo->is_enabled()) { $score = wpseo_tax_adminbar_seo_score(); } elseif ($analysis_readability->is_enabled()) { $score = wpseo_tax_adminbar_content_score(); } $seo_url = get_edit_tag_link(filter_input(INPUT_GET, 'tag_ID'), 'category'); } // Never display notifications for network admin. $counter = ''; if ($admin_menu) { $seo_url = get_admin_url(null, 'admin.php?page=' . WPSEO_Admin::PAGE_IDENTIFIER); if ('' === $score) { // Notification information. $notification_center = Yoast_Notification_Center::get(); $notification_count = $notification_center->get_notification_count(); $new_notifications = $notification_center->get_new_notifications(); $new_notifications_count = count($new_notifications); if ($notification_count > 0) { // Always show Alerts page when clicking on the main link. /* translators: %s: number of notifications */ $counter_screen_reader_text = sprintf(_n('%s notification', '%s notifications', $notification_count), number_format_i18n($notification_count)); $counter = sprintf(' <div class="wp-core-ui wp-ui-notification yoast-issue-counter"><span aria-hidden="true">%d</span><span class="screen-reader-text">%s</span></div>', $notification_count, $counter_screen_reader_text); } if ($new_notifications_count) { $notification = sprintf(_n('You have a new issue concerning your SEO!', 'You have %d new issues concerning your SEO!', $new_notifications_count, 'wordpress-seo'), $new_notifications_count); $counter .= '<div class="yoast-issue-added">' . $notification . '</div>'; } } } // Yoast Icon. $icon_svg = WPSEO_Utils::get_icon_svg(); $title = '<div id="yoast-ab-icon" class="ab-item yoast-logo svg" style="background-image: url(\'' . $icon_svg . '\');"><span class="screen-reader-text">' . __('SEO', 'wordpress-seo') . '</span></div>'; $wp_admin_bar->add_menu(array('id' => 'wpseo-menu', 'title' => $title . $score . $counter, 'href' => $seo_url)); if (!empty($notification_count)) { $wp_admin_bar->add_menu(array('parent' => 'wpseo-menu', 'id' => 'wpseo-notifications', 'title' => __('Notifications', 'wordpress-seo') . $counter, 'href' => $seo_url)); } $wp_admin_bar->add_menu(array('parent' => 'wpseo-menu', 'id' => 'wpseo-kwresearch', 'title' => __('Keyword Research', 'wordpress-seo'), 'meta' => array('tabindex' => '0'))); $wp_admin_bar->add_menu(array('parent' => 'wpseo-kwresearch', 'id' => 'wpseo-adwordsexternal', 'title' => __('AdWords External', 'wordpress-seo'), 'href' => 'http://adwords.google.com/keywordplanner', 'meta' => array('target' => '_blank'))); $wp_admin_bar->add_menu(array('parent' => 'wpseo-kwresearch', 'id' => 'wpseo-googleinsights', 'title' => __('Google Trends', 'wordpress-seo'), 'href' => 'https://www.google.com/trends/explore#q=' . urlencode($focuskw), 'meta' => array('target' => '_blank'))); $wp_admin_bar->add_menu(array('parent' => 'wpseo-kwresearch', 'id' => 'wpseo-wordtracker', 'title' => __('SEO Book', 'wordpress-seo'), 'href' => 'http://tools.seobook.com/keyword-tools/seobook/?keyword=' . urlencode($focuskw), 'meta' => array('target' => '_blank'))); if (!is_admin()) { $url = WPSEO_Frontend::get_instance()->canonical(false); if (is_string($url)) { $wp_admin_bar->add_menu(array('parent' => 'wpseo-menu', 'id' => 'wpseo-analysis', 'title' => __('Analyze this page', 'wordpress-seo'), 'meta' => array('tabindex' => '0'))); $wp_admin_bar->add_menu(array('parent' => 'wpseo-analysis', 'id' => 'wpseo-inlinks-ose', 'title' => __('Check Inlinks (OSE)', 'wordpress-seo'), 'href' => '//moz.com/researchtools/ose/links?site=' . urlencode($url), 'meta' => array('target' => '_blank'))); $wp_admin_bar->add_menu(array('parent' => 'wpseo-analysis', 'id' => 'wpseo-kwdensity', 'title' => __('Check Keyword Density', 'wordpress-seo'), 'href' => '//www.zippy.co.uk/keyworddensity/index.php?url=' . urlencode($url) . '&keyword=' . urlencode($focuskw), 'meta' => array('target' => '_blank'))); $wp_admin_bar->add_menu(array('parent' => 'wpseo-analysis', 'id' => 'wpseo-cache', 'title' => __('Check Google Cache', 'wordpress-seo'), 'href' => '//webcache.googleusercontent.com/search?strip=1&q=cache:' . urlencode($url), 'meta' => array('target' => '_blank'))); $wp_admin_bar->add_menu(array('parent' => 'wpseo-analysis', 'id' => 'wpseo-header', 'title' => __('Check Headers', 'wordpress-seo'), 'href' => '//quixapp.com/headers/?r=' . urlencode($url), 'meta' => array('target' => '_blank'))); $wp_admin_bar->add_menu(array('parent' => 'wpseo-analysis', 'id' => 'wpseo-richsnippets', 'title' => __('Check Rich Snippets', 'wordpress-seo'), 'href' => '//www.google.com/webmasters/tools/richsnippets?q=' . urlencode($url), 'meta' => array('target' => '_blank'))); $wp_admin_bar->add_menu(array('parent' => 'wpseo-analysis', 'id' => 'wpseo-facebookdebug', 'title' => __('Facebook Debugger', 'wordpress-seo'), 'href' => '//developers.facebook.com/tools/debug/og/object?q=' . urlencode($url), 'meta' => array('target' => '_blank'))); $wp_admin_bar->add_menu(array('parent' => 'wpseo-analysis', 'id' => 'wpseo-pinterestvalidator', 'title' => __('Pinterest Rich Pins Validator', 'wordpress-seo'), 'href' => '//developers.pinterest.com/rich_pins/validator/?link=' . urlencode($url), 'meta' => array('target' => '_blank'))); $wp_admin_bar->add_menu(array('parent' => 'wpseo-analysis', 'id' => 'wpseo-htmlvalidation', 'title' => __('HTML Validator', 'wordpress-seo'), 'href' => '//validator.w3.org/check?uri=' . urlencode($url), 'meta' => array('target' => '_blank'))); $wp_admin_bar->add_menu(array('parent' => 'wpseo-analysis', 'id' => 'wpseo-cssvalidation', 'title' => __('CSS Validator', 'wordpress-seo'), 'href' => '//jigsaw.w3.org/css-validator/validator?uri=' . urlencode($url), 'meta' => array('target' => '_blank'))); $wp_admin_bar->add_menu(array('parent' => 'wpseo-analysis', 'id' => 'wpseo-pagespeed', 'title' => __('Google Page Speed Test', 'wordpress-seo'), 'href' => '//developers.google.com/speed/pagespeed/insights/?url=' . urlencode($url), 'meta' => array('target' => '_blank'))); $wp_admin_bar->add_menu(array('parent' => 'wpseo-analysis', 'id' => 'wpseo-modernie', 'title' => __('Modern IE Site Scan', 'wordpress-seo'), 'href' => '//www.modern.ie/en-us/report#' . urlencode($url), 'meta' => array('target' => '_blank'))); $wp_admin_bar->add_menu(array('parent' => 'wpseo-analysis', 'id' => 'wpseo-google-mobile-friendly', 'title' => __('Mobile-Friendly Test', 'wordpress-seo'), 'href' => 'https://www.google.com/webmasters/tools/mobile-friendly/?url=' . urlencode($url), 'meta' => array('target' => '_blank'))); } } // @todo: add links to bulk title and bulk description edit pages. if ($admin_menu) { $wp_admin_bar->add_menu(array('parent' => 'wpseo-menu', 'id' => 'wpseo-settings', 'title' => __('SEO Settings', 'wordpress-seo'), 'meta' => array('tabindex' => '0'))); $wp_admin_bar->add_menu(array('parent' => 'wpseo-settings', 'id' => 'wpseo-general', 'title' => __('Dashboard', 'wordpress-seo'), 'href' => admin_url('admin.php?page=wpseo_dashboard'))); $wp_admin_bar->add_menu(array('parent' => 'wpseo-settings', 'id' => 'wpseo-titles', 'title' => __('Titles & Metas', 'wordpress-seo'), 'href' => admin_url('admin.php?page=wpseo_titles'))); $wp_admin_bar->add_menu(array('parent' => 'wpseo-settings', 'id' => 'wpseo-social', 'title' => __('Social', 'wordpress-seo'), 'href' => admin_url('admin.php?page=wpseo_social'))); $wp_admin_bar->add_menu(array('parent' => 'wpseo-settings', 'id' => 'wpseo-xml', 'title' => __('XML Sitemaps', 'wordpress-seo'), 'href' => admin_url('admin.php?page=wpseo_xml'))); $wp_admin_bar->add_menu(array('parent' => 'wpseo-settings', 'id' => 'wpseo-wpseo-advanced', 'title' => __('Advanced', 'wordpress-seo'), 'href' => admin_url('admin.php?page=wpseo_advanced'))); $wp_admin_bar->add_menu(array('parent' => 'wpseo-settings', 'id' => 'wpseo-tools', 'title' => __('Tools', 'wordpress-seo'), 'href' => admin_url('admin.php?page=wpseo_tools'))); $wp_admin_bar->add_menu(array('parent' => 'wpseo-settings', 'id' => 'wpseo-search-console', 'title' => __('Search Console', 'wordpress-seo'), 'href' => admin_url('admin.php?page=wpseo_search_console'))); $wp_admin_bar->add_menu(array('parent' => 'wpseo-settings', 'id' => 'wpseo-licenses', 'title' => '<span style="color:#f18500">' . __('Extensions', 'wordpress-seo') . '</span>', 'href' => admin_url('admin.php?page=wpseo_licenses'))); } }
/** * Walk a list of terms and find hierarchy, preserving source order. * * @since 2.25 * * @param array $terms Term objects, by reference * @param array $arguments Shortcode arguments, including defaults * * @return array ( [taxonomy] => array( [root terms] => array( [fields], array( 'children' => [child terms] ) */ private static function _get_term_tree(&$terms, $arguments = array()) { $term = current($terms); if (empty($term) or !isset($term->parent)) { return array(); } /* * Set found_rows aside to be restored later */ if (isset($terms['found_rows'])) { $found_rows = $terms['found_rows']; unset($terms['found_rows']); } else { $found_rows = NULL; } $child_of = !empty($arguments['child_of']) ? absint($arguments['child_of']) : NULL; $include_tree = !empty($arguments['include_tree']) ? wp_parse_id_list($arguments['include_tree']) : NULL; $exclude_tree = empty($include_tree) && !empty($arguments['exclude_tree']) ? wp_parse_id_list($arguments['exclude_tree']) : NULL; $depth = !empty($arguments['depth']) ? absint($arguments['depth']) : 0; $term_tree = array(); $root_ids = array(); $parents = array(); $child_ids = array(); foreach ($terms as $term) { // TODO Make this conditional on $arguments['link'] $link = get_edit_tag_link($term->term_id, $term->taxonomy); if (!is_wp_error($link)) { $term->edit_link = $link; $link = get_term_link(intval($term->term_id), $term->taxonomy); $term->term_link = $link; } if (is_wp_error($link)) { return $link; } if ('edit' == $arguments['link']) { $term->link = $term->edit_link; } else { $term->link = $term->term_link; } $term->children = array(); $parent = absint($term->parent); if (0 == $parent) { $term_tree[$term->taxonomy][] = $term; $root_ids[$term->taxonomy][$term->term_id] = count($term_tree[$term->taxonomy]) - 1; } else { $parents[$term->taxonomy][$term->parent][] = $term; $child_ids[$term->taxonomy][$term->term_id] = absint($term->parent); } } /* * Collapse multi-level children */ foreach ($parents as $taxonomy => $tax_parents) { if (!isset($term_tree[$taxonomy])) { $term_tree[$taxonomy] = array(); $root_ids[$taxonomy] = array(); } while (!empty($tax_parents)) { foreach ($tax_parents as $parent_id => $children) { foreach ($children as $index => $child) { if (!array_key_exists($child->term_id, $tax_parents)) { if (array_key_exists($child->parent, $root_ids[$taxonomy])) { // Found a root node - attach the leaf $term_tree[$taxonomy][$root_ids[$taxonomy][$child->parent]]->children[] = $child; } elseif (isset($child_ids[$taxonomy][$child->parent])) { // Found a non-root parent node - attach the leaf $the_parent = $child_ids[$taxonomy][$child->parent]; foreach ($tax_parents[$the_parent] as $candidate_index => $candidate) { if ($candidate->term_id == $child->parent) { $parents[$taxonomy][$the_parent][$candidate_index]->children[] = $child; break; } } // foreach candidate } else { // No parent exists; make this a root node $term_tree[$taxonomy][] = $child; $root_ids[$taxonomy][$child->term_id] = count($term_tree[$taxonomy]) - 1; } // Move the leaf node unset($tax_parents[$parent_id][$index]); if (empty($tax_parents[$parent_id])) { unset($tax_parents[$parent_id]); } } // leaf node; no children } // foreach child } // foreach parent_id } // has parents } // foreach taxonomy /* * Calculate and potentially trim parent/child tree */ $all_terms_count = 0; foreach (array_keys($term_tree) as $taxonomy) { if ($child_of) { $result = self::_find_child_of($term_tree[$taxonomy], $child_of); if (false !== $result) { $term_tree[$taxonomy] = $result->children; } else { $term_tree[$taxonomy] = array(); continue; } } // $child_of if ($include_tree) { $result = self::_find_include_tree($term_tree[$taxonomy], $include_tree); if (false !== $result) { $term_tree[$taxonomy] = $result; } else { $term_tree[$taxonomy] = array(); continue; } } // $include_tree if ($exclude_tree) { self::_remove_exclude_tree($term_tree[$taxonomy], $exclude_tree); } // $include_tree $term_count = 0; $root_limit = count($term_tree[$taxonomy]); if ($root_limit) { for ($root_index = 0; $root_index < $root_limit; $root_index++) { if (isset($term_tree[$taxonomy][$root_index])) { $term_count++; $term_tree[$taxonomy][$root_index]->level = 0; if (!empty($term_tree[$taxonomy][$root_index]->children)) { $term_count += self::_count_term_children($term_tree[$taxonomy][$root_index], $depth); } } else { $root_limit++; } } } $term_tree[$taxonomy]['found_rows'] = $term_count; $all_terms_count += $term_count; } $term_tree['found_rows'] = $all_terms_count; return $term_tree; }
function wp_get_all_tags($args = '') { $tags = get_terms('post_tag'); foreach ($tags as $key => $tag) { if ('edit' == 'view') { $link = get_edit_tag_link($tag->term_id, 'post_tag'); } else { $link = get_term_link(intval($tag->term_id), 'post_tag'); } if (is_wp_error($link)) { return false; } $tags[$key]->link = $link; $tags[$key]->id = $tag->term_id; $tags[$key]->name = $tag->name; // echo ' <a href="'. $link .'">' . $tag->name . '</a>'; } return $tags; }