返回介绍

_get_custom_object_labels()

发布于 2017-09-11 13:23:39 字数 2878 浏览 959 评论 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.

_get_custom_object_labels( object $object,  array $nohier_vs_hier_defaults )

Build an object with custom-something object (post type, taxonomy) labels out of a custom-something object


description


参数

$object

(object) (Required) A custom-something object.

$nohier_vs_hier_defaults

(array) (Required) Hierarchical vs non-hierarchical default labels.


返回值

(object) Object containing labels for the given custom-something object.


源代码

File: wp-includes/post.php

function _get_custom_object_labels( $object, $nohier_vs_hier_defaults ) {
	$object->labels = (array) $object->labels;

	if ( isset( $object->label ) && empty( $object->labels['name'] ) )
		$object->labels['name'] = $object->label;

	if ( !isset( $object->labels['singular_name'] ) && isset( $object->labels['name'] ) )
		$object->labels['singular_name'] = $object->labels['name'];

	if ( ! isset( $object->labels['name_admin_bar'] ) )
		$object->labels['name_admin_bar'] = isset( $object->labels['singular_name'] ) ? $object->labels['singular_name'] : $object->name;

	if ( !isset( $object->labels['menu_name'] ) && isset( $object->labels['name'] ) )
		$object->labels['menu_name'] = $object->labels['name'];

	if ( !isset( $object->labels['all_items'] ) && isset( $object->labels['menu_name'] ) )
		$object->labels['all_items'] = $object->labels['menu_name'];

	if ( !isset( $object->labels['archives'] ) && isset( $object->labels['all_items'] ) ) {
		$object->labels['archives'] = $object->labels['all_items'];
	}

	$defaults = array();
	foreach ( $nohier_vs_hier_defaults as $key => $value ) {
		$defaults[$key] = $object->hierarchical ? $value[1] : $value[0];
	}
	$labels = array_merge( $defaults, $object->labels );
	$object->labels = (object) $object->labels;

	return (object) $labels;
}

更新日志

Versiondescription
3.0.0Introduced.

相关函数

Used By

  • wp-includes/taxonomy.php: get_taxonomy_labels()
  • wp-includes/post.php: get_post_type_labels()

User Contributed Notes

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

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

发布评论

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