Skip to content

Commit 2ab7887

Browse files
committed
Grouped backports to the 5.4 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.4 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.4@54559 602fd350-edb4-49c9-b593-d223f7449a82
1 parent fa2aa44 commit 2ab7887

19 files changed

+289
-68
lines changed

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

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

29512951
// Filter query clauses to include filenames.
29522952
if ( isset( $query['s'] ) ) {
2953-
add_filter( 'posts_clauses', '_filter_query_attachment_filenames' );
2953+
add_filter( 'wp_allow_query_attachment_by_filename', '__return_true' );
29542954
}
29552955

29562956
/**

src/wp-admin/includes/post.php

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

12541254
// Filter query clauses to include filenames.
12551255
if ( isset( $q['s'] ) ) {
1256-
add_filter( 'posts_clauses', '_filter_query_attachment_filenames' );
1256+
add_filter( 'wp_allow_query_attachment_by_filename', '__return_true' );
12571257
}
12581258

12591259
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
}
@@ -221,6 +221,9 @@ public function sanitize_query( $queries, $parent_query = null ) {
221221
$this->validate_date_values( $queries );
222222
}
223223

224+
// Sanitize the relation parameter.
225+
$queries['relation'] = $this->sanitize_relation( $queries['relation'] );
226+
224227
foreach ( $queries as $key => $q ) {
225228
if ( ! is_array( $q ) || in_array( $key, $this->time_keys, true ) ) {
226229
// 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: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,13 @@ class WP_Query {
441441
*/
442442
public $thumbnails_cached = false;
443443

444+
/**
445+
* Controls whether an attachment query should include filenames or not.
446+
*
447+
* @since 6.0.3
448+
* @var bool
449+
*/
450+
protected $allow_query_attachment_by_filename = false;
444451
/**
445452
* Cached list of search stopwords.
446453
*
@@ -1388,8 +1395,13 @@ protected function parse_search( &$q ) {
13881395
$q['search_orderby_title'][] = $wpdb->prepare( "{$wpdb->posts}.post_title LIKE %s", $like );
13891396
}
13901397

1391-
$like = $n . $wpdb->esc_like( $term ) . $n;
1392-
$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 );
1398+
$like = $n . $wpdb->esc_like( $term ) . $n;
1399+
1400+
if ( ! empty( $this->allow_query_attachment_by_filename ) ) {
1401+
$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 );
1402+
} else {
1403+
$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+
}
13931405
$searchand = ' AND ';
13941406
}
13951407

@@ -1773,6 +1785,16 @@ public function get_posts() {
17731785
// Fill again in case 'pre_get_posts' unset some vars.
17741786
$q = $this->fill_query_vars( $q );
17751787

1788+
/**
1789+
* Filters whether an attachment query should include filenames or not.
1790+
*
1791+
* @since 6.0.3
1792+
*
1793+
* @param bool $allow_query_attachment_by_filename Whether or not to include filenames.
1794+
*/
1795+
$this->allow_query_attachment_by_filename = apply_filters( 'wp_allow_query_attachment_by_filename', false );
1796+
remove_all_filters( 'wp_allow_query_attachment_by_filename' );
1797+
17761798
// Parse meta query.
17771799
$this->meta_query = new WP_Meta_Query();
17781800
$this->meta_query->parse_query_vars( $q );
@@ -2204,7 +2226,7 @@ public function get_posts() {
22042226
}
22052227
}
22062228

2207-
if ( ! empty( $this->tax_query->queries ) || ! empty( $this->meta_query->queries ) ) {
2229+
if ( ! empty( $this->tax_query->queries ) || ! empty( $this->meta_query->queries ) || ! empty( $this->allow_query_attachment_by_filename ) ) {
22082230
$groupby = "{$wpdb->posts}.ID";
22092231
}
22102232

@@ -2281,6 +2303,10 @@ public function get_posts() {
22812303
}
22822304
$where .= $search . $whichauthor . $whichmimetype;
22832305

2306+
if ( ! empty( $this->allow_query_attachment_by_filename ) ) {
2307+
$join .= " LEFT JOIN {$wpdb->postmeta} AS sq1 ON ( {$wpdb->posts}.ID = sq1.post_id AND sq1.meta_key = '_wp_attached_file' )";
2308+
}
2309+
22842310
if ( ! empty( $this->meta_query->queries ) ) {
22852311
$clauses = $this->meta_query->get_sql( 'post', $wpdb->posts, 'ID', $this );
22862312
$join .= $clauses['join'];

src/wp-includes/comment.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2337,6 +2337,15 @@ function wp_update_comment( $commentarr ) {
23372337
return 0;
23382338
}
23392339

2340+
$filter_comment = false;
2341+
if ( ! has_filter( 'pre_comment_content', 'wp_filter_kses' ) ) {
2342+
$filter_comment = ! user_can( isset( $comment['user_id'] ) ? $comment['user_id'] : 0, 'unfiltered_html' );
2343+
}
2344+
2345+
if ( $filter_comment ) {
2346+
add_filter( 'pre_comment_content', 'wp_filter_kses' );
2347+
}
2348+
23402349
// Escape data pulled from DB.
23412350
$comment = wp_slash( $comment );
23422351

@@ -2347,6 +2356,10 @@ function wp_update_comment( $commentarr ) {
23472356

23482357
$commentarr = wp_filter_comment( $commentarr );
23492358

2359+
if ( $filter_comment ) {
2360+
remove_filter( 'pre_comment_content', 'wp_filter_kses' );
2361+
}
2362+
23502363
// Now extract the merged array.
23512364
$data = wp_unslash( $commentarr );
23522365

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

Lines changed: 2 additions & 2 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' ) { #>

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: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3964,4 +3964,22 @@ function wp_ajax_press_this_add_category() {
39643964
function wp_get_user_request_data( $request_id ) {
39653965
_deprecated_function( __FUNCTION__, '5.4.0', 'wp_get_user_request()' );
39663966
return wp_get_user_request( $request_id );
3967-
}
3967+
}
3968+
3969+
3970+
/**
3971+
* Filter the SQL clauses of an attachment query to include filenames.
3972+
*
3973+
* @since 4.7.0
3974+
* @deprecated 6.0.3
3975+
* @access private
3976+
*
3977+
* @param array $clauses An array including WHERE, GROUP BY, JOIN, ORDER BY,
3978+
* DISTINCT, fields (SELECT), and LIMITS clauses.
3979+
* @return array The unmodified clauses.
3980+
*/
3981+
function _filter_query_attachment_filenames( $clauses ) {
3982+
_deprecated_function( __FUNCTION__, '6.0.3', 'add_filter( "wp_allow_query_attachment_by_filename", "__return_true" )');
3983+
remove_filter( 'posts_clauses', __FUNCTION__ );
3984+
return $clauses;
3985+
}

src/wp-includes/functions.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3221,10 +3221,12 @@ function wp_nonce_ays( $action ) {
32213221
} else {
32223222
$html = __( 'The link you followed has expired.' );
32233223
if ( wp_get_referer() ) {
3224-
$html .= '</p><p>';
3225-
$html .= sprintf(
3224+
$wp_http_referer = remove_query_arg( 'updated', wp_get_referer() );
3225+
$wp_http_referer = wp_validate_redirect( esc_url_raw( $wp_http_referer ) );
3226+
$html .= '</p><p>';
3227+
$html .= sprintf(
32263228
'<a href="%s">%s</a>',
3227-
esc_url( remove_query_arg( 'updated', wp_get_referer() ) ),
3229+
esc_url( $wp_http_referer ),
32283230
__( 'Please try again.' )
32293231
);
32303232
}

src/wp-includes/media-template.php

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

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

0 commit comments

Comments
 (0)