Skip to content

Commit 568680f

Browse files
committed
Grouped backports to the 5.7 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.7 branch. Props audrasjb, costdev, cu121, dd32, davidbaumwald, ehtis, johnbillion, johnjamesjacoby, martinkrcho, matveb, oztaser, paulkevan, peterwilsoncc, ravipatel, SergeyBiryukov, talldanwp, timothyblynjacobs, tykoted, voldemortensen, vortfu, xknown. git-svn-id: https://develop.svn.wordpress.org/branches/5.7@54553 602fd350-edb4-49c9-b593-d223f7449a82
1 parent b5e8553 commit 568680f

19 files changed

+191
-64
lines changed

src/wp-admin/includes/ajax-actions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2974,7 +2974,7 @@ function wp_ajax_query_attachments() {
29742974

29752975
// Filter query clauses to include filenames.
29762976
if ( isset( $query['s'] ) ) {
2977-
add_filter( 'posts_clauses', '_filter_query_attachment_filenames' );
2977+
add_filter( 'wp_allow_query_attachment_by_filename', '__return_true' );
29782978
}
29792979

29802980
/**

src/wp-admin/includes/post.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1269,7 +1269,7 @@ function wp_edit_attachments_query_vars( $q = false ) {
12691269

12701270
// Filter query clauses to include filenames.
12711271
if ( isset( $q['s'] ) ) {
1272-
add_filter( 'posts_clauses', '_filter_query_attachment_filenames' );
1272+
add_filter( 'wp_allow_query_attachment_by_filename', '__return_true' );
12731273
}
12741274

12751275
return $q;

src/wp-includes/class-wp-date-query.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ public function __construct( $date_query, $default_column = 'post_date' ) {
149149
return;
150150
}
151151

152-
if ( isset( $date_query['relation'] ) && 'OR' === strtoupper( $date_query['relation'] ) ) {
153-
$this->relation = 'OR';
152+
if ( isset( $date_query['relation'] ) ) {
153+
$this->relation = $this->sanitize_relation( $date_query['relation'] );
154154
} else {
155155
$this->relation = 'AND';
156156
}
@@ -219,6 +219,9 @@ public function sanitize_query( $queries, $parent_query = null ) {
219219
$this->validate_date_values( $queries );
220220
}
221221

222+
// Sanitize the relation parameter.
223+
$queries['relation'] = $this->sanitize_relation( $queries['relation'] );
224+
222225
foreach ( $queries as $key => $q ) {
223226
if ( ! is_array( $q ) || in_array( $key, $this->time_keys, true ) ) {
224227
// This is a first-order query. Trust the values and sanitize when building SQL.
@@ -1039,4 +1042,20 @@ public function build_time_query( $column, $compare, $hour = null, $minute = nul
10391042

10401043
return $wpdb->prepare( "DATE_FORMAT( $column, %s ) $compare %f", $format, $time );
10411044
}
1045+
1046+
/**
1047+
* Sanitizes a 'relation' operator.
1048+
*
1049+
* @since 6.0.3
1050+
*
1051+
* @param string $relation Raw relation key from the query argument.
1052+
* @return string Sanitized relation ('AND' or 'OR').
1053+
*/
1054+
public function sanitize_relation( $relation ) {
1055+
if ( 'OR' === strtoupper( $relation ) ) {
1056+
return 'OR';
1057+
} else {
1058+
return 'AND';
1059+
}
1060+
}
10421061
}

src/wp-includes/class-wp-query.php

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,13 @@ class WP_Query {
444444
*/
445445
public $thumbnails_cached = false;
446446

447+
/**
448+
* Controls whether an attachment query should include filenames or not.
449+
*
450+
* @since 6.0.3
451+
* @var bool
452+
*/
453+
protected $allow_query_attachment_by_filename = false;
447454
/**
448455
* Cached list of search stopwords.
449456
*
@@ -1394,7 +1401,12 @@ protected function parse_search( &$q ) {
13941401
}
13951402

13961403
$like = $n . $wpdb->esc_like( $term ) . $n;
1397-
$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 );
1404+
1405+
if ( ! empty( $this->allow_query_attachment_by_filename ) ) {
1406+
$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 );
1407+
} else {
1408+
$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 );
1409+
}
13981410
$searchand = ' AND ';
13991411
}
14001412

@@ -1789,6 +1801,16 @@ public function get_posts() {
17891801
// Fill again in case 'pre_get_posts' unset some vars.
17901802
$q = $this->fill_query_vars( $q );
17911803

1804+
/**
1805+
* Filters whether an attachment query should include filenames or not.
1806+
*
1807+
* @since 6.0.3
1808+
*
1809+
* @param bool $allow_query_attachment_by_filename Whether or not to include filenames.
1810+
*/
1811+
$this->allow_query_attachment_by_filename = apply_filters( 'wp_allow_query_attachment_by_filename', false );
1812+
remove_all_filters( 'wp_allow_query_attachment_by_filename' );
1813+
17921814
// Parse meta query.
17931815
$this->meta_query = new WP_Meta_Query();
17941816
$this->meta_query->parse_query_vars( $q );
@@ -2220,7 +2242,7 @@ public function get_posts() {
22202242
}
22212243
}
22222244

2223-
if ( ! empty( $this->tax_query->queries ) || ! empty( $this->meta_query->queries ) ) {
2245+
if ( ! empty( $this->tax_query->queries ) || ! empty( $this->meta_query->queries ) || ! empty( $this->allow_query_attachment_by_filename ) ) {
22242246
$groupby = "{$wpdb->posts}.ID";
22252247
}
22262248

@@ -2297,6 +2319,10 @@ public function get_posts() {
22972319
}
22982320
$where .= $search . $whichauthor . $whichmimetype;
22992321

2322+
if ( ! empty( $this->allow_query_attachment_by_filename ) ) {
2323+
$join .= " LEFT JOIN {$wpdb->postmeta} AS sq1 ON ( {$wpdb->posts}.ID = sq1.post_id AND sq1.meta_key = '_wp_attached_file' )";
2324+
}
2325+
23002326
if ( ! empty( $this->meta_query->queries ) ) {
23012327
$clauses = $this->meta_query->get_sql( 'post', $wpdb->posts, 'ID', $this );
23022328
$join .= $clauses['join'];

src/wp-includes/comment.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2461,6 +2461,15 @@ function wp_update_comment( $commentarr, $wp_error = false ) {
24612461
}
24622462
}
24632463

2464+
$filter_comment = false;
2465+
if ( ! has_filter( 'pre_comment_content', 'wp_filter_kses' ) ) {
2466+
$filter_comment = ! user_can( isset( $comment['user_id'] ) ? $comment['user_id'] : 0, 'unfiltered_html' );
2467+
}
2468+
2469+
if ( $filter_comment ) {
2470+
add_filter( 'pre_comment_content', 'wp_filter_kses' );
2471+
}
2472+
24642473
// Escape data pulled from DB.
24652474
$comment = wp_slash( $comment );
24662475

@@ -2471,6 +2480,10 @@ function wp_update_comment( $commentarr, $wp_error = false ) {
24712480

24722481
$commentarr = wp_filter_comment( $commentarr );
24732482

2483+
if ( $filter_comment ) {
2484+
remove_filter( 'pre_comment_content', 'wp_filter_kses' );
2485+
}
2486+
24742487
// Now extract the merged array.
24752488
$data = wp_unslash( $commentarr );
24762489

src/wp-includes/customize/class-wp-customize-header-image-control.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,10 @@ public function print_header_image_template() {
130130
<# } else { #>
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

139139
<# if ( data.type === 'uploaded' ) { #>
@@ -158,7 +158,7 @@ public function print_header_image_template() {
158158

159159
<# } else { #>
160160

161-
<img src="{{{data.header.thumbnail_url}}}" alt="{{{data.header.alt_text || data.header.description}}}" />
161+
<img src="{{data.header.thumbnail_url}}" alt="{{data.header.alt_text || data.header.description}}" />
162162

163163
<# } #>
164164
<# } else { #>

src/wp-includes/customize/class-wp-customize-site-icon-control.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function content_template() {
6868
<div class="favicon">
6969
<img src="{{ data.attachment.sizes.full ? data.attachment.sizes.full.url : data.attachment.url }}" alt="<?php esc_attr_e( 'Preview as a browser icon' ); ?>"/>
7070
</div>
71-
<span class="browser-title" aria-hidden="true"><# print( '<?php bloginfo( 'name' ); ?>' ) #></span>
71+
<span class="browser-title" aria-hidden="true"><# print( '<?php echo esc_js( get_bloginfo( 'name' ) ); ?>' ) #></span>
7272
</div>
7373
<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' ); ?>"/>
7474
</div>

src/wp-includes/deprecated.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4203,3 +4203,21 @@ function wp_sensitive_page_meta() {
42034203
<?php
42044204
wp_strict_cross_origin_referrer();
42054205
}
4206+
4207+
/**
4208+
* Filter the SQL clauses of an attachment query to include filenames.
4209+
*
4210+
* @since 4.7.0
4211+
* @deprecated 6.0.3
4212+
* @access private
4213+
*
4214+
* @param array $clauses An array including WHERE, GROUP BY, JOIN, ORDER BY,
4215+
* DISTINCT, fields (SELECT), and LIMITS clauses.
4216+
* @return array The unmodified clauses.
4217+
*/
4218+
function _filter_query_attachment_filenames( $clauses ) {
4219+
_deprecated_function( __FUNCTION__, '6.0.3', 'add_filter( "wp_allow_query_attachment_by_filename", "__return_true" )');
4220+
remove_filter( 'posts_clauses', __FUNCTION__ );
4221+
return $clauses;
4222+
}
4223+

src/wp-includes/functions.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3288,10 +3288,12 @@ function wp_nonce_ays( $action ) {
32883288
} else {
32893289
$html = __( 'The link you followed has expired.' );
32903290
if ( wp_get_referer() ) {
3291+
$wp_http_referer = remove_query_arg( 'updated', wp_get_referer() );
3292+
$wp_http_referer = wp_validate_redirect( esc_url_raw( $wp_http_referer ) );
32913293
$html .= '</p><p>';
32923294
$html .= sprintf(
32933295
'<a href="%s">%s</a>',
3294-
esc_url( remove_query_arg( 'updated', wp_get_referer() ) ),
3296+
esc_url( $wp_http_referer ),
32953297
__( 'Please try again.' )
32963298
);
32973299
}

src/wp-includes/media-template.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1493,7 +1493,7 @@ function wp_print_media_templates() {
14931493
<div class="favicon">
14941494
<img id="preview-favicon" src="{{ data.url }}" alt="<?php esc_attr_e( 'Preview as a browser icon' ); ?>"/>
14951495
</div>
1496-
<span class="browser-title" aria-hidden="true"><# print( '<?php bloginfo( 'name' ); ?>' ) #></span>
1496+
<span class="browser-title" aria-hidden="true"><# print( '<?php echo esc_js( get_bloginfo( 'name' ) ); ?>' ) #></span>
14971497
</div>
14981498

14991499
<strong aria-hidden="true"><?php _e( 'As an app icon' ); ?></strong>

0 commit comments

Comments
 (0)