sync_category_tag_slugs()同步分类与标签

目录

描述

Synchronize category and post tag slugs when global terms are enabled.

sync_category_tag_slugs() 描述

用法

<?php sync_category_tag_slugs$term$taxonomy ); ?>

sync_category_tag_slugs() 用法

参数

$term

(object|array) (必填) The term.

默认值: None

$taxonomy

(string) (必填) The taxonomy for $term. Should be 'category' or 'post_tag', as these are the only taxonomies which are processed by this function; anything else will be returned untouched.

默认值: None

sync_category_tag_slugs() 参数

示例

This function is not intended to be called directly, but is hooked to the 'get_term' filter by default.

sync_category_tag_slugs() 示例

注意

  • 使用到: global_terms_enabled() - To check if global terms are enabled. If not the $term is not 过滤器ed.
  • 使用到: sanitize_title() - To 过滤器 $term slug if $taxonomy is 'category' or 'post_tag'.

sync_category_tag_slugs() 注意

历史

sync_category_tag_slugs() 历史

源文件

sync_category_tag_slugs() 函数的代码位于 wp-admin/includes/ms.php.

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Synchronize category and post tag slugs when global terms are enabled.
 *
 * @since 3.0.0
 *
 * @param object $term     The term.
 * @param string $taxonomy The taxonomy for $term. Should be 'category' or 'post_tag', as these are
 *                         the only taxonomies which are processed by this function; anything else
 *                         will be returned untouched.
 * @return object|array Returns `$term`, after filtering the 'slug' field with {@see sanitize_title()}
 *                      if $taxonomy is 'category' or 'post_tag'.
 */
function sync_category_tag_slugs( $term, $taxonomy ) {
	if ( global_terms_enabled() && ( $taxonomy == 'category' || $taxonomy == 'post_tag' ) ) {
		if ( is_object( $term ) ) {
			$term->slug = sanitize_title( $term->name );
		} else {
			$term['slug'] = sanitize_title( $term['name'] );
		}
	}
	return $term;
}

sync_category_tag_slugs() 源文件