Make WordPress Core

Ticket #54375: 54375.diff

File 54375.diff, 1.3 KB (added by audrasjb, 3 years ago)

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

  • src/wp-includes/post.php

    diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php
    index b6ca7c24d3..9b7aa898e2 100644
    a b function is_post_type_viewable( $post_type ) { 
    21122112 * For all others, the 'publicly_queryable' value will be used.
    21132113 *
    21142114 * @since 5.7.0
     2115 * @since 5.9.0 Added `is_post_status_viewable` hook to filter the result.
    21152116 *
    21162117 * @param string|stdClass $post_status Post status name or object.
    21172118 * @return bool Whether the post status should be considered viewable.
    function is_post_status_viewable( $post_status ) { 
    21322133                return false;
    21332134        }
    21342135
    2135         return $post_status->publicly_queryable || ( $post_status->_builtin && $post_status->public );
     2136        $is_viewable = $post_status->publicly_queryable || ( $post_status->_builtin && $post_status->public );
     2137
     2138        /**
     2139         * Filters whether a post status is considered "viewable".
     2140         *
     2141         * @since 5.9.0
     2142         *
     2143         * @param bool     $is_viewable Whether the post status is "viewable".
     2144         * @param stdClass $post_status Post status object.
     2145         */
     2146        $is_viewable = apply_filters( 'is_post_status_viewable', $is_viewable, $post_status );
     2147
     2148        // Make sure the filtered value is a boolean type before returning it.
     2149        if ( ! is_bool( $is_viewable ) {
     2150                return false;
     2151        }
     2152
     2153        return $is_viewable;
    21362154}
    21372155
    21382156/**