Make WordPress Core


Ignore:
Timestamp:
10/17/2022 05:58:36 PM (22 months ago)
Author:
audrasjb
Message:

Grouped backports to the 5.5 branch.

  • Editor: Bump @wordpress packages for the branch,
  • Media: Refactor search by filename within the admin,
  • REST API: Lockdown post parameter of the terms endpoint,
  • Customize: Escape blogname option in underscores templates,
  • Query: Validate relation in WP_Date_Query,
  • Posts, Post types: Apply KSES to post-by-email content,
  • General: Validate host on "Are you sure?" screen,
  • Posts, Post types: Remove emails from post-by-email logs,
  • Pings/trackbacks: Apply KSES to all trackbacks,
  • Mail: Reset PHPMailer properties between use,
  • Comments: Apply kses when editing comments,
  • Widgets: Escape RSS error messages for display.

Merges [54521-54530] to the 5.5 branch.
Props audrasjb, costdev, cu121, dd32, davidbaumwald, ehtis, johnbillion, johnjamesjacoby, martinkrcho, matveb, oztaser, paulkevan, peterwilsoncc, ravipatel, SergeyBiryukov, talldanwp, timothyblynjacobs, tykoted, voldemortensen, vortfu, xknown.

Location:
branches/5.5
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/5.5

  • branches/5.5/src/wp-includes/post.php

    r52468 r54556  
    19761976 * @since 4.5.0 Added the ability to pass a post type name in addition to object.
    19771977 * @since 4.6.0 Converted the `$post_type` parameter to accept a `WP_Post_Type` object.
     1978 * @since 5.9.0 Added `is_post_type_viewable` hook to filter the result.
    19781979 *
    19791980 * @param string|WP_Post_Type $post_type Post type name or object.
     
    19831984    if ( is_scalar( $post_type ) ) {
    19841985        $post_type = get_post_type_object( $post_type );
     1986
    19851987        if ( ! $post_type ) {
    19861988            return false;
     
    19881990    }
    19891991
    1990     return $post_type->publicly_queryable || ( $post_type->_builtin && $post_type->public );
     1992    if ( ! is_object( $post_type ) ) {
     1993        return false;
     1994    }
     1995
     1996    $is_viewable = $post_type->publicly_queryable || ( $post_type->_builtin && $post_type->public );
     1997
     1998    /**
     1999     * Filters whether a post type is considered "viewable".
     2000     *
     2001     * The returned filtered value must be a boolean type to ensure
     2002     * `is_post_type_viewable()` only returns a boolean. This strictness
     2003     * is by design to maintain backwards-compatibility and guard against
     2004     * potential type errors in PHP 8.1+. Non-boolean values (even falsey
     2005     * and truthy values) will result in the function returning false.
     2006     *
     2007     * @since 5.9.0
     2008     *
     2009     * @param bool         $is_viewable Whether the post type is "viewable" (strict type).
     2010     * @param WP_Post_Type $post_type   Post type object.
     2011     */
     2012    return true === apply_filters( 'is_post_type_viewable', $is_viewable, $post_type );
     2013}
     2014
     2015/**
     2016 * Determines whether a post status is considered "viewable".
     2017 *
     2018 * For built-in post statuses such as publish and private, the 'public' value will be evaluated.
     2019 * For all others, the 'publicly_queryable' value will be used.
     2020 *
     2021 * @since 5.7.0
     2022 * @since 5.9.0 Added `is_post_status_viewable` hook to filter the result.
     2023 *
     2024 * @param string|stdClass $post_status Post status name or object.
     2025 * @return bool Whether the post status should be considered viewable.
     2026 */
     2027function is_post_status_viewable( $post_status ) {
     2028    if ( is_scalar( $post_status ) ) {
     2029        $post_status = get_post_status_object( $post_status );
     2030
     2031        if ( ! $post_status ) {
     2032            return false;
     2033        }
     2034    }
     2035
     2036    if (
     2037        ! is_object( $post_status ) ||
     2038        $post_status->internal ||
     2039        $post_status->protected
     2040    ) {
     2041        return false;
     2042    }
     2043
     2044    $is_viewable = $post_status->publicly_queryable || ( $post_status->_builtin && $post_status->public );
     2045
     2046    /**
     2047     * Filters whether a post status is considered "viewable".
     2048     *
     2049     * The returned filtered value must be a boolean type to ensure
     2050     * `is_post_status_viewable()` only returns a boolean. This strictness
     2051     * is by design to maintain backwards-compatibility and guard against
     2052     * potential type errors in PHP 8.1+. Non-boolean values (even falsey
     2053     * and truthy values) will result in the function returning false.
     2054     *
     2055     * @since 5.9.0
     2056     *
     2057     * @param bool     $is_viewable Whether the post status is "viewable" (strict type).
     2058     * @param stdClass $post_status Post status object.
     2059     */
     2060    return true === apply_filters( 'is_post_status_viewable', $is_viewable, $post_status );
     2061}
     2062
     2063/**
     2064 * Determines whether a post is publicly viewable.
     2065 *
     2066 * Posts are considered publicly viewable if both the post status and post type
     2067 * are viewable.
     2068 *
     2069 * @since 5.7.0
     2070 *
     2071 * @param int|WP_Post|null $post Optional. Post ID or post object. Defaults to global $post.
     2072 * @return bool Whether the post is publicly viewable.
     2073 */
     2074function is_post_publicly_viewable( $post = null ) {
     2075    $post = get_post( $post );
     2076
     2077    if ( ! $post ) {
     2078        return false;
     2079    }
     2080
     2081    $post_type   = get_post_type( $post );
     2082    $post_status = get_post_status( $post );
     2083
     2084    return is_post_type_viewable( $post_type ) && is_post_status_viewable( $post_status );
    19912085}
    19922086
     
    73317425
    73327426/**
    7333  * Filter the SQL clauses of an attachment query to include filenames.
    7334  *
    7335  * @since 4.7.0
    7336  * @access private
    7337  *
    7338  * @global wpdb $wpdb WordPress database abstraction object.
    7339  *
    7340  * @param string[] $clauses An array including WHERE, GROUP BY, JOIN, ORDER BY,
    7341  *                          DISTINCT, fields (SELECT), and LIMITS clauses.
    7342  * @return string[] The modified array of clauses.
    7343  */
    7344 function _filter_query_attachment_filenames( $clauses ) {
    7345     global $wpdb;
    7346     remove_filter( 'posts_clauses', __FUNCTION__ );
    7347 
    7348     // Add a LEFT JOIN of the postmeta table so we don't trample existing JOINs.
    7349     $clauses['join'] .= " LEFT JOIN {$wpdb->postmeta} AS sq1 ON ( {$wpdb->posts}.ID = sq1.post_id AND sq1.meta_key = '_wp_attached_file' )";
    7350 
    7351     $clauses['groupby'] = "{$wpdb->posts}.ID";
    7352 
    7353     $clauses['where'] = preg_replace(
    7354         "/\({$wpdb->posts}.post_content (NOT LIKE|LIKE) (\'[^']+\')\)/",
    7355         '$0 OR ( sq1.meta_value $1 $2 )',
    7356         $clauses['where']
    7357     );
    7358 
    7359     return $clauses;
    7360 }
    7361 
    7362 /**
    73637427 * Sets the last changed time for the 'posts' cache group.
    73647428 *
Note: See TracChangeset for help on using the changeset viewer.