Make WordPress Core

Ticket #49628: 49628.4.diff

File 49628.4.diff, 1.2 KB (added by audrasjb, 3 years ago)

Posts, Post Types: Introduce post_type_viewable hook to filter the result of is_post_type_viewable() function.

  • src/wp-includes/post.php

    diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php
    index 0f75bf537e..3f85d4fdf9 100644
    a b function set_post_type( $post_id = 0, $post_type = 'post' ) { 
    20862086 * @since 4.4.0
    20872087 * @since 4.5.0 Added the ability to pass a post type name in addition to object.
    20882088 * @since 4.6.0 Converted the `$post_type` parameter to accept a `WP_Post_Type` object.
     2089 * @since 5.9.0 Added `post_type_viewable` hook to filter the result.
    20892090 *
    20902091 * @param string|WP_Post_Type $post_type Post type name or object.
    20912092 * @return bool Whether the post type should be considered viewable.
    function is_post_type_viewable( $post_type ) { 
    21022103                return false;
    21032104        }
    21042105
    2105         return $post_type->publicly_queryable || ( $post_type->_builtin && $post_type->public );
     2106        $is_viewable = $post_type->publicly_queryable || ( $post_type->_builtin && $post_type->public );
     2107        /**
     2108         * Filters whether a post type is considered "viewable".
     2109         *
     2110         * @since 5.9.0
     2111         *
     2112         * @param bool         $is_viewable Whether the post type is "viewable".
     2113         * @param WP_Post_Type $post_type   Post type object.
     2114         */
     2115        return apply_filters( 'post_type_viewable', $is_viewable, $post_type );
    21062116}
    21072117
    21082118/**