: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* @global array $post_type_meta_caps Used to store meta capabilities.
* @param string[] $capabilities Post type meta capabilities.
function _post_type_meta_capabilities( $capabilities = null ) {
global $post_type_meta_caps;
foreach ( $capabilities as $core => $custom ) {
if ( in_array( $core, array( 'read_post', 'delete_post', 'edit_post' ), true ) ) {
$post_type_meta_caps[ $custom ] = $core;
* Builds an object with all post type labels out of a post type object.
* Accepted keys of the label array in the post type object:
* - `name` - General name for the post type, usually plural. The same and overridden
* by `$post_type_object->label`. Default is 'Posts' / 'Pages'.
* - `singular_name` - Name for one object of this post type. Default is 'Post' / 'Page'.
* - `add_new` - Label for adding a new item. Default is 'Add New Post' / 'Add New Page'.
* - `add_new_item` - Label for adding a new singular item. Default is 'Add New Post' / 'Add New Page'.
* - `edit_item` - Label for editing a singular item. Default is 'Edit Post' / 'Edit Page'.
* - `new_item` - Label for the new item page title. Default is 'New Post' / 'New Page'.
* - `view_item` - Label for viewing a singular item. Default is 'View Post' / 'View Page'.
* - `view_items` - Label for viewing post type archives. Default is 'View Posts' / 'View Pages'.
* - `search_items` - Label for searching plural items. Default is 'Search Posts' / 'Search Pages'.
* - `not_found` - Label used when no items are found. Default is 'No posts found' / 'No pages found'.
* - `not_found_in_trash` - Label used when no items are in the Trash. Default is 'No posts found in Trash' /
* 'No pages found in Trash'.
* - `parent_item_colon` - Label used to prefix parents of hierarchical items. Not used on non-hierarchical
* post types. Default is 'Parent Page:'.
* - `all_items` - Label to signify all items in a submenu link. Default is 'All Posts' / 'All Pages'.
* - `archives` - Label for archives in nav menus. Default is 'Post Archives' / 'Page Archives'.
* - `attributes` - Label for the attributes meta box. Default is 'Post Attributes' / 'Page Attributes'.
* - `insert_into_item` - Label for the media frame button. Default is 'Insert into post' / 'Insert into page'.
* - `uploaded_to_this_item` - Label for the media frame filter. Default is 'Uploaded to this post' /
* 'Uploaded to this page'.
* - `featured_image` - Label for the featured image meta box title. Default is 'Featured image'.
* - `set_featured_image` - Label for setting the featured image. Default is 'Set featured image'.
* - `remove_featured_image` - Label for removing the featured image. Default is 'Remove featured image'.
* - `use_featured_image` - Label in the media frame for using a featured image. Default is 'Use as featured image'.
* - `menu_name` - Label for the menu name. Default is the same as `name`.
* - `filter_items_list` - Label for the table views hidden heading. Default is 'Filter posts list' /
* - `filter_by_date` - Label for the date filter in list tables. Default is 'Filter by date'.
* - `items_list_navigation` - Label for the table pagination hidden heading. Default is 'Posts list navigation' /
* 'Pages list navigation'.
* - `items_list` - Label for the table hidden heading. Default is 'Posts list' / 'Pages list'.
* - `item_published` - Label used when an item is published. Default is 'Post published.' / 'Page published.'
* - `item_published_privately` - Label used when an item is published with private visibility.
* Default is 'Post published privately.' / 'Page published privately.'
* - `item_reverted_to_draft` - Label used when an item is switched to a draft.
* Default is 'Post reverted to draft.' / 'Page reverted to draft.'
* - `item_trashed` - Label used when an item is moved to Trash. Default is 'Post trashed.' / 'Page trashed.'
* - `item_scheduled` - Label used when an item is scheduled for publishing. Default is 'Post scheduled.' /
* - `item_updated` - Label used when an item is updated. Default is 'Post updated.' / 'Page updated.'
* - `item_link` - Title for a navigation link block variation. Default is 'Post Link' / 'Page Link'.
* - `item_link_description` - Description for a navigation link block variation. Default is 'A link to a post.' /
* Above, the first default value is for non-hierarchical post types (like posts)
* and the second one is for hierarchical post types (like pages).
* Note: To set labels used in post type admin notices, see the {@see 'post_updated_messages'} filter.
* @since 4.3.0 Added the `featured_image`, `set_featured_image`, `remove_featured_image`,
* and `use_featured_image` labels.
* @since 4.4.0 Added the `archives`, `insert_into_item`, `uploaded_to_this_item`, `filter_items_list`,
* `items_list_navigation`, and `items_list` labels.
* @since 4.6.0 Converted the `$post_type` parameter to accept a `WP_Post_Type` object.
* @since 4.7.0 Added the `view_items` and `attributes` labels.
* @since 5.0.0 Added the `item_published`, `item_published_privately`, `item_reverted_to_draft`,
* `item_scheduled`, and `item_updated` labels.
* @since 5.7.0 Added the `filter_by_date` label.
* @since 5.8.0 Added the `item_link` and `item_link_description` labels.
* @since 6.3.0 Added the `item_trashed` label.
* @since 6.4.0 Changed default values for the `add_new` label to include the type of content.
* This matches `add_new_item` and provides more context for better accessibility.
* @since 6.6.0 Added the `template_name` label.
* @param object|WP_Post_Type $post_type_object Post type object.
* @return object Object with all the labels as member variables.
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 );
if ( ! isset( $post_type_object->labels->template_name ) && isset( $post_type_object->labels->singular_name ) ) {
/* translators: %s: Post type name. */
$labels->template_name = sprintf( __( 'Single item: %s' ), $post_type_object->labels->singular_name );
$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
* Possible hook names include:
* - `post_type_labels_post`
* - `post_type_labels_page`
* - `post_type_labels_attachment`
* @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 );
* Builds an object with custom-something object (post type, taxonomy) labels
* out of a custom-something object
* @param object $data_object A custom-something object.
* @param array $nohier_vs_hier_defaults Hierarchical vs non-hierarchical default labels.
* @return object Object containing labels for the given custom-something object.
function _get_custom_object_labels( $data_object, $nohier_vs_hier_defaults ) {
$data_object->labels = (array) $data_object->labels;
if ( isset( $data_object->label ) && empty( $data_object->labels['name'] ) ) {
$data_object->labels['name'] = $data_object->label;
if ( ! isset( $data_object->labels['singular_name'] ) && isset( $data_object->labels['name'] ) ) {
$data_object->labels['singular_name'] = $data_object->labels['name'];
if ( ! isset( $data_object->labels['name_admin_bar'] ) ) {
$data_object->labels['name_admin_bar'] =
isset( $data_object->labels['singular_name'] )
? $data_object->labels['singular_name']
if ( ! isset( $data_object->labels['menu_name'] ) && isset( $data_object->labels['name'] ) ) {
$data_object->labels['menu_name'] = $data_object->labels['name'];
if ( ! isset( $data_object->labels['all_items'] ) && isset( $data_object->labels['menu_name'] ) ) {
$data_object->labels['all_items'] = $data_object->labels['menu_name'];
if ( ! isset( $data_object->labels['archives'] ) && isset( $data_object->labels['all_items'] ) ) {
$data_object->labels['archives'] = $data_object->labels['all_items'];
foreach ( $nohier_vs_hier_defaults as $key => $value ) {
$defaults[ $key ] = $data_object->hierarchical ? $value[1] : $value[0];
$labels = array_merge( $defaults, $data_object->labels );
$data_object->labels = (object) $data_object->labels;
* Adds submenus for post types.
function _add_post_type_submenus() {
foreach ( get_post_types( array( 'show_ui' => true ) ) as $ptype ) {
$ptype_obj = get_post_type_object( $ptype );
if ( ! $ptype_obj->show_in_menu || true === $ptype_obj->show_in_menu ) {
add_submenu_page( $ptype_obj->show_in_menu, $ptype_obj->labels->name, $ptype_obj->labels->all_items, $ptype_obj->cap->edit_posts, "edit.php?post_type=$ptype" );
* Registers support of certain features for a post type.
* All core features are directly associated with a functional area of the edit
* screen, such as the editor or a meta box. Features include: 'title', 'editor',
* 'comments', 'revisions', 'trackbacks', 'author', 'excerpt', 'page-attributes',
* 'thumbnail', 'custom-fields', and 'post-formats'.
* Additionally, the 'revisions' feature dictates whether the post type will
* store revisions, the 'autosave' feature dictates whether the post type
* will be autosaved, and the 'comments' feature dictates whether the comments
* count will show on the edit screen.
* A third, optional parameter can also be passed along with a feature to provide
* additional information about supporting that feature.
* add_post_type_support( 'my_post_type', 'comments' );
* add_post_type_support( 'my_post_type', array(
* add_post_type_support( 'my_post_type', 'my_feature', array(
* @since 5.3.0 Formalized the existing and already documented `...$args` parameter
* by adding it to the function signature.
* @global array $_wp_post_type_features
* @param string $post_type The post type for which to add the feature.
* @param string|array $feature The feature being added, accepts an array of
* feature strings or a single string.
* @param mixed ...$args Optional extra arguments to pass along with certain features.
function add_post_type_support( $post_type, $feature, ...$args ) {
global $_wp_post_type_features;
$features = (array) $feature;
foreach ( $features as $feature ) {
$_wp_post_type_features[ $post_type ][ $feature ] = $args;
$_wp_post_type_features[ $post_type ][ $feature ] = true;
* Removes support for a feature from a post type.
* @global array $_wp_post_type_features
* @param string $post_type The post type for which to remove the feature.
* @param string $feature The feature being removed.
function remove_post_type_support( $post_type, $feature ) {
global $_wp_post_type_features;
unset( $_wp_post_type_features[ $post_type ][ $feature ] );
* Gets all the post type features
* @global array $_wp_post_type_features
* @param string $post_type The post type.
* @return array Post type supports list.
function get_all_post_type_supports( $post_type ) {
global $_wp_post_type_features;
if ( isset( $_wp_post_type_features[ $post_type ] ) ) {
return $_wp_post_type_features[ $post_type ];
* Checks a post type's support for a given feature.
* @global array $_wp_post_type_features
* @param string $post_type The post type being checked.
* @param string $feature The feature being checked.
* @return bool Whether the post type supports the given feature.
function post_type_supports( $post_type, $feature ) {
global $_wp_post_type_features;
return ( isset( $_wp_post_type_features[ $post_type ][ $feature ] ) );
* Retrieves a list of post type names that support a specific feature.
* @global array $_wp_post_type_features Post type features
* @param array|string $feature Single feature or an array of features the post types should support.
* @param string $operator Optional. The logical operation to perform. 'or' means
* only one element from the array needs to match; 'and'
* means all elements must match; 'not' means no elements may
* @return string[] A list of post type names.
function get_post_types_by_support( $feature, $operator = 'and' ) {
global $_wp_post_type_features;
$features = array_fill_keys( (array) $feature, true );
return array_keys( wp_filter_object_list( $_wp_post_type_features, $features, $operator ) );
* Updates the post type for the post ID.
* The page or post cache will be cleaned for the post ID.
* @global wpdb $wpdb WordPress database abstraction object.
* @param int $post_id Optional. Post ID to change post type. Default 0.
* @param string $post_type Optional. Post type. Accepts 'post' or 'page' to
* name a few. Default 'post'.
* @return int|false Amount of rows changed. Should be 1 for success and 0 for failure.
function set_post_type( $post_id = 0, $post_type = 'post' ) {
$post_type = sanitize_post_field( 'post_type', $post_type, $post_id, 'db' );
$return = $wpdb->update( $wpdb->posts, array( 'post_type' => $post_type ), array( 'ID' => $post_id ) );
clean_post_cache( $post_id );
* Determines whether a post type is considered "viewable".
* For built-in post types such as posts and pages, the 'public' value will be evaluated.
* For all others, the 'publicly_queryable' value will be used.
* @since 4.5.0 Added the ability to pass a post type name in addition to object.
* @since 4.6.0 Converted the `$post_type` parameter to accept a `WP_Post_Type` object.
* @since 5.9.0 Added `is_post_type_viewable` hook to filter the result.
* @param string|WP_Post_Type $post_type Post type name or object.
* @return bool Whether the post type should be considered viewable.
function is_post_type_viewable( $post_type ) {
if ( is_scalar( $post_type ) ) {
$post_type = get_post_type_object( $post_type );
if ( ! is_object( $post_type ) ) {
$is_viewable = $post_type->publicly_queryable || ( $post_type->_builtin && $post_type->public );
* Filters whether a post type is considered "viewable".
* The returned filtered value must be a boolean type to ensure
* `is_post_type_viewable()` only returns a boolean. This strictness
* is by design to maintain backwards-compatibility and guard against
* potential type errors in PHP 8.1+. Non-boolean values (even falsey
* and truthy values) will result in the function returning false.
* @param bool $is_viewable Whether the post type is "viewable" (strict type).
* @param WP_Post_Type $post_type Post type object.
return true === apply_filters( 'is_post_type_viewable', $is_viewable, $post_type );
* Determines whether a post status is considered "viewable".
* For built-in post statuses such as publish and private, the 'public' value will be evaluated.
* For all others, the 'publicly_queryable' value will be used.
* @since 5.9.0 Added `is_post_status_viewable` hook to filter the result.
* @param string|stdClass $post_status Post status name or object.
* @return bool Whether the post status should be considered viewable.
function is_post_status_viewable( $post_status ) {
if ( is_scalar( $post_status ) ) {
$post_status = get_post_status_object( $post_status );
! is_object( $post_status ) ||
$post_status->internal ||
$is_viewable = $post_status->publicly_queryable || ( $post_status->_builtin && $post_status->public );
* Filters whether a post status is considered "viewable".
* The returned filtered value must be a boolean type to ensure
* `is_post_status_viewable()` only returns a boolean. This strictness
* is by design to maintain backwards-compatibility and guard against
* potential type errors in PHP 8.1+. Non-boolean values (even falsey
* and truthy values) will result in the function returning false.
* @param bool $is_viewable Whether the post status is "viewable" (strict type).
* @param stdClass $post_status Post status object.
return true === apply_filters( 'is_post_status_viewable', $is_viewable, $post_status );
* Determines whether a post is publicly viewable.
* Posts are considered publicly viewable if both the post status and post type
* @param int|WP_Post|null $post Optional. Post ID or post object. Defaults to global $post.
* @return bool Whether the post is publicly viewable.
function is_post_publicly_viewable( $post = null ) {
$post = get_post( $post );
$post_type = get_post_type( $post );
$post_status = get_post_status( $post );
return is_post_type_viewable( $post_type ) && is_post_status_viewable( $post_status );
* Retrieves an array of the latest posts, or posts matching the given criteria.
* For more information on the accepted arguments, see the
* {@link https://developer.wordpress.org/reference/classes/wp_query/
* WP_Query} documentation in the Developer Handbook.
* The `$ignore_sticky_posts` and `$no_found_rows` arguments are ignored by
* this function and both are set to `true`.
* The defaults are as follows:
* @see WP_Query::parse_query()
* Optional. Arguments to retrieve posts. See WP_Query::parse_query() for all available arguments.
* @type int $numberposts Total number of posts to retrieve. Is an alias of `$posts_per_page`
* in WP_Query. Accepts -1 for all. Default 5.
* @type int|string $category Category ID or comma-separated list of IDs (this or any children).
* Is an alias of `$cat` in WP_Query. Default 0.
* @type int[] $include An array of post IDs to retrieve, sticky posts will be included.
* Is an alias of `$post__in` in WP_Query. Default empty array.
* @type int[] $exclude An array of post IDs not to retrieve. Default empty array.
* @type bool $suppress_filters Whether to suppress filters. Default true.