函数原型
get_post_type_labels( object|WP_Post_Type $post_type_object ): object
函数描述
Builds an object with all post type labels out of a post type object.
是否弃用
未弃用
函数参数
-
$post_type_object
object|WP_Post_Type
Required - Post type object.
函数返回值
object Object with all the labels as member variables.
函数位置
File: wp-includes/post.php.
函数源码
function get_post_type_labels( $post_type_object ) {
$nohier_vs_hier_defaults = WP_Post_Type::get_default_labels();
$nohier_vs_hier_defaults['menu_name'] = $nohier_vs_hier_defaults['name'];
$labels = _get_custom_object_labels( $post_type_object, $nohier_vs_hier_defaults );
$post_type = $post_type_object->name;
$default_labels = clone $labels;
/**
* Filters the labels of a specific post type.
*
* The dynamic portion of the hook name, `$post_type`, refers to
* the post type slug.
*
* Possible hook names include:
*
* - `post_type_labels_post`
* - `post_type_labels_page`
* - `post_type_labels_attachment`
*
* @since 3.5.0
*
* @see get_post_type_labels() for the full list of labels.
*
* @param object $labels Object with labels for the post type as member variables.
*/
$labels = apply_filters( "post_type_labels_{$post_type}", $labels );
// Ensure that the filtered labels contain all required default values.
$labels = (object) array_merge( (array) $default_labels, (array) $labels );
return $labels;
}
源码链接
变更日志
| Version | Description |
|---|---|
| 5.8.0 | Added the item_link and item_link_description labels. |
| 5.7.0 | Added the filter_by_date label. |
| 5.0.0 | Added the item_published, item_published_privately, item_reverted_to_draft, item_scheduled, and item_updated labels. |
| 4.7.0 | Added the view_items and attributes labels. |
| 4.6.0 | Converted the $post_type parameter to accept a WP_Post_Type object. |
| 4.4.0 | Added the archives, insert_into_item, uploaded_to_this_item, filter_items_list, items_list_navigation, and items_list labels. |
| 4.3.0 | Added the featured_image, set_featured_image, remove_featured_image, and use_featured_image labels. |
| 3.0.0 | Introduced. |

