Make WordPress Core

Changeset 54568 for branches/4.8


Ignore:
Timestamp:
10/17/2022 06:10:19 PM (2 years ago)
Author:
SergeyBiryukov
Message:

Grouped backports to the 4.8 branch.

  • 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,
  • Media: Refactor search by filename within the admin,
  • Pings/trackbacks: Apply KSES to all trackbacks,
  • Comments: Apply kses when editing comments,
  • Customize: Escape blogname option in underscores templates,
  • REST API: Lockdown post parameter of the terms endpoint,
  • Mail: Reset PHPMailer properties between use,
  • Query: Validate relation in WP_Date_Query,
  • Widgets: Escape RSS error messages for display.

Merges [54521], [54522], [54523], [54524], [54525], [54526], [54527], [54528], [54529], [54530], [54541] to the 4.8 branch.
Props voldemortensen, johnbillion, paulkevan, peterwilsoncc, xknown, dd32, audrasjb, martinkrcho, vortfu, davidbaumwald, tykoted, timothyblynjacobs, johnjamesjacoby, ehtis, matveb, talldanwp.

Location:
branches/4.8
Files:
20 edited

Legend:

Unmodified
Added
Removed
  • branches/4.8

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

    r45944 r54568  
    24672467    // Filter query clauses to include filenames.
    24682468    if ( isset( $query['s'] ) ) {
    2469         add_filter( 'posts_clauses', '_filter_query_attachment_filenames' );
     2469        add_filter( 'wp_allow_query_attachment_by_filename', '__return_true' );
    24702470    }
    24712471
  • branches/4.8/src/wp-admin/includes/post.php

    r44055 r54568  
    11701170    // Filter query clauses to include filenames.
    11711171    if ( isset( $q['s'] ) ) {
    1172         add_filter( 'posts_clauses', '_filter_query_attachment_filenames' );
     1172        add_filter( 'wp_allow_query_attachment_by_filename', '__return_true' );
    11731173    }
    11741174
  • branches/4.8/src/wp-includes/class-wp-query.php

    r47649 r54568  
    487487    private $compat_methods = array( 'init_query_flags', 'parse_tax_query' );
    488488
     489    /**
     490     * Controls whether an attachment query should include filenames or not.
     491     *
     492     * @since 6.0.3
     493     * @var bool
     494     */
     495    protected $allow_query_attachment_by_filename = false;
    489496    /**
    490497     * Resets query flags to false.
     
    13471354
    13481355            $like = $n . $wpdb->esc_like( $term ) . $n;
    1349             $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 );
     1356
     1357            if ( ! empty( $this->allow_query_attachment_by_filename ) ) {
     1358                $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 );
     1359            } else {
     1360                $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 );
     1361            }
    13501362            $searchand = ' AND ';
    13511363        }
     
    16841696        $q = $this->fill_query_vars($q);
    16851697
     1698        /**
     1699         * Filters whether an attachment query should include filenames or not.
     1700         *
     1701         * @since 6.0.3
     1702         *
     1703         * @param bool $allow_query_attachment_by_filename Whether or not to include filenames.
     1704         */
     1705        $this->allow_query_attachment_by_filename = apply_filters( 'wp_allow_query_attachment_by_filename', false );
     1706        remove_all_filters( 'wp_allow_query_attachment_by_filename' );
     1707
    16861708        // Parse meta query
    16871709        $this->meta_query = new WP_Meta_Query();
     
    20882110        }
    20892111
    2090         if ( !empty( $this->tax_query->queries ) || !empty( $this->meta_query->queries ) ) {
     2112        if ( ! empty( $this->tax_query->queries ) || ! empty( $this->meta_query->queries ) || ! empty( $this->allow_query_attachment_by_filename ) ) {
    20912113            $groupby = "{$wpdb->posts}.ID";
    20922114        }
     
    21362158        }
    21372159        $where .= $search . $whichauthor . $whichmimetype;
     2160
     2161        if ( ! empty( $this->allow_query_attachment_by_filename ) ) {
     2162            $join .= " LEFT JOIN {$wpdb->postmeta} AS sq1 ON ( {$wpdb->posts}.ID = sq1.post_id AND sq1.meta_key = '_wp_attached_file' )";
     2163        }
    21382164
    21392165        if ( ! empty( $this->meta_query->queries ) ) {
  • branches/4.8/src/wp-includes/comment.php

    r44846 r54568  
    21472147    }
    21482148
     2149    $filter_comment = false;
     2150    if ( ! has_filter( 'pre_comment_content', 'wp_filter_kses' ) ) {
     2151        $filter_comment = ! user_can( isset( $comment['user_id'] ) ? $comment['user_id'] : 0, 'unfiltered_html' );
     2152    }
     2153
     2154    if ( $filter_comment ) {
     2155        add_filter( 'pre_comment_content', 'wp_filter_kses' );
     2156    }
     2157
    21492158    // Escape data pulled from DB.
    21502159    $comment = wp_slash($comment);
     
    21562165
    21572166    $commentarr = wp_filter_comment( $commentarr );
     2167
     2168    if ( $filter_comment ) {
     2169        remove_filter( 'pre_comment_content', 'wp_filter_kses' );
     2170    }
    21582171
    21592172    // Now extract the merged array.
  • branches/4.8/src/wp-includes/customize/class-wp-customize-header-image-control.php

    r40671 r54568  
    104104
    105105            <button type="button" class="choice thumbnail"
    106                 data-customize-image-value="{{{data.header.url}}}"
     106                data-customize-image-value="{{data.header.url}}"
    107107                data-customize-header-image-data="{{JSON.stringify(data.header)}}">
    108108                <span class="screen-reader-text"><?php _e( 'Set image' ); ?></span>
    109                 <img src="{{{data.header.thumbnail_url}}}" alt="{{{data.header.alt_text || data.header.description}}}">
     109                <img src="{{data.header.thumbnail_url}}" alt="{{data.header.alt_text || data.header.description}}" />
    110110            </button>
    111111
  • branches/4.8/src/wp-includes/customize/class-wp-customize-site-icon-control.php

    r40671 r54568  
    7070                                <img src="{{ data.attachment.sizes.full ? data.attachment.sizes.full.url : data.attachment.url }}" alt="<?php esc_attr_e( 'Preview as a browser icon' ); ?>"/>
    7171                            </div>
    72                             <span class="browser-title" aria-hidden="true"><?php bloginfo( 'name' ); ?></span>
     72                            <span class="browser-title" aria-hidden="true"><?php echo esc_js( get_bloginfo( 'name' ) ); ?></span>
    7373                        </div>
    7474                        <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/4.8/src/wp-includes/date.php

    r39672 r54568  
    152152     */
    153153    public function __construct( $date_query, $default_column = 'post_date' ) {
    154         if ( isset( $date_query['relation'] ) && 'OR' === strtoupper( $date_query['relation'] ) ) {
    155             $this->relation = 'OR';
     154        if ( isset( $date_query['relation'] ) ) {
     155            $this->relation = $this->sanitize_relation( $date_query['relation'] );
    156156        } else {
    157157            $this->relation = 'AND';
     
    232232            $this->validate_date_values( $queries );
    233233        }
     234
     235        // Sanitize the relation parameter.
     236        $queries['relation'] = $this->sanitize_relation( $queries['relation'] );
    234237
    235238        foreach ( $queries as $key => $q ) {
     
    10181021        return $wpdb->prepare( "DATE_FORMAT( $column, %s ) $compare %f", $format, $time );
    10191022    }
     1023
     1024    /**
     1025     * Sanitizes a 'relation' operator.
     1026     *
     1027     * @since 6.0.3
     1028     *
     1029     * @param string $relation Raw relation key from the query argument.
     1030     * @return string Sanitized relation ('AND' or 'OR').
     1031     */
     1032    public function sanitize_relation( $relation ) {
     1033        if ( 'OR' === strtoupper( $relation ) ) {
     1034            return 'OR';
     1035        } else {
     1036            return 'AND';
     1037        }
     1038    }
    10201039}
  • branches/4.8/src/wp-includes/deprecated.php

    r39758 r54568  
    38793879        return strcmp( $a->$_menu_item_sort_prop, $b->$_menu_item_sort_prop );
    38803880}
     3881
     3882/**
     3883 * Filter the SQL clauses of an attachment query to include filenames.
     3884 *
     3885 * @since 4.7.0
     3886 * @deprecated 6.0.3
     3887 * @access private
     3888 *
     3889 * @param array $clauses An array including WHERE, GROUP BY, JOIN, ORDER BY,
     3890 *                       DISTINCT, fields (SELECT), and LIMITS clauses.
     3891 * @return array The unmodified clauses.
     3892 */
     3893function _filter_query_attachment_filenames( $clauses ) {
     3894    _deprecated_function( __FUNCTION__, '6.0.3', 'add_filter( "wp_allow_query_attachment_by_filename", "__return_true" )');
     3895    remove_filter( 'posts_clauses', __FUNCTION__ );
     3896    return $clauses;
     3897}
     3898
  • branches/4.8/src/wp-includes/functions.php

    r46494 r54568  
    23702370            if ( $type !== $real_mime ) {
    23712371                /*
    2372                  * Everything else including image/* and application/*: 
     2372                 * Everything else including image/* and application/*:
    23732373                 * If the real content type doesn't match the file extension, assume it's dangerous.
    23742374                 */
     
    23792379    }
    23802380
    2381     // The mime type must be allowed 
     2381    // The mime type must be allowed
    23822382    if ( $type ) {
    23832383        $allowed = get_allowed_mime_types();
     
    26512651        $html = __( 'Are you sure you want to do this?' );
    26522652        if ( wp_get_referer() ) {
    2653             $html .= '</p><p>';
    2654             $html .= sprintf( '<a href="%s">%s</a>',
    2655                 esc_url( remove_query_arg( 'updated', wp_get_referer() ) ),
     2653            $wp_http_referer = remove_query_arg( 'updated', wp_get_referer() );
     2654            $wp_http_referer = wp_validate_redirect( esc_url_raw( $wp_http_referer ) );
     2655            $html           .= '</p><p>';
     2656            $html           .= sprintf(
     2657                '<a href="%s">%s</a>',
     2658                esc_url( $wp_http_referer ),
    26562659                __( 'Please try again.' )
    26572660            );
  • branches/4.8/src/wp-includes/media-template.php

    r40640 r54568  
    12531253                <img id="preview-favicon" src="{{ data.url }}" alt="<?php esc_attr_e( 'Preview as a browser icon' ); ?>"/>
    12541254            </div>
    1255             <span class="browser-title" aria-hidden="true"><?php bloginfo( 'name' ); ?></span>
     1255            <span class="browser-title" aria-hidden="true"><?php echo esc_js( get_bloginfo( 'name' ) ); ?></span>
    12561256        </div>
    12571257
  • branches/4.8/src/wp-includes/pluggable.php

    r47980 r54568  
    313313    $phpmailer->clearCustomHeaders();
    314314    $phpmailer->clearReplyTos();
     315    $phpmailer->Body    = '';
     316    $phpmailer->AltBody = '';
    315317
    316318    // From email and name
  • branches/4.8/src/wp-includes/post.php

    r52475 r54568  
    16321632    }
    16331633
    1634     return $post_type->publicly_queryable || ( $post_type->_builtin && $post_type->public );
     1634    if ( ! is_object( $post_type ) ) {
     1635        return false;
     1636    }
     1637
     1638    $is_viewable = $post_type->publicly_queryable || ( $post_type->_builtin && $post_type->public );
     1639
     1640    /**
     1641     * Filters whether a post type is considered "viewable".
     1642     *
     1643     * The returned filtered value must be a boolean type to ensure
     1644     * `is_post_type_viewable()` only returns a boolean. This strictness
     1645     * is by design to maintain backwards-compatibility and guard against
     1646     * potential type errors in PHP 8.1+. Non-boolean values (even falsey
     1647     * and truthy values) will result in the function returning false.
     1648     *
     1649     * @since 5.9.0
     1650     *
     1651     * @param bool         $is_viewable Whether the post type is "viewable" (strict type).
     1652     * @param WP_Post_Type $post_type   Post type object.
     1653     */
     1654    return true === apply_filters( 'is_post_type_viewable', $is_viewable, $post_type );
     1655}
     1656
     1657/**
     1658 * Determines whether a post status is considered "viewable".
     1659 *
     1660 * For built-in post statuses such as publish and private, the 'public' value will be evaluated.
     1661 * For all others, the 'publicly_queryable' value will be used.
     1662 *
     1663 * @since 5.7.0
     1664 * @since 5.9.0 Added `is_post_status_viewable` hook to filter the result.
     1665 *
     1666 * @param string|stdClass $post_status Post status name or object.
     1667 * @return bool Whether the post status should be considered viewable.
     1668 */
     1669function is_post_status_viewable( $post_status ) {
     1670    if ( is_scalar( $post_status ) ) {
     1671        $post_status = get_post_status_object( $post_status );
     1672
     1673        if ( ! $post_status ) {
     1674            return false;
     1675        }
     1676    }
     1677
     1678    if (
     1679        ! is_object( $post_status ) ||
     1680        $post_status->internal ||
     1681        $post_status->protected
     1682    ) {
     1683        return false;
     1684    }
     1685
     1686    $is_viewable = $post_status->publicly_queryable || ( $post_status->_builtin && $post_status->public );
     1687
     1688    /**
     1689     * Filters whether a post status is considered "viewable".
     1690     *
     1691     * The returned filtered value must be a boolean type to ensure
     1692     * `is_post_status_viewable()` only returns a boolean. This strictness
     1693     * is by design to maintain backwards-compatibility and guard against
     1694     * potential type errors in PHP 8.1+. Non-boolean values (even falsey
     1695     * and truthy values) will result in the function returning false.
     1696     *
     1697     * @since 5.9.0
     1698     *
     1699     * @param bool     $is_viewable Whether the post status is "viewable" (strict type).
     1700     * @param stdClass $post_status Post status object.
     1701     */
     1702    return true === apply_filters( 'is_post_status_viewable', $is_viewable, $post_status );
     1703}
     1704
     1705/**
     1706 * Determines whether a post is publicly viewable.
     1707 *
     1708 * Posts are considered publicly viewable if both the post status and post type
     1709 * are viewable.
     1710 *
     1711 * @since 5.7.0
     1712 *
     1713 * @param int|WP_Post|null $post Optional. Post ID or post object. Defaults to global $post.
     1714 * @return bool Whether the post is publicly viewable.
     1715 */
     1716function is_post_publicly_viewable( $post = null ) {
     1717    $post = get_post( $post );
     1718
     1719    if ( ! $post ) {
     1720        return false;
     1721    }
     1722
     1723    $post_type   = get_post_type( $post );
     1724    $post_status = get_post_status( $post );
     1725
     1726    return is_post_type_viewable( $post_type ) && is_post_status_viewable( $post_status );
    16351727}
    16361728
     
    62426334    return $post_name;
    62436335}
    6244 
    6245 /**
    6246  * Filter the SQL clauses of an attachment query to include filenames.
    6247  *
    6248  * @since 4.7.0
    6249  * @access private
    6250  *
    6251  * @global wpdb $wpdb WordPress database abstraction object.
    6252  *
    6253  * @param array $clauses An array including WHERE, GROUP BY, JOIN, ORDER BY,
    6254  *                       DISTINCT, fields (SELECT), and LIMITS clauses.
    6255  * @return array The modified clauses.
    6256  */
    6257 function _filter_query_attachment_filenames( $clauses ) {
    6258     global $wpdb;
    6259     remove_filter( 'posts_clauses', __FUNCTION__ );
    6260 
    6261     // Add a LEFT JOIN of the postmeta table so we don't trample existing JOINs.
    6262     $clauses['join'] .= " LEFT JOIN {$wpdb->postmeta} AS sq1 ON ( {$wpdb->posts}.ID = sq1.post_id AND sq1.meta_key = '_wp_attached_file' )";
    6263 
    6264     $clauses['groupby'] = "{$wpdb->posts}.ID";
    6265 
    6266     $clauses['where'] = preg_replace(
    6267         "/\({$wpdb->posts}.post_content (NOT LIKE|LIKE) (\'[^']+\')\)/",
    6268         "$0 OR ( sq1.meta_value $1 $2 )",
    6269         $clauses['where'] );
    6270 
    6271     return $clauses;
    6272 }
  • branches/4.8/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php

    r39671 r54568  
    5050        // Filter query clauses to include filenames.
    5151        if ( isset( $query_args['s'] ) ) {
    52             add_filter( 'posts_clauses', '_filter_query_attachment_filenames' );
     52            add_filter( 'wp_allow_query_attachment_by_filename', '__return_true' );
    5353        }
    5454
  • branches/4.8/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php

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

    r41044 r54568  
    12341234    if ( is_wp_error($rss) ) {
    12351235        if ( is_admin() || current_user_can('manage_options') )
    1236             echo '<p><strong>' . __( 'RSS Error:' ) . '</strong> ' . $rss->get_error_message() . '</p>';
     1236            echo '<p><strong>' . __( 'RSS Error:' ) . '</strong> ' . esc_html( $rss->get_error_message() ) . '</p>';
    12371237        return;
    12381238    }
     
    13431343
    13441344    if ( ! empty( $args['error'] ) ) {
    1345         echo '<p class="widget-error"><strong>' . __( 'RSS Error:' ) . '</strong> ' . $args['error'] . '</p>';
     1345        echo '<p class="widget-error"><strong>' . __( 'RSS Error:' ) . '</strong> ' . esc_html( $args['error'] ) . '</p>';
    13461346    }
    13471347
  • branches/4.8/src/wp-mail.php

    r39772 r54568  
    6060    wp_die( __('There doesn&#8217;t seem to be any new mail.') );
    6161}
     62
     63// Always run as an unauthenticated user.
     64wp_set_current_user( 0 );
    6265
    6366for ( $i = 1; $i <= $count; $i++ ) {
     
    125128                $author = sanitize_email($author);
    126129                if ( is_email($author) ) {
    127                     /* translators: Post author email address */
    128                     echo '<p>' . sprintf(__('Author is %s'), $author) . '</p>';
    129130                    $userdata = get_user_by('email', $author);
    130131                    if ( ! empty( $userdata ) ) {
  • branches/4.8/src/wp-trackback.php

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

    r38844 r54568  
    371371
    372372        add_post_meta( $attachment, '_wp_attached_file', 'some-image1.png', true );
    373         add_filter( 'posts_clauses', '_filter_query_attachment_filenames' );
     373        add_filter( 'wp_allow_query_attachment_by_filename', '__return_true' );
    374374
    375375        // Pass post_type a string value.
     
    397397
    398398        add_post_meta( $attachment, '_wp_attached_file', 'some-image2.png', true );
    399         add_filter( 'posts_clauses', '_filter_query_attachment_filenames' );
     399        add_filter( 'wp_allow_query_attachment_by_filename', '__return_true' );
    400400
    401401        // Pass post_type an array value.
     
    448448        add_post_meta( $attachment, '_wp_attached_file', 'some-image4.png', true );
    449449        add_post_meta( $attachment, '_test_meta_key', 'value', true );
    450         add_filter( 'posts_clauses', '_filter_query_attachment_filenames' );
     450        add_filter( 'wp_allow_query_attachment_by_filename', '__return_true' );
    451451
    452452        // Pass post_type a string value.
     
    484484
    485485        add_post_meta( $attachment, '_wp_attached_file', 'some-image5.png', true );
    486         add_filter( 'posts_clauses', '_filter_query_attachment_filenames' );
     486        add_filter( 'wp_allow_query_attachment_by_filename', '__return_true' );
    487487
    488488        // Pass post_type a string value.
     
    507507     * @ticket 22744
    508508     */
    509     public function test_filter_query_attachment_filenames_unhooks_itself() {
    510         add_filter( 'posts_clauses', '_filter_query_attachment_filenames' );
    511 
    512         apply_filters( 'posts_clauses', array(
    513             'where'    => '',
    514             'groupby'  => '',
    515             'join'     => '',
    516             'orderby'  => '',
    517             'distinct' => '',
    518             'fields'   => '',
    519             'limit'    => '',
    520         ) );
    521 
    522         $result = has_filter( 'posts_clauses', '_filter_query_attachment_filenames' );
    523 
    524         $this->assertFalse( $result );
     509    public function test_wp_query_removes_filter_wp_allow_query_attachment_by_filename() {
     510        $attachment = self::factory()->post->create(
     511            array(
     512                'post_type'    => 'attachment',
     513                'post_status'  => 'publish',
     514                'post_title'   => 'bar foo',
     515                'post_content' => 'foo bar',
     516                'post_excerpt' => 'This post has foo',
     517            )
     518        );
     519
     520        add_post_meta( $attachment, '_wp_attached_file', 'some-image1.png', true );
     521        add_filter( 'wp_allow_query_attachment_by_filename', '__return_true' );
     522
     523        $q = new WP_Query(
     524            array(
     525                's'           => 'image1',
     526                'fields'      => 'ids',
     527                'post_type'   => 'attachment',
     528                'post_status' => 'inherit',
     529            )
     530        );
     531
     532        $this->assertSame( array( $attachment ), $q->posts );
     533
     534        /*
     535         * WP_Query should have removed the wp_allow_query_attachment_by_filename filter
     536         * and thus not match the attachment created above
     537         */
     538        $q->get_posts();
     539        $this->assertEmpty( $q->posts );
    525540    }
    526541
  • branches/4.8/tests/phpunit/tests/rest-api/rest-comments-controller.php

    r40101 r54568  
    25912591                'author_name'       => '<div>div</div> <strong>strong</strong> <script>oh noes</script>',
    25922592                'author_user_agent' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>',
     2593                'author'            => self::$editor_id,
    25932594            ), array(
    25942595                'content' => array(
     
    25982599                'author_name'       => 'div strong',
    25992600                'author_user_agent' => 'div strong',
     2601                'author'            => self::$editor_id,
    26002602            ) );
    26012603        } else {
     
    26052607                'author_name'       => '<div>div</div> <strong>strong</strong> <script>oh noes</script>',
    26062608                'author_user_agent' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>',
     2609                'author'            => self::$editor_id,
    26072610            ), array(
    26082611                'content' => array(
     
    26122615                'author_name'       => 'div strong',
    26132616                'author_user_agent' => 'div strong',
     2617                'author'            => self::$editor_id,
    26142618            ) );
    26152619        }
     
    26232627            'author_name'       => '\\\&\\\ &amp; &invalid; < &lt; &amp;lt;',
    26242628            'author_user_agent' => '\\\&\\\ &amp; &invalid; < &lt; &amp;lt;',
     2629            'author'            => self::$superadmin_id,
    26252630        ), array(
    26262631            'content' => array(
     
    26302635            'author_name'       => '\\\&amp;\\\ &amp; &amp;invalid; &lt; &lt; &amp;lt;',
    26312636            'author_user_agent' => '\\\&\\\ &amp; &invalid; &lt; &lt; &amp;lt;',
     2637            'author'            => self::$superadmin_id,
    26322638        ) );
    26332639    }
     
    26402646            'author_name'       => '<div>div</div> <strong>strong</strong> <script>oh noes</script>',
    26412647            'author_user_agent' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>',
     2648            'author'            => self::$superadmin_id,
    26422649        ), array(
    26432650            'content' => array(
     
    26472654            'author_name'       => 'div strong',
    26482655            'author_user_agent' => 'div strong',
     2656            'author'            => self::$superadmin_id,
    26492657        ) );
    26502658    }
Note: See TracChangeset for help on using the changeset viewer.