Make WordPress Core


Ignore:
Timestamp:
10/17/2022 06:01:26 PM (11 months ago)
Author:
audrasjb
Message:

Grouped backports to the 5.4 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.4 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.4
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/5.4

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

    r52469 r54559  
    19731973 * @since 4.5.0 Added the ability to pass a post type name in addition to object.
    19741974 * @since 4.6.0 Converted the `$post_type` parameter to accept a `WP_Post_Type` object.
     1975 * @since 5.9.0 Added `is_post_type_viewable` hook to filter the result.
    19751976 *
    19761977 * @param string|WP_Post_Type $post_type Post type name or object.
     
    19801981    if ( is_scalar( $post_type ) ) {
    19811982        $post_type = get_post_type_object( $post_type );
     1983
    19821984        if ( ! $post_type ) {
    19831985            return false;
     
    19851987    }
    19861988
    1987     return $post_type->publicly_queryable || ( $post_type->_builtin && $post_type->public );
     1989    if ( ! is_object( $post_type ) ) {
     1990        return false;
     1991    }
     1992
     1993    $is_viewable = $post_type->publicly_queryable || ( $post_type->_builtin && $post_type->public );
     1994
     1995    /**
     1996     * Filters whether a post type is considered "viewable".
     1997     *
     1998     * The returned filtered value must be a boolean type to ensure
     1999     * `is_post_type_viewable()` only returns a boolean. This strictness
     2000     * is by design to maintain backwards-compatibility and guard against
     2001     * potential type errors in PHP 8.1+. Non-boolean values (even falsey
     2002     * and truthy values) will result in the function returning false.
     2003     *
     2004     * @since 5.9.0
     2005     *
     2006     * @param bool         $is_viewable Whether the post type is "viewable" (strict type).
     2007     * @param WP_Post_Type $post_type   Post type object.
     2008     */
     2009    return true === apply_filters( 'is_post_type_viewable', $is_viewable, $post_type );
     2010}
     2011
     2012/**
     2013 * Determines whether a post status is considered "viewable".
     2014 *
     2015 * For built-in post statuses such as publish and private, the 'public' value will be evaluated.
     2016 * For all others, the 'publicly_queryable' value will be used.
     2017 *
     2018 * @since 5.7.0
     2019 * @since 5.9.0 Added `is_post_status_viewable` hook to filter the result.
     2020 *
     2021 * @param string|stdClass $post_status Post status name or object.
     2022 * @return bool Whether the post status should be considered viewable.
     2023 */
     2024function is_post_status_viewable( $post_status ) {
     2025    if ( is_scalar( $post_status ) ) {
     2026        $post_status = get_post_status_object( $post_status );
     2027
     2028        if ( ! $post_status ) {
     2029            return false;
     2030        }
     2031    }
     2032
     2033    if (
     2034        ! is_object( $post_status ) ||
     2035        $post_status->internal ||
     2036        $post_status->protected
     2037    ) {
     2038        return false;
     2039    }
     2040
     2041    $is_viewable = $post_status->publicly_queryable || ( $post_status->_builtin && $post_status->public );
     2042
     2043    /**
     2044     * Filters whether a post status is considered "viewable".
     2045     *
     2046     * The returned filtered value must be a boolean type to ensure
     2047     * `is_post_status_viewable()` only returns a boolean. This strictness
     2048     * is by design to maintain backwards-compatibility and guard against
     2049     * potential type errors in PHP 8.1+. Non-boolean values (even falsey
     2050     * and truthy values) will result in the function returning false.
     2051     *
     2052     * @since 5.9.0
     2053     *
     2054     * @param bool     $is_viewable Whether the post status is "viewable" (strict type).
     2055     * @param stdClass $post_status Post status object.
     2056     */
     2057    return true === apply_filters( 'is_post_status_viewable', $is_viewable, $post_status );
     2058}
     2059
     2060/**
     2061 * Determines whether a post is publicly viewable.
     2062 *
     2063 * Posts are considered publicly viewable if both the post status and post type
     2064 * are viewable.
     2065 *
     2066 * @since 5.7.0
     2067 *
     2068 * @param int|WP_Post|null $post Optional. Post ID or post object. Defaults to global $post.
     2069 * @return bool Whether the post is publicly viewable.
     2070 */
     2071function is_post_publicly_viewable( $post = null ) {
     2072    $post = get_post( $post );
     2073
     2074    if ( ! $post ) {
     2075        return false;
     2076    }
     2077
     2078    $post_type   = get_post_type( $post );
     2079    $post_status = get_post_status( $post );
     2080
     2081    return is_post_type_viewable( $post_type ) && is_post_status_viewable( $post_status );
    19882082}
    19892083
     
    71387232
    71397233/**
    7140  * Filter the SQL clauses of an attachment query to include filenames.
    7141  *
    7142  * @since 4.7.0
    7143  * @access private
    7144  *
    7145  * @global wpdb $wpdb WordPress database abstraction object.
    7146  *
    7147  * @param string[] $clauses An array including WHERE, GROUP BY, JOIN, ORDER BY,
    7148  *                          DISTINCT, fields (SELECT), and LIMITS clauses.
    7149  * @return string[] The modified array of clauses.
    7150  */
    7151 function _filter_query_attachment_filenames( $clauses ) {
    7152     global $wpdb;
    7153     remove_filter( 'posts_clauses', __FUNCTION__ );
    7154 
    7155     // Add a LEFT JOIN of the postmeta table so we don't trample existing JOINs.
    7156     $clauses['join'] .= " LEFT JOIN {$wpdb->postmeta} AS sq1 ON ( {$wpdb->posts}.ID = sq1.post_id AND sq1.meta_key = '_wp_attached_file' )";
    7157 
    7158     $clauses['groupby'] = "{$wpdb->posts}.ID";
    7159 
    7160     $clauses['where'] = preg_replace(
    7161         "/\({$wpdb->posts}.post_content (NOT LIKE|LIKE) (\'[^']+\')\)/",
    7162         '$0 OR ( sq1.meta_value $1 $2 )',
    7163         $clauses['where']
    7164     );
    7165 
    7166     return $clauses;
    7167 }
    7168 
    7169 /**
    71707234 * Sets the last changed time for the 'posts' cache group.
    71717235 *
Note: See TracChangeset for help on using the changeset viewer.