Make WordPress Core


Ignore:
Timestamp:
10/17/2022 06:03:55 PM (3 years ago)
Author:
audrasjb
Message:

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

Legend:

Unmodified
Added
Removed
  • branches/5.3

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

    r52470 r54562  
    19621962 * @since 4.5.0 Added the ability to pass a post type name in addition to object.
    19631963 * @since 4.6.0 Converted the `$post_type` parameter to accept a `WP_Post_Type` object.
     1964 * @since 5.9.0 Added `is_post_type_viewable` hook to filter the result.
    19641965 *
    19651966 * @param string|WP_Post_Type $post_type Post type name or object.
     
    19691970    if ( is_scalar( $post_type ) ) {
    19701971        $post_type = get_post_type_object( $post_type );
     1972
    19711973        if ( ! $post_type ) {
    19721974            return false;
     
    19741976    }
    19751977
    1976     return $post_type->publicly_queryable || ( $post_type->_builtin && $post_type->public );
     1978    if ( ! is_object( $post_type ) ) {
     1979        return false;
     1980    }
     1981
     1982    $is_viewable = $post_type->publicly_queryable || ( $post_type->_builtin && $post_type->public );
     1983
     1984    /**
     1985     * Filters whether a post type is considered "viewable".
     1986     *
     1987     * The returned filtered value must be a boolean type to ensure
     1988     * `is_post_type_viewable()` only returns a boolean. This strictness
     1989     * is by design to maintain backwards-compatibility and guard against
     1990     * potential type errors in PHP 8.1+. Non-boolean values (even falsey
     1991     * and truthy values) will result in the function returning false.
     1992     *
     1993     * @since 5.9.0
     1994     *
     1995     * @param bool         $is_viewable Whether the post type is "viewable" (strict type).
     1996     * @param WP_Post_Type $post_type   Post type object.
     1997     */
     1998    return true === apply_filters( 'is_post_type_viewable', $is_viewable, $post_type );
     1999}
     2000
     2001/**
     2002 * Determines whether a post status is considered "viewable".
     2003 *
     2004 * For built-in post statuses such as publish and private, the 'public' value will be evaluated.
     2005 * For all others, the 'publicly_queryable' value will be used.
     2006 *
     2007 * @since 5.7.0
     2008 * @since 5.9.0 Added `is_post_status_viewable` hook to filter the result.
     2009 *
     2010 * @param string|stdClass $post_status Post status name or object.
     2011 * @return bool Whether the post status should be considered viewable.
     2012 */
     2013function is_post_status_viewable( $post_status ) {
     2014    if ( is_scalar( $post_status ) ) {
     2015        $post_status = get_post_status_object( $post_status );
     2016
     2017        if ( ! $post_status ) {
     2018            return false;
     2019        }
     2020    }
     2021
     2022    if (
     2023        ! is_object( $post_status ) ||
     2024        $post_status->internal ||
     2025        $post_status->protected
     2026    ) {
     2027        return false;
     2028    }
     2029
     2030    $is_viewable = $post_status->publicly_queryable || ( $post_status->_builtin && $post_status->public );
     2031
     2032    /**
     2033     * Filters whether a post status is considered "viewable".
     2034     *
     2035     * The returned filtered value must be a boolean type to ensure
     2036     * `is_post_status_viewable()` only returns a boolean. This strictness
     2037     * is by design to maintain backwards-compatibility and guard against
     2038     * potential type errors in PHP 8.1+. Non-boolean values (even falsey
     2039     * and truthy values) will result in the function returning false.
     2040     *
     2041     * @since 5.9.0
     2042     *
     2043     * @param bool     $is_viewable Whether the post status is "viewable" (strict type).
     2044     * @param stdClass $post_status Post status object.
     2045     */
     2046    return true === apply_filters( 'is_post_status_viewable', $is_viewable, $post_status );
     2047}
     2048
     2049/**
     2050 * Determines whether a post is publicly viewable.
     2051 *
     2052 * Posts are considered publicly viewable if both the post status and post type
     2053 * are viewable.
     2054 *
     2055 * @since 5.7.0
     2056 *
     2057 * @param int|WP_Post|null $post Optional. Post ID or post object. Defaults to global $post.
     2058 * @return bool Whether the post is publicly viewable.
     2059 */
     2060function is_post_publicly_viewable( $post = null ) {
     2061    $post = get_post( $post );
     2062
     2063    if ( ! $post ) {
     2064        return false;
     2065    }
     2066
     2067    $post_type   = get_post_type( $post );
     2068    $post_status = get_post_status( $post );
     2069
     2070    return is_post_type_viewable( $post_type ) && is_post_status_viewable( $post_status );
    19772071}
    19782072
     
    71007194
    71017195/**
    7102  * Filter the SQL clauses of an attachment query to include filenames.
    7103  *
    7104  * @since 4.7.0
    7105  * @access private
    7106  *
    7107  * @global wpdb $wpdb WordPress database abstraction object.
    7108  *
    7109  * @param array $clauses An array including WHERE, GROUP BY, JOIN, ORDER BY,
    7110  *                       DISTINCT, fields (SELECT), and LIMITS clauses.
    7111  * @return array The modified clauses.
    7112  */
    7113 function _filter_query_attachment_filenames( $clauses ) {
    7114     global $wpdb;
    7115     remove_filter( 'posts_clauses', __FUNCTION__ );
    7116 
    7117     // Add a LEFT JOIN of the postmeta table so we don't trample existing JOINs.
    7118     $clauses['join'] .= " LEFT JOIN {$wpdb->postmeta} AS sq1 ON ( {$wpdb->posts}.ID = sq1.post_id AND sq1.meta_key = '_wp_attached_file' )";
    7119 
    7120     $clauses['groupby'] = "{$wpdb->posts}.ID";
    7121 
    7122     $clauses['where'] = preg_replace(
    7123         "/\({$wpdb->posts}.post_content (NOT LIKE|LIKE) (\'[^']+\')\)/",
    7124         '$0 OR ( sq1.meta_value $1 $2 )',
    7125         $clauses['where']
    7126     );
    7127 
    7128     return $clauses;
    7129 }
    7130 
    7131 /**
    71327196 * Sets the last changed time for the 'posts' cache group.
    71337197 *
Note: See TracChangeset for help on using the changeset viewer.