Make WordPress Core


Ignore:
Timestamp:
10/17/2022 06:08:00 PM (2 years ago)
Author:
audrasjb
Message:

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

Legend:

Unmodified
Added
Removed
  • branches/5.2

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

    r52471 r54563  
    18841884 * @since 4.5.0 Added the ability to pass a post type name in addition to object.
    18851885 * @since 4.6.0 Converted the `$post_type` parameter to accept a `WP_Post_Type` object.
     1886 * @since 5.9.0 Added `is_post_type_viewable` hook to filter the result.
    18861887 *
    18871888 * @param string|WP_Post_Type $post_type Post type name or object.
     
    18911892    if ( is_scalar( $post_type ) ) {
    18921893        $post_type = get_post_type_object( $post_type );
     1894
    18931895        if ( ! $post_type ) {
    18941896            return false;
     
    18961898    }
    18971899
    1898     return $post_type->publicly_queryable || ( $post_type->_builtin && $post_type->public );
     1900    if ( ! is_object( $post_type ) ) {
     1901        return false;
     1902    }
     1903
     1904    $is_viewable = $post_type->publicly_queryable || ( $post_type->_builtin && $post_type->public );
     1905
     1906    /**
     1907     * Filters whether a post type is considered "viewable".
     1908     *
     1909     * The returned filtered value must be a boolean type to ensure
     1910     * `is_post_type_viewable()` only returns a boolean. This strictness
     1911     * is by design to maintain backwards-compatibility and guard against
     1912     * potential type errors in PHP 8.1+. Non-boolean values (even falsey
     1913     * and truthy values) will result in the function returning false.
     1914     *
     1915     * @since 5.9.0
     1916     *
     1917     * @param bool         $is_viewable Whether the post type is "viewable" (strict type).
     1918     * @param WP_Post_Type $post_type   Post type object.
     1919     */
     1920    return true === apply_filters( 'is_post_type_viewable', $is_viewable, $post_type );
     1921}
     1922
     1923/**
     1924 * Determines whether a post status is considered "viewable".
     1925 *
     1926 * For built-in post statuses such as publish and private, the 'public' value will be evaluated.
     1927 * For all others, the 'publicly_queryable' value will be used.
     1928 *
     1929 * @since 5.7.0
     1930 * @since 5.9.0 Added `is_post_status_viewable` hook to filter the result.
     1931 *
     1932 * @param string|stdClass $post_status Post status name or object.
     1933 * @return bool Whether the post status should be considered viewable.
     1934 */
     1935function is_post_status_viewable( $post_status ) {
     1936    if ( is_scalar( $post_status ) ) {
     1937        $post_status = get_post_status_object( $post_status );
     1938
     1939        if ( ! $post_status ) {
     1940            return false;
     1941        }
     1942    }
     1943
     1944    if (
     1945        ! is_object( $post_status ) ||
     1946        $post_status->internal ||
     1947        $post_status->protected
     1948    ) {
     1949        return false;
     1950    }
     1951
     1952    $is_viewable = $post_status->publicly_queryable || ( $post_status->_builtin && $post_status->public );
     1953
     1954    /**
     1955     * Filters whether a post status is considered "viewable".
     1956     *
     1957     * The returned filtered value must be a boolean type to ensure
     1958     * `is_post_status_viewable()` only returns a boolean. This strictness
     1959     * is by design to maintain backwards-compatibility and guard against
     1960     * potential type errors in PHP 8.1+. Non-boolean values (even falsey
     1961     * and truthy values) will result in the function returning false.
     1962     *
     1963     * @since 5.9.0
     1964     *
     1965     * @param bool     $is_viewable Whether the post status is "viewable" (strict type).
     1966     * @param stdClass $post_status Post status object.
     1967     */
     1968    return true === apply_filters( 'is_post_status_viewable', $is_viewable, $post_status );
     1969}
     1970
     1971/**
     1972 * Determines whether a post is publicly viewable.
     1973 *
     1974 * Posts are considered publicly viewable if both the post status and post type
     1975 * are viewable.
     1976 *
     1977 * @since 5.7.0
     1978 *
     1979 * @param int|WP_Post|null $post Optional. Post ID or post object. Defaults to global $post.
     1980 * @return bool Whether the post is publicly viewable.
     1981 */
     1982function is_post_publicly_viewable( $post = null ) {
     1983    $post = get_post( $post );
     1984
     1985    if ( ! $post ) {
     1986        return false;
     1987    }
     1988
     1989    $post_type   = get_post_type( $post );
     1990    $post_status = get_post_status( $post );
     1991
     1992    return is_post_type_viewable( $post_type ) && is_post_status_viewable( $post_status );
    18991993}
    19001994
     
    68646958
    68656959/**
    6866  * Filter the SQL clauses of an attachment query to include filenames.
    6867  *
    6868  * @since 4.7.0
    6869  * @access private
    6870  *
    6871  * @global wpdb $wpdb WordPress database abstraction object.
    6872  *
    6873  * @param array $clauses An array including WHERE, GROUP BY, JOIN, ORDER BY,
    6874  *                       DISTINCT, fields (SELECT), and LIMITS clauses.
    6875  * @return array The modified clauses.
    6876  */
    6877 function _filter_query_attachment_filenames( $clauses ) {
    6878     global $wpdb;
    6879     remove_filter( 'posts_clauses', __FUNCTION__ );
    6880 
    6881     // Add a LEFT JOIN of the postmeta table so we don't trample existing JOINs.
    6882     $clauses['join'] .= " LEFT JOIN {$wpdb->postmeta} AS sq1 ON ( {$wpdb->posts}.ID = sq1.post_id AND sq1.meta_key = '_wp_attached_file' )";
    6883 
    6884     $clauses['groupby'] = "{$wpdb->posts}.ID";
    6885 
    6886     $clauses['where'] = preg_replace(
    6887         "/\({$wpdb->posts}.post_content (NOT LIKE|LIKE) (\'[^']+\')\)/",
    6888         '$0 OR ( sq1.meta_value $1 $2 )',
    6889         $clauses['where']
    6890     );
    6891 
    6892     return $clauses;
    6893 }
    6894 
    6895 /**
    68966960 * Sets the last changed time for the 'posts' cache group.
    68976961 *
Note: See TracChangeset for help on using the changeset viewer.