Skip to content

Commit 11c294a

Browse files
committed
Grouped backports to the 5.8 branch.
- Editor: Bump @WordPress packages for the 5.9 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`, - Users: Revert use of shared objects for current user, - 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.8 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.8@54548 602fd350-edb4-49c9-b593-d223f7449a82
1 parent d6a1abb commit 11c294a

21 files changed

+191
-99
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
@@ -1284,7 +1284,7 @@ function wp_edit_attachments_query_vars( $q = false ) {
12841284

12851285
// Filter query clauses to include filenames.
12861286
if ( isset( $q['s'] ) ) {
1287-
add_filter( 'posts_clauses', '_filter_query_attachment_filenames' );
1287+
add_filter( 'wp_allow_query_attachment_by_filename', '__return_true' );
12881288
}
12891289

12901290
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
@@ -2466,6 +2466,15 @@ function wp_update_comment( $commentarr, $wp_error = false ) {
24662466
}
24672467
}
24682468

2469+
$filter_comment = false;
2470+
if ( ! has_filter( 'pre_comment_content', 'wp_filter_kses' ) ) {
2471+
$filter_comment = ! user_can( isset( $comment['user_id'] ) ? $comment['user_id'] : 0, 'unfiltered_html' );
2472+
}
2473+
2474+
if ( $filter_comment ) {
2475+
add_filter( 'pre_comment_content', 'wp_filter_kses' );
2476+
}
2477+
24692478
// Escape data pulled from DB.
24702479
$comment = wp_slash( $comment );
24712480

@@ -2476,6 +2485,10 @@ function wp_update_comment( $commentarr, $wp_error = false ) {
24762485

24772486
$commentarr = wp_filter_comment( $commentarr );
24782487

2488+
if ( $filter_comment ) {
2489+
remove_filter( 'pre_comment_content', 'wp_filter_kses' );
2490+
}
2491+
24792492
// Now extract the merged array.
24802493
$data = wp_unslash( $commentarr );
24812494

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
@@ -4224,3 +4224,21 @@ function _excerpt_render_inner_columns_blocks( $columns, $allowed_blocks ) {
42244224
_deprecated_function( __FUNCTION__, '5.8.0', '_excerpt_render_inner_blocks()' );
42254225
return _excerpt_render_inner_blocks( $columns, $allowed_blocks );
42264226
}
4227+
4228+
/**
4229+
* Filter the SQL clauses of an attachment query to include filenames.
4230+
*
4231+
* @since 4.7.0
4232+
* @deprecated 6.0.3
4233+
* @access private
4234+
*
4235+
* @param array $clauses An array including WHERE, GROUP BY, JOIN, ORDER BY,
4236+
* DISTINCT, fields (SELECT), and LIMITS clauses.
4237+
* @return array The unmodified clauses.
4238+
*/
4239+
function _filter_query_attachment_filenames( $clauses ) {
4240+
_deprecated_function( __FUNCTION__, '6.0.3', 'add_filter( "wp_allow_query_attachment_by_filename", "__return_true" )');
4241+
remove_filter( 'posts_clauses', __FUNCTION__ );
4242+
return $clauses;
4243+
}
4244+

src/wp-includes/functions.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3466,10 +3466,12 @@ function wp_nonce_ays( $action ) {
34663466
} else {
34673467
$html = __( 'The link you followed has expired.' );
34683468
if ( wp_get_referer() ) {
3469+
$wp_http_referer = remove_query_arg( 'updated', wp_get_referer() );
3470+
$wp_http_referer = wp_validate_redirect( esc_url_raw( $wp_http_referer ) );
34693471
$html .= '</p><p>';
34703472
$html .= sprintf(
34713473
'<a href="%s">%s</a>',
3472-
esc_url( remove_query_arg( 'updated', wp_get_referer() ) ),
3474+
esc_url( $wp_http_referer ),
34733475
__( 'Please try again.' )
34743476
);
34753477
}

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)