Make WordPress Core

Changeset 54570


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

Grouped backports to the 5.1 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,
  • Widgets: Escape RSS error messages for display.

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

Location:
branches/5.1
Files:
20 edited

Legend:

Unmodified
Added
Removed
  • branches/5.1

  • branches/5.1/src/wp-admin/includes/ajax-actions.php

    r45939 r54570  
    27472747    // Filter query clauses to include filenames.
    27482748    if ( isset( $query['s'] ) ) {
    2749         add_filter( 'posts_clauses', '_filter_query_attachment_filenames' );
     2749        add_filter( 'wp_allow_query_attachment_by_filename', '__return_true' );
    27502750    }
    27512751
  • branches/5.1/src/wp-admin/includes/post.php

    r44670 r54570  
    12551255    // Filter query clauses to include filenames.
    12561256    if ( isset( $q['s'] ) ) {
    1257         add_filter( 'posts_clauses', '_filter_query_attachment_filenames' );
     1257        add_filter( 'wp_allow_query_attachment_by_filename', '__return_true' );
    12581258    }
    12591259
  • branches/5.1/src/wp-includes/class-wp-query.php

    r47646 r54570  
    426426    public $thumbnails_cached = false;
    427427
     428    /**
     429     * Controls whether an attachment query should include filenames or not.
     430     *
     431     * @since 6.0.3
     432     * @var bool
     433     */
     434    protected $allow_query_attachment_by_filename = false;
    428435    /**
    429436     * Cached list of search stopwords.
     
    13531360            }
    13541361
    1355             $like      = $n . $wpdb->esc_like( $term ) . $n;
    1356             $search   .= $wpdb->prepare( "{$searchand}(({$wpdb->posts}.post_title $like_op %s) $andor_op ({$wpdb->posts}.post_excerpt $like_op %s) $andor_op ({$wpdb->posts}.post_content $like_op %s))", $like, $like, $like );
     1362            $like = $n . $wpdb->esc_like( $term ) . $n;
     1363
     1364            if ( ! empty( $this->allow_query_attachment_by_filename ) ) {
     1365                $search .= $wpdb->prepare( "{$searchand}(({$wpdb->posts}.post_title $like_op %s) $andor_op ({$wpdb->posts}.post_excerpt $like_op %s) $andor_op ({$wpdb->posts}.post_content $like_op %s) $andor_op (sq1.meta_value $like_op %s))", $like, $like, $like, $like );
     1366            } else {
     1367                $search .= $wpdb->prepare( "{$searchand}(({$wpdb->posts}.post_title $like_op %s) $andor_op ({$wpdb->posts}.post_excerpt $like_op %s) $andor_op ({$wpdb->posts}.post_content $like_op %s))", $like, $like, $like );
     1368            }
    13571369            $searchand = ' AND ';
    13581370        }
     
    17371749        $q = $this->fill_query_vars( $q );
    17381750
     1751        /**
     1752         * Filters whether an attachment query should include filenames or not.
     1753         *
     1754         * @since 6.0.3
     1755         *
     1756         * @param bool $allow_query_attachment_by_filename Whether or not to include filenames.
     1757         */
     1758        $this->allow_query_attachment_by_filename = apply_filters( 'wp_allow_query_attachment_by_filename', false );
     1759        remove_all_filters( 'wp_allow_query_attachment_by_filename' );
     1760
    17391761        // Parse meta query
    17401762        $this->meta_query = new WP_Meta_Query();
     
    21672189        }
    21682190
    2169         if ( ! empty( $this->tax_query->queries ) || ! empty( $this->meta_query->queries ) ) {
     2191        if ( ! empty( $this->tax_query->queries ) || ! empty( $this->meta_query->queries ) || ! empty( $this->allow_query_attachment_by_filename ) ) {
    21702192            $groupby = "{$wpdb->posts}.ID";
    21712193        }
     
    22432265        }
    22442266        $where .= $search . $whichauthor . $whichmimetype;
     2267
     2268        if ( ! empty( $this->allow_query_attachment_by_filename ) ) {
     2269            $join .= " LEFT JOIN {$wpdb->postmeta} AS sq1 ON ( {$wpdb->posts}.ID = sq1.post_id AND sq1.meta_key = '_wp_attached_file' )";
     2270        }
    22452271
    22462272        if ( ! empty( $this->meta_query->queries ) ) {
  • branches/5.1/src/wp-includes/comment.php

    r47918 r54570  
    22842284    }
    22852285
     2286    $filter_comment = false;
     2287    if ( ! has_filter( 'pre_comment_content', 'wp_filter_kses' ) ) {
     2288        $filter_comment = ! user_can( isset( $comment['user_id'] ) ? $comment['user_id'] : 0, 'unfiltered_html' );
     2289    }
     2290
     2291    if ( $filter_comment ) {
     2292        add_filter( 'pre_comment_content', 'wp_filter_kses' );
     2293    }
     2294
    22862295    // Escape data pulled from DB.
    22872296    $comment = wp_slash( $comment );
     
    22932302
    22942303    $commentarr = wp_filter_comment( $commentarr );
     2304
     2305    if ( $filter_comment ) {
     2306        remove_filter( 'pre_comment_content', 'wp_filter_kses' );
     2307    }
    22952308
    22962309    // Now extract the merged array.
  • branches/5.1/src/wp-includes/customize/class-wp-customize-header-image-control.php

    r44600 r54570  
    131131
    132132            <button type="button" class="choice thumbnail"
    133                 data-customize-image-value="{{{data.header.url}}}"
     133                data-customize-image-value="{{data.header.url}}"
    134134                data-customize-header-image-data="{{JSON.stringify(data.header)}}">
    135135                <span class="screen-reader-text"><?php _e( 'Set image' ); ?></span>
    136                 <img src="{{{data.header.thumbnail_url}}}" alt="{{{data.header.alt_text || data.header.description}}}">
     136                <img src="{{data.header.thumbnail_url}}" alt="{{data.header.alt_text || data.header.description}}" />
    137137            </button>
    138138
  • branches/5.1/src/wp-includes/customize/class-wp-customize-site-icon-control.php

    r41162 r54570  
    6767                                <img src="{{ data.attachment.sizes.full ? data.attachment.sizes.full.url : data.attachment.url }}" alt="<?php esc_attr_e( 'Preview as a browser icon' ); ?>"/>
    6868                            </div>
    69                             <span class="browser-title" aria-hidden="true"><?php bloginfo( 'name' ); ?></span>
     69                            <span class="browser-title" aria-hidden="true"><?php echo esc_js( get_bloginfo( 'name' ) ); ?></span>
    7070                        </div>
    7171                        <img class="app-icon-preview" src="{{ data.attachment.sizes.full ? data.attachment.sizes.full.url : data.attachment.url }}" alt="<?php esc_attr_e( 'Preview as an app icon' ); ?>"/>
  • branches/5.1/src/wp-includes/date.php

    r42877 r54570  
    146146     */
    147147    public function __construct( $date_query, $default_column = 'post_date' ) {
    148         if ( isset( $date_query['relation'] ) && 'OR' === strtoupper( $date_query['relation'] ) ) {
    149             $this->relation = 'OR';
     148        if ( isset( $date_query['relation'] ) ) {
     149            $this->relation = $this->sanitize_relation( $date_query['relation'] );
    150150        } else {
    151151            $this->relation = 'AND';
     
    225225            $this->validate_date_values( $queries );
    226226        }
     227
     228        // Sanitize the relation parameter.
     229        $queries['relation'] = $this->sanitize_relation( $queries['relation'] );
    227230
    228231        foreach ( $queries as $key => $q ) {
     
    10211024        return $wpdb->prepare( "DATE_FORMAT( $column, %s ) $compare %f", $format, $time );
    10221025    }
     1026
     1027    /**
     1028     * Sanitizes a 'relation' operator.
     1029     *
     1030     * @since 6.0.3
     1031     *
     1032     * @param string $relation Raw relation key from the query argument.
     1033     * @return string Sanitized relation ('AND' or 'OR').
     1034     */
     1035    public function sanitize_relation( $relation ) {
     1036        if ( 'OR' === strtoupper( $relation ) ) {
     1037            return 'OR';
     1038        } else {
     1039            return 'AND';
     1040        }
     1041    }
    10231042}
  • branches/5.1/src/wp-includes/deprecated.php

    r43174 r54570  
    39533953    }
    39543954}
     3955
     3956/**
     3957 * Filter the SQL clauses of an attachment query to include filenames.
     3958 *
     3959 * @since 4.7.0
     3960 * @deprecated 6.0.3
     3961 * @access private
     3962 *
     3963 * @param array $clauses An array including WHERE, GROUP BY, JOIN, ORDER BY,
     3964 *                       DISTINCT, fields (SELECT), and LIMITS clauses.
     3965 * @return array The unmodified clauses.
     3966 */
     3967function _filter_query_attachment_filenames( $clauses ) {
     3968    _deprecated_function( __FUNCTION__, '6.0.3', 'add_filter( "wp_allow_query_attachment_by_filename", "__return_true" )');
     3969    remove_filter( 'posts_clauses', __FUNCTION__ );
     3970    return $clauses;
     3971}
     3972
  • branches/5.1/src/wp-includes/functions.php

    r49457 r54570  
    29182918        $html = __( 'The link you followed has expired.' );
    29192919        if ( wp_get_referer() ) {
    2920             $html .= '</p><p>';
    2921             $html .= sprintf(
     2920            $wp_http_referer = remove_query_arg( 'updated', wp_get_referer() );
     2921            $wp_http_referer = wp_validate_redirect( esc_url_raw( $wp_http_referer ) );
     2922            $html           .= '</p><p>';
     2923            $html           .= sprintf(
    29222924                '<a href="%s">%s</a>',
    2923                 esc_url( remove_query_arg( 'updated', wp_get_referer() ) ),
     2925                esc_url( $wp_http_referer ),
    29242926                __( 'Please try again.' )
    29252927            );
  • branches/5.1/src/wp-includes/media-template.php

    r43976 r54570  
    13131313                <img id="preview-favicon" src="{{ data.url }}" alt="<?php esc_attr_e( 'Preview as a browser icon' ); ?>"/>
    13141314            </div>
    1315             <span class="browser-title" aria-hidden="true"><?php bloginfo( 'name' ); ?></span>
     1315            <span class="browser-title" aria-hidden="true"><?php echo esc_js( get_bloginfo( 'name' ) ); ?></span>
    13161316        </div>
    13171317
  • branches/5.1/src/wp-includes/pluggable.php

    r47963 r54570  
    315315        $phpmailer->clearCustomHeaders();
    316316        $phpmailer->clearReplyTos();
     317        $phpmailer->Body    = '';
     318        $phpmailer->AltBody = '';
    317319
    318320        // From email and name
  • branches/5.1/src/wp-includes/post.php

    r52472 r54570  
    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 *
  • branches/5.1/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php

    r44309 r54570  
    4949        // Filter query clauses to include filenames.
    5050        if ( isset( $query_args['s'] ) ) {
    51             add_filter( 'posts_clauses', '_filter_query_attachment_filenames' );
     51            add_filter( 'wp_allow_query_attachment_by_filename', '__return_true' );
    5252        }
    5353
  • branches/5.1/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php

    r43987 r54570  
    136136
    137137    /**
     138     * Checks if the terms for a post can be read.
     139     *
     140     * @since 6.0.3
     141     *
     142     * @param WP_Post         $post    Post object.
     143     * @param WP_REST_Request $request Full details about the request.
     144     * @return bool Whether the terms for the post can be read.
     145     */
     146    public function check_read_terms_permission_for_post( $post, $request ) {
     147        // If the requested post isn't associated with this taxonomy, deny access.
     148        if ( ! is_object_in_taxonomy( $post->post_type, $this->taxonomy ) ) {
     149            return false;
     150        }
     151
     152        // Grant access if the post is publicly viewable.
     153        if ( is_post_publicly_viewable( $post ) ) {
     154            return true;
     155        }
     156
     157        // Otherwise grant access if the post is readable by the logged in user.
     158        if ( current_user_can( 'read_post', $post->ID ) ) {
     159            return true;
     160        }
     161
     162        // Otherwise, deny access.
     163        return false;
     164    }
     165
     166    /**
    138167     * Checks if a request has access to read terms in the specified taxonomy.
    139168     *
     
    145174    public function get_items_permissions_check( $request ) {
    146175        $tax_obj = get_taxonomy( $this->taxonomy );
     176
    147177        if ( ! $tax_obj || ! $this->check_is_taxonomy_allowed( $this->taxonomy ) ) {
    148178            return false;
    149179        }
     180
    150181        if ( 'edit' === $request['context'] && ! current_user_can( $tax_obj->cap->edit_terms ) ) {
    151             return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to edit terms in this taxonomy.' ), array( 'status' => rest_authorization_required_code() ) );
    152         }
     182            return new WP_Error(
     183                'rest_forbidden_context',
     184                __( 'Sorry, you are not allowed to edit terms in this taxonomy.' ),
     185                array( 'status' => rest_authorization_required_code() )
     186            );
     187        }
     188
     189        if ( ! empty( $request['post'] ) ) {
     190            $post = get_post( $request['post'] );
     191
     192            if ( ! $post ) {
     193                return new WP_Error(
     194                    'rest_post_invalid_id',
     195                    __( 'Invalid post ID.' ),
     196                    array(
     197                        'status' => 400,
     198                    )
     199                );
     200            }
     201
     202            if ( ! $this->check_read_terms_permission_for_post( $post, $request ) ) {
     203                return new WP_Error(
     204                    'rest_forbidden_context',
     205                    __( 'Sorry, you are not allowed to view terms for this post.' ),
     206                    array(
     207                        'status' => rest_authorization_required_code(),
     208                    )
     209                );
     210            }
     211        }
     212
    153213        return true;
    154214    }
  • branches/5.1/src/wp-includes/widgets.php

    r44585 r54570  
    14471447    if ( is_wp_error( $rss ) ) {
    14481448        if ( is_admin() || current_user_can( 'manage_options' ) ) {
    1449             echo '<p><strong>' . __( 'RSS Error:' ) . '</strong> ' . $rss->get_error_message() . '</p>';
     1449            echo '<p><strong>' . __( 'RSS Error:' ) . '</strong> ' . esc_html( $rss->get_error_message() ) . '</p>';
    14501450        }
    14511451        return;
     
    15701570
    15711571    if ( ! empty( $args['error'] ) ) {
    1572         echo '<p class="widget-error"><strong>' . __( 'RSS Error:' ) . '</strong> ' . $args['error'] . '</p>';
     1572        echo '<p class="widget-error"><strong>' . __( 'RSS Error:' ) . '</strong> ' . esc_html( $args['error'] ) . '</p>';
    15731573    }
    15741574
  • branches/5.1/src/wp-mail.php

    r42343 r54570  
    6565    wp_die( __( 'There doesn&#8217;t seem to be any new mail.' ) );
    6666}
     67
     68// Always run as an unauthenticated user.
     69wp_set_current_user( 0 );
    6770
    6871for ( $i = 1; $i <= $count; $i++ ) {
     
    132135                $author = sanitize_email( $author );
    133136                if ( is_email( $author ) ) {
    134                     /* translators: Post author email address */
    135                     echo '<p>' . sprintf( __( 'Author is %s' ), $author ) . '</p>';
    136137                    $userdata = get_user_by( 'email', $author );
    137138                    if ( ! empty( $userdata ) ) {
  • branches/5.1/src/wp-trackback.php

    r42343 r54570  
    1313    wp( array( 'tb' => '1' ) );
    1414}
     15
     16// Always run as an unauthenticated user.
     17wp_set_current_user( 0 );
    1518
    1619/**
  • branches/5.1/tests/phpunit/tests/query/search.php

    r43571 r54570  
    456456
    457457        add_post_meta( $attachment, '_wp_attached_file', 'some-image1.png', true );
    458         add_filter( 'posts_clauses', '_filter_query_attachment_filenames' );
     458        add_filter( 'wp_allow_query_attachment_by_filename', '__return_true' );
    459459
    460460        // Pass post_type a string value.
     
    486486
    487487        add_post_meta( $attachment, '_wp_attached_file', 'some-image2.png', true );
    488         add_filter( 'posts_clauses', '_filter_query_attachment_filenames' );
     488        add_filter( 'wp_allow_query_attachment_by_filename', '__return_true' );
    489489
    490490        // Pass post_type an array value.
     
    545545        add_post_meta( $attachment, '_wp_attached_file', 'some-image4.png', true );
    546546        add_post_meta( $attachment, '_test_meta_key', 'value', true );
    547         add_filter( 'posts_clauses', '_filter_query_attachment_filenames' );
     547        add_filter( 'wp_allow_query_attachment_by_filename', '__return_true' );
    548548
    549549        // Pass post_type a string value.
     
    585585
    586586        add_post_meta( $attachment, '_wp_attached_file', 'some-image5.png', true );
    587         add_filter( 'posts_clauses', '_filter_query_attachment_filenames' );
     587        add_filter( 'wp_allow_query_attachment_by_filename', '__return_true' );
    588588
    589589        // Pass post_type a string value.
     
    610610     * @ticket 22744
    611611     */
    612     public function test_filter_query_attachment_filenames_unhooks_itself() {
    613         add_filter( 'posts_clauses', '_filter_query_attachment_filenames' );
    614 
    615         apply_filters(
    616             'posts_clauses',
    617             array(
    618                 'where'    => '',
    619                 'groupby'  => '',
    620                 'join'     => '',
    621                 'orderby'  => '',
    622                 'distinct' => '',
    623                 'fields'   => '',
    624                 'limit'    => '',
    625             )
    626         );
    627 
    628         $result = has_filter( 'posts_clauses', '_filter_query_attachment_filenames' );
    629 
    630         $this->assertFalse( $result );
     612    public function test_wp_query_removes_filter_wp_allow_query_attachment_by_filename() {
     613        $attachment = self::factory()->post->create(
     614            array(
     615                'post_type'    => 'attachment',
     616                'post_status'  => 'publish',
     617                'post_title'   => 'bar foo',
     618                'post_content' => 'foo bar',
     619                'post_excerpt' => 'This post has foo',
     620            )
     621        );
     622
     623        add_post_meta( $attachment, '_wp_attached_file', 'some-image1.png', true );
     624        add_filter( 'wp_allow_query_attachment_by_filename', '__return_true' );
     625
     626        $q = new WP_Query(
     627            array(
     628                's'           => 'image1',
     629                'fields'      => 'ids',
     630                'post_type'   => 'attachment',
     631                'post_status' => 'inherit',
     632            )
     633        );
     634
     635        $this->assertSame( array( $attachment ), $q->posts );
     636
     637        /*
     638         * WP_Query should have removed the wp_allow_query_attachment_by_filename filter
     639         * and thus not match the attachment created above
     640         */
     641        $q->get_posts();
     642        $this->assertEmpty( $q->posts );
    631643    }
    632644
  • branches/5.1/tests/phpunit/tests/rest-api/rest-comments-controller.php

    r43571 r54570  
    26962696                    'author_name'       => '<div>div</div> <strong>strong</strong> <script>oh noes</script>',
    26972697                    'author_user_agent' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>',
     2698                    'author'            => self::$editor_id,
    26982699                ),
    26992700                array(
     
    27042705                    'author_name'       => 'div strong',
    27052706                    'author_user_agent' => 'div strong',
     2707                    'author'            => self::$editor_id,
    27062708                )
    27072709            );
     
    27132715                    'author_name'       => '<div>div</div> <strong>strong</strong> <script>oh noes</script>',
    27142716                    'author_user_agent' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>',
     2717                    'author'            => self::$editor_id,
    27152718                ),
    27162719                array(
     
    27212724                    'author_name'       => 'div strong',
    27222725                    'author_user_agent' => 'div strong',
     2726                    'author'            => self::$editor_id,
    27232727                )
    27242728            );
     
    27342738                'author_name'       => '\\\&\\\ &amp; &invalid; < &lt; &amp;lt;',
    27352739                'author_user_agent' => '\\\&\\\ &amp; &invalid; < &lt; &amp;lt;',
     2740                'author'            => self::$superadmin_id,
    27362741            ),
    27372742            array(
     
    27422747                'author_name'       => '\\\&amp;\\\ &amp; &amp;invalid; &lt; &lt; &amp;lt;',
    27432748                'author_user_agent' => '\\\&\\\ &amp; &invalid; &lt; &lt; &amp;lt;',
     2749                'author'            => self::$superadmin_id,
    27442750            )
    27452751        );
     
    27542760                'author_name'       => '<div>div</div> <strong>strong</strong> <script>oh noes</script>',
    27552761                'author_user_agent' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>',
     2762                'author'            => self::$superadmin_id,
    27562763            ),
    27572764            array(
     
    27622769                'author_name'       => 'div strong',
    27632770                'author_user_agent' => 'div strong',
     2771                'author'            => self::$superadmin_id,
    27642772            )
    27652773        );
Note: See TracChangeset for help on using the changeset viewer.