使用custom-something对象(post type,taxonomy)标签构建一个对象

原型

_get_custom_object_labels( object $object, array $nohier_vs_hier_defaults )

参数

$object (object) (Required) 一个自定义对象。

$nohier_vs_hier_defaults (array) (Required) 分层与非分层默认标签。

返回值

(object)  包含给定custom-something对象的标签的对象。

源文件

路径:wp-includes/post.php

<?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;
}
...
?>

其他

英文文档:https://developer.wordpress.org/reference/functions/_get_custom_object_labels/