返回介绍

_make_cat_compat()

发布于 2017-09-11 13:26:38 字数 3326 浏览 926 评论 0 收藏 0

Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

_make_cat_compat( array|object|WP_Term $category )

Update category structure to old pre 2.3 from new taxonomy structure.


description

This function was added for the taxonomy support to update the new category structure with the old category one. This will maintain compatibility with plugins and themes which depend on the old key or property names.

The parameter should only be passed a variable and not create the array or object inline to the parameter. The reason for this is that parameter is passed by reference and PHP will fail unless it has the variable.

There is no return value, because everything is updated on the variable you pass to it. This is one of the features with using pass by reference in PHP.


参数

$category

(array|object|WP_Term) (Required) Category Row object or array


源代码

File: wp-includes/category.php

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'];
	}
}

更新日志

Versiondescription
4.4.0The $category parameter now also accepts a WP_Term object.
2.3.0Introduced.

相关函数

Uses

  • wp-includes/load.php: is_wp_error()

Used By

  • wp-admin/includes/taxonomy.php: get_category_to_edit()
  • wp-admin/includes/taxonomy.php: wp_update_category()
  • wp-includes/category-template.php: get_the_category()
  • wp-includes/class-wp-query.php: WP_Query::get_queried_object()
  • wp-includes/category.php: get_categories()
  • wp-includes/category.php: get_category()
  • wp-includes/category.php: get_category_by_path()
  • wp-includes/category.php: get_category_by_slug()
  • Show 3 more used by Hide more used by

User Contributed Notes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文