_make_cat_compat

函数
_make_cat_compat ( $category )
Access
Private
参数
  • (array|object|WP_Term) $category Category row object or array.
    Required:
定义位置
相关方法
wp_ajax_date_formatwp_ajax_save_attachment_compatmaybe_add_columnget_home_pathget_category_template
引入
2.3.0
弃用
-

_make_cat_compat: 这个函数通过将wp_get_post_categories函数别名为get_the_category函数来确保与旧版本的WordPress向后兼容。

从新的分类结构更新到旧的2.3之前的分类结构。

这个函数是为分类法支持而添加的,以更新新的分类结构与旧的分类结构。这将保持与依赖旧键或属性名称的插件和主题的兼容性。

参数应该只传递一个变量,而不是创建数组或对象到参数的内联。这样做的原因是,参数是通过引用传递的,除非有变量,否则PHP会失败。

没有返回值,因为所有的东西都是在你传递给它的变量上更新。这就是在PHP中使用引用传递的特点之一。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function _make_cat_compat( &$category ) {
if ( is_object( $category ) && ! is_wp_error( $category ) ) {
$category->cat_ID = $category->term_id;
$category->category_count = $category->count;
$category->category_description = $category->description;
$category->cat_name = $category->name;
$category->category_nicename = $category->slug;
$category->category_parent = $category->parent;
} elseif ( is_array( $category ) && isset( $category['term_id'] ) ) {
$category['cat_ID'] = &$category['term_id'];
$category['category_count'] = &$category['count'];
$category['category_description'] = &$category['description'];
$category['cat_name'] = &$category['name'];
$category['category_nicename'] = &$category['slug'];
$category['category_parent'] = &$category['parent'];
}
}
function _make_cat_compat( &$category ) { if ( is_object( $category ) && ! is_wp_error( $category ) ) { $category->cat_ID = $category->term_id; $category->category_count = $category->count; $category->category_description = $category->description; $category->cat_name = $category->name; $category->category_nicename = $category->slug; $category->category_parent = $category->parent; } elseif ( is_array( $category ) && isset( $category['term_id'] ) ) { $category['cat_ID'] = &$category['term_id']; $category['category_count'] = &$category['count']; $category['category_description'] = &$category['description']; $category['cat_name'] = &$category['name']; $category['category_nicename'] = &$category['slug']; $category['category_parent'] = &$category['parent']; } }
function _make_cat_compat( &$category ) {
	if ( is_object( $category ) && ! is_wp_error( $category ) ) {
		$category->cat_ID               = $category->term_id;
		$category->category_count       = $category->count;
		$category->category_description = $category->description;
		$category->cat_name             = $category->name;
		$category->category_nicename    = $category->slug;
		$category->category_parent      = $category->parent;
	} elseif ( is_array( $category ) && isset( $category['term_id'] ) ) {
		$category['cat_ID']               = &$category['term_id'];
		$category['category_count']       = &$category['count'];
		$category['category_description'] = &$category['description'];
		$category['cat_name']             = &$category['name'];
		$category['category_nicename']    = &$category['slug'];
		$category['category_parent']      = &$category['parent'];
	}
}

常见问题

FAQs
查看更多 >