Make WordPress Core

Changeset 52043


Ignore:
Timestamp:
11/08/2021 03:20:51 PM (3 years ago)
Author:
hellofromTonya
Message:

Posts/Post Types: Introduce 'is_post_status_viewable ' filter in is_post_status_viewable().

Introduces a new filter 'is_post_status_viewable' which allows overriding the check.

The function's return signature is a boolean type. This commit ensures
the return signature remains unchanged by requirinng a strict boolean
type of the returned filtered value.

Why?

  • To maintain this signature and backwards-compatibility.
  • To future prepare for PHP 8.1 and beyond.

An explanation is included in the filter's DocBlock.

Follow-up to [50130].

Props audrasjb, hellofromTonya, peterwilsoncc.
Fixes #54375.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/post.php

    r52041 r52043  
    21582158 *
    21592159 * @since 5.7.0
     2160 * @since 5.9.0 Added `is_post_status_viewable` hook to filter the result.
    21602161 *
    21612162 * @param string|stdClass $post_status Post status name or object.
     
    21782179    }
    21792180
    2180     return $post_status->publicly_queryable || ( $post_status->_builtin && $post_status->public );
     2181    $is_viewable = $post_status->publicly_queryable || ( $post_status->_builtin && $post_status->public );
     2182
     2183    /**
     2184     * Filters whether a post status is considered "viewable".
     2185     *
     2186     * The returned filtered value must be a boolean type to ensure
     2187     * `is_post_status_viewable()` only returns a boolean. This strictness
     2188     * is by design to maintain backwards-compatibility and guard against
     2189     * potential type errors in PHP 8.1+. Non-boolean values (even falsey
     2190     * and truthy values) will result in the function returning false.
     2191     *
     2192     * @since 5.9.0
     2193     *
     2194     * @param bool     $is_viewable Whether the post status is "viewable" (strict type).
     2195     * @param stdClass $post_status Post status object.
     2196     */
     2197    return true === apply_filters( 'is_post_status_viewable', $is_viewable, $post_status );
    21812198}
    21822199
Note: See TracChangeset for help on using the changeset viewer.