_get_custom_object_labels

函数
_get_custom_object_labels ( $object, $nohier_vs_hier_defaults )
Access
Private
参数
  • (object) $object A custom-something object.
    Required:
  • (array) $nohier_vs_hier_defaults Hierarchical vs non-hierarchical default labels.
    Required:
返回值
  • (object) Object containing labels for the given custom-something object.
定义位置
相关方法
wp_get_custom_cssget_post_type_labelsget_custom_headerwp_get_object_termsget_taxonomy_labels
引入
3.0.0
弃用
-

_get_custom_object_labels: 这是一个用于获取自定义文章类型或分类法的自定义标签的函数。它接受一个文章类型或分类法的名称作为参数,并返回一个自定义标签的数组。

从一个自定义对象中建立一个带有自定义对象(文章类型、分类法)标签的对象。

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

常见问题

FAQs
查看更多 >