Skip to content

Commit cb637ad

Browse files
committed
Grouped backports to the 5.3 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.3 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.3@54562 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 6327022 commit cb637ad

19 files changed

+296
-68
lines changed

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

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

29472947
// Filter query clauses to include filenames.
29482948
if ( isset( $query['s'] ) ) {
2949-
add_filter( 'posts_clauses', '_filter_query_attachment_filenames' );
2949+
add_filter( 'wp_allow_query_attachment_by_filename', '__return_true' );
29502950
}
29512951

29522952
/**

src/wp-admin/includes/post.php

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

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

12561256
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
@@ -433,6 +433,13 @@ class WP_Query {
433433
*/
434434
public $thumbnails_cached = false;
435435

436+
/**
437+
* Controls whether an attachment query should include filenames or not.
438+
*
439+
* @since 6.0.3
440+
* @var bool
441+
*/
442+
protected $allow_query_attachment_by_filename = false;
436443
/**
437444
* Cached list of search stopwords.
438445
*
@@ -1373,8 +1380,13 @@ protected function parse_search( &$q ) {
13731380
$q['search_orderby_title'][] = $wpdb->prepare( "{$wpdb->posts}.post_title LIKE %s", $like );
13741381
}
13751382

1376-
$like = $n . $wpdb->esc_like( $term ) . $n;
1377-
$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 );
1383+
$like = $n . $wpdb->esc_like( $term ) . $n;
1384+
1385+
if ( ! empty( $this->allow_query_attachment_by_filename ) ) {
1386+
$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 );
1387+
} else {
1388+
$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 );
1389+
}
13781390
$searchand = ' AND ';
13791391
}
13801392

@@ -1758,6 +1770,16 @@ public function get_posts() {
17581770
// Fill again in case pre_get_posts unset some vars.
17591771
$q = $this->fill_query_vars( $q );
17601772

1773+
/**
1774+
* Filters whether an attachment query should include filenames or not.
1775+
*
1776+
* @since 6.0.3
1777+
*
1778+
* @param bool $allow_query_attachment_by_filename Whether or not to include filenames.
1779+
*/
1780+
$this->allow_query_attachment_by_filename = apply_filters( 'wp_allow_query_attachment_by_filename', false );
1781+
remove_all_filters( 'wp_allow_query_attachment_by_filename' );
1782+
17611783
// Parse meta query
17621784
$this->meta_query = new WP_Meta_Query();
17631785
$this->meta_query->parse_query_vars( $q );
@@ -2189,7 +2211,7 @@ public function get_posts() {
21892211
}
21902212
}
21912213

2192-
if ( ! empty( $this->tax_query->queries ) || ! empty( $this->meta_query->queries ) ) {
2214+
if ( ! empty( $this->tax_query->queries ) || ! empty( $this->meta_query->queries ) || ! empty( $this->allow_query_attachment_by_filename ) ) {
21932215
$groupby = "{$wpdb->posts}.ID";
21942216
}
21952217

@@ -2266,6 +2288,10 @@ public function get_posts() {
22662288
}
22672289
$where .= $search . $whichauthor . $whichmimetype;
22682290

2291+
if ( ! empty( $this->allow_query_attachment_by_filename ) ) {
2292+
$join .= " LEFT JOIN {$wpdb->postmeta} AS sq1 ON ( {$wpdb->posts}.ID = sq1.post_id AND sq1.meta_key = '_wp_attached_file' )";
2293+
}
2294+
22692295
if ( ! empty( $this->meta_query->queries ) ) {
22702296
$clauses = $this->meta_query->get_sql( 'post', $wpdb->posts, 'ID', $this );
22712297
$join .= $clauses['join'];

src/wp-includes/comment.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2331,6 +2331,15 @@ function wp_update_comment( $commentarr ) {
23312331
return 0;
23322332
}
23332333

2334+
$filter_comment = false;
2335+
if ( ! has_filter( 'pre_comment_content', 'wp_filter_kses' ) ) {
2336+
$filter_comment = ! user_can( isset( $comment['user_id'] ) ? $comment['user_id'] : 0, 'unfiltered_html' );
2337+
}
2338+
2339+
if ( $filter_comment ) {
2340+
add_filter( 'pre_comment_content', 'wp_filter_kses' );
2341+
}
2342+
23342343
// Escape data pulled from DB.
23352344
$comment = wp_slash( $comment );
23362345

@@ -2341,6 +2350,10 @@ function wp_update_comment( $commentarr ) {
23412350

23422351
$commentarr = wp_filter_comment( $commentarr );
23432352

2353+
if ( $filter_comment ) {
2354+
remove_filter( 'pre_comment_content', 'wp_filter_kses' );
2355+
}
2356+
23442357
// Now extract the merged array.
23452358
$data = wp_unslash( $commentarr );
23462359

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
@@ -64,7 +64,7 @@ public function content_template() {
6464
<div class="favicon">
6565
<img src="{{ data.attachment.sizes.full ? data.attachment.sizes.full.url : data.attachment.url }}" alt="<?php esc_attr_e( 'Preview as a browser icon' ); ?>"/>
6666
</div>
67-
<span class="browser-title" aria-hidden="true"><# print( '<?php bloginfo( 'name' ); ?>' ) #></span>
67+
<span class="browser-title" aria-hidden="true"><# print( '<?php echo esc_js( get_bloginfo( 'name' ) ); ?>' ) #></span>
6868
</div>
6969
<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' ); ?>"/>
7070
</div>

src/wp-includes/deprecated.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3953,3 +3953,21 @@ function wp_ajax_press_this_add_category() {
39533953
wp_send_json_error( array( 'errorMessage' => __( 'The Press This plugin is required.' ) ) );
39543954
}
39553955
}
3956+
3957+
/**
3958+
* Filter the SQL clauses of an attachment query to include filenames.
3959+
*
3960+
* @since 4.7.0
3961+
* @deprecated 6.0.3
3962+
* @access private
3963+
*
3964+
* @param array $clauses An array including WHERE, GROUP BY, JOIN, ORDER BY,
3965+
* DISTINCT, fields (SELECT), and LIMITS clauses.
3966+
* @return array The unmodified clauses.
3967+
*/
3968+
function _filter_query_attachment_filenames( $clauses ) {
3969+
_deprecated_function( __FUNCTION__, '6.0.3', 'add_filter( "wp_allow_query_attachment_by_filename", "__return_true" )');
3970+
remove_filter( 'posts_clauses', __FUNCTION__ );
3971+
return $clauses;
3972+
}
3973+

src/wp-includes/functions.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3164,10 +3164,12 @@ function wp_nonce_ays( $action ) {
31643164
} else {
31653165
$html = __( 'The link you followed has expired.' );
31663166
if ( wp_get_referer() ) {
3167-
$html .= '</p><p>';
3168-
$html .= sprintf(
3167+
$wp_http_referer = remove_query_arg( 'updated', wp_get_referer() );
3168+
$wp_http_referer = wp_validate_redirect( esc_url_raw( $wp_http_referer ) );
3169+
$html .= '</p><p>';
3170+
$html .= sprintf(
31693171
'<a href="%s">%s</a>',
3170-
esc_url( remove_query_arg( 'updated', wp_get_referer() ) ),
3172+
esc_url( $wp_http_referer ),
31713173
__( 'Please try again.' )
31723174
);
31733175
}

src/wp-includes/media-template.php

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

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

0 commit comments

Comments
 (0)