mirror of
https://github.com/WordPress/WordPress.git
synced 2024-11-13 06:07:23 +01:00
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. Built from https://develop.svn.wordpress.org/branches/5.8@54548 git-svn-id: http://core.svn.wordpress.org/branches/5.8@54103 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
0bad0b3e48
commit
d8ffe4fe33
@ -2974,7 +2974,7 @@ function wp_ajax_query_attachments() {
|
||||
|
||||
// Filter query clauses to include filenames.
|
||||
if ( isset( $query['s'] ) ) {
|
||||
add_filter( 'posts_clauses', '_filter_query_attachment_filenames' );
|
||||
add_filter( 'wp_allow_query_attachment_by_filename', '__return_true' );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1284,7 +1284,7 @@ function wp_edit_attachments_query_vars( $q = false ) {
|
||||
|
||||
// Filter query clauses to include filenames.
|
||||
if ( isset( $q['s'] ) ) {
|
||||
add_filter( 'posts_clauses', '_filter_query_attachment_filenames' );
|
||||
add_filter( 'wp_allow_query_attachment_by_filename', '__return_true' );
|
||||
}
|
||||
|
||||
return $q;
|
||||
|
@ -149,8 +149,8 @@ class WP_Date_Query {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( isset( $date_query['relation'] ) && 'OR' === strtoupper( $date_query['relation'] ) ) {
|
||||
$this->relation = 'OR';
|
||||
if ( isset( $date_query['relation'] ) ) {
|
||||
$this->relation = $this->sanitize_relation( $date_query['relation'] );
|
||||
} else {
|
||||
$this->relation = 'AND';
|
||||
}
|
||||
@ -219,6 +219,9 @@ class WP_Date_Query {
|
||||
$this->validate_date_values( $queries );
|
||||
}
|
||||
|
||||
// Sanitize the relation parameter.
|
||||
$queries['relation'] = $this->sanitize_relation( $queries['relation'] );
|
||||
|
||||
foreach ( $queries as $key => $q ) {
|
||||
if ( ! is_array( $q ) || in_array( $key, $this->time_keys, true ) ) {
|
||||
// This is a first-order query. Trust the values and sanitize when building SQL.
|
||||
@ -1039,4 +1042,20 @@ class WP_Date_Query {
|
||||
|
||||
return $wpdb->prepare( "DATE_FORMAT( $column, %s ) $compare %f", $format, $time );
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitizes a 'relation' operator.
|
||||
*
|
||||
* @since 6.0.3
|
||||
*
|
||||
* @param string $relation Raw relation key from the query argument.
|
||||
* @return string Sanitized relation ('AND' or 'OR').
|
||||
*/
|
||||
public function sanitize_relation( $relation ) {
|
||||
if ( 'OR' === strtoupper( $relation ) ) {
|
||||
return 'OR';
|
||||
} else {
|
||||
return 'AND';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -444,6 +444,13 @@ class WP_Query {
|
||||
*/
|
||||
public $thumbnails_cached = false;
|
||||
|
||||
/**
|
||||
* Controls whether an attachment query should include filenames or not.
|
||||
*
|
||||
* @since 6.0.3
|
||||
* @var bool
|
||||
*/
|
||||
protected $allow_query_attachment_by_filename = false;
|
||||
/**
|
||||
* Cached list of search stopwords.
|
||||
*
|
||||
@ -1394,7 +1401,12 @@ class WP_Query {
|
||||
}
|
||||
|
||||
$like = $n . $wpdb->esc_like( $term ) . $n;
|
||||
$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 );
|
||||
|
||||
if ( ! empty( $this->allow_query_attachment_by_filename ) ) {
|
||||
$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 );
|
||||
} else {
|
||||
$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 );
|
||||
}
|
||||
$searchand = ' AND ';
|
||||
}
|
||||
|
||||
@ -1789,6 +1801,16 @@ class WP_Query {
|
||||
// Fill again in case 'pre_get_posts' unset some vars.
|
||||
$q = $this->fill_query_vars( $q );
|
||||
|
||||
/**
|
||||
* Filters whether an attachment query should include filenames or not.
|
||||
*
|
||||
* @since 6.0.3
|
||||
*
|
||||
* @param bool $allow_query_attachment_by_filename Whether or not to include filenames.
|
||||
*/
|
||||
$this->allow_query_attachment_by_filename = apply_filters( 'wp_allow_query_attachment_by_filename', false );
|
||||
remove_all_filters( 'wp_allow_query_attachment_by_filename' );
|
||||
|
||||
// Parse meta query.
|
||||
$this->meta_query = new WP_Meta_Query();
|
||||
$this->meta_query->parse_query_vars( $q );
|
||||
@ -2220,7 +2242,7 @@ class WP_Query {
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $this->tax_query->queries ) || ! empty( $this->meta_query->queries ) ) {
|
||||
if ( ! empty( $this->tax_query->queries ) || ! empty( $this->meta_query->queries ) || ! empty( $this->allow_query_attachment_by_filename ) ) {
|
||||
$groupby = "{$wpdb->posts}.ID";
|
||||
}
|
||||
|
||||
@ -2297,6 +2319,10 @@ class WP_Query {
|
||||
}
|
||||
$where .= $search . $whichauthor . $whichmimetype;
|
||||
|
||||
if ( ! empty( $this->allow_query_attachment_by_filename ) ) {
|
||||
$join .= " LEFT JOIN {$wpdb->postmeta} AS sq1 ON ( {$wpdb->posts}.ID = sq1.post_id AND sq1.meta_key = '_wp_attached_file' )";
|
||||
}
|
||||
|
||||
if ( ! empty( $this->meta_query->queries ) ) {
|
||||
$clauses = $this->meta_query->get_sql( 'post', $wpdb->posts, 'ID', $this );
|
||||
$join .= $clauses['join'];
|
||||
|
@ -2466,6 +2466,15 @@ function wp_update_comment( $commentarr, $wp_error = false ) {
|
||||
}
|
||||
}
|
||||
|
||||
$filter_comment = false;
|
||||
if ( ! has_filter( 'pre_comment_content', 'wp_filter_kses' ) ) {
|
||||
$filter_comment = ! user_can( isset( $comment['user_id'] ) ? $comment['user_id'] : 0, 'unfiltered_html' );
|
||||
}
|
||||
|
||||
if ( $filter_comment ) {
|
||||
add_filter( 'pre_comment_content', 'wp_filter_kses' );
|
||||
}
|
||||
|
||||
// Escape data pulled from DB.
|
||||
$comment = wp_slash( $comment );
|
||||
|
||||
@ -2476,6 +2485,10 @@ function wp_update_comment( $commentarr, $wp_error = false ) {
|
||||
|
||||
$commentarr = wp_filter_comment( $commentarr );
|
||||
|
||||
if ( $filter_comment ) {
|
||||
remove_filter( 'pre_comment_content', 'wp_filter_kses' );
|
||||
}
|
||||
|
||||
// Now extract the merged array.
|
||||
$data = wp_unslash( $commentarr );
|
||||
|
||||
|
@ -130,10 +130,10 @@ class WP_Customize_Header_Image_Control extends WP_Customize_Image_Control {
|
||||
<# } else { #>
|
||||
|
||||
<button type="button" class="choice thumbnail"
|
||||
data-customize-image-value="{{{data.header.url}}}"
|
||||
data-customize-image-value="{{data.header.url}}"
|
||||
data-customize-header-image-data="{{JSON.stringify(data.header)}}">
|
||||
<span class="screen-reader-text"><?php _e( 'Set image' ); ?></span>
|
||||
<img src="{{{data.header.thumbnail_url}}}" alt="{{{data.header.alt_text || data.header.description}}}" />
|
||||
<img src="{{data.header.thumbnail_url}}" alt="{{data.header.alt_text || data.header.description}}" />
|
||||
</button>
|
||||
|
||||
<# if ( data.type === 'uploaded' ) { #>
|
||||
@ -158,7 +158,7 @@ class WP_Customize_Header_Image_Control extends WP_Customize_Image_Control {
|
||||
|
||||
<# } else { #>
|
||||
|
||||
<img src="{{{data.header.thumbnail_url}}}" alt="{{{data.header.alt_text || data.header.description}}}" />
|
||||
<img src="{{data.header.thumbnail_url}}" alt="{{data.header.alt_text || data.header.description}}" />
|
||||
|
||||
<# } #>
|
||||
<# } else { #>
|
||||
|
@ -68,7 +68,7 @@ class WP_Customize_Site_Icon_Control extends WP_Customize_Cropped_Image_Control
|
||||
<div class="favicon">
|
||||
<img src="{{ data.attachment.sizes.full ? data.attachment.sizes.full.url : data.attachment.url }}" alt="<?php esc_attr_e( 'Preview as a browser icon' ); ?>" />
|
||||
</div>
|
||||
<span class="browser-title" aria-hidden="true"><# print( '<?php bloginfo( 'name' ); ?>' ) #></span>
|
||||
<span class="browser-title" aria-hidden="true"><# print( '<?php echo esc_js( get_bloginfo( 'name' ) ); ?>' ) #></span>
|
||||
</div>
|
||||
<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' ); ?>" />
|
||||
</div>
|
||||
|
@ -4224,3 +4224,21 @@ function _excerpt_render_inner_columns_blocks( $columns, $allowed_blocks ) {
|
||||
_deprecated_function( __FUNCTION__, '5.8.0', '_excerpt_render_inner_blocks()' );
|
||||
return _excerpt_render_inner_blocks( $columns, $allowed_blocks );
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the SQL clauses of an attachment query to include filenames.
|
||||
*
|
||||
* @since 4.7.0
|
||||
* @deprecated 6.0.3
|
||||
* @access private
|
||||
*
|
||||
* @param array $clauses An array including WHERE, GROUP BY, JOIN, ORDER BY,
|
||||
* DISTINCT, fields (SELECT), and LIMITS clauses.
|
||||
* @return array The unmodified clauses.
|
||||
*/
|
||||
function _filter_query_attachment_filenames( $clauses ) {
|
||||
_deprecated_function( __FUNCTION__, '6.0.3', 'add_filter( "wp_allow_query_attachment_by_filename", "__return_true" )');
|
||||
remove_filter( 'posts_clauses', __FUNCTION__ );
|
||||
return $clauses;
|
||||
}
|
||||
|
||||
|
@ -3466,10 +3466,12 @@ function wp_nonce_ays( $action ) {
|
||||
} else {
|
||||
$html = __( 'The link you followed has expired.' );
|
||||
if ( wp_get_referer() ) {
|
||||
$wp_http_referer = remove_query_arg( 'updated', wp_get_referer() );
|
||||
$wp_http_referer = wp_validate_redirect( esc_url_raw( $wp_http_referer ) );
|
||||
$html .= '</p><p>';
|
||||
$html .= sprintf(
|
||||
'<a href="%s">%s</a>',
|
||||
esc_url( remove_query_arg( 'updated', wp_get_referer() ) ),
|
||||
esc_url( $wp_http_referer ),
|
||||
__( 'Please try again.' )
|
||||
);
|
||||
}
|
||||
|
@ -1493,7 +1493,7 @@ function wp_print_media_templates() {
|
||||
<div class="favicon">
|
||||
<img id="preview-favicon" src="{{ data.url }}" alt="<?php esc_attr_e( 'Preview as a browser icon' ); ?>" />
|
||||
</div>
|
||||
<span class="browser-title" aria-hidden="true"><# print( '<?php bloginfo( 'name' ); ?>' ) #></span>
|
||||
<span class="browser-title" aria-hidden="true"><# print( '<?php echo esc_js( get_bloginfo( 'name' ) ); ?>' ) #></span>
|
||||
</div>
|
||||
|
||||
<strong aria-hidden="true"><?php _e( 'As an app icon' ); ?></strong>
|
||||
|
@ -91,7 +91,6 @@ if ( ! function_exists( 'get_user_by' ) ) :
|
||||
*
|
||||
* @since 2.8.0
|
||||
* @since 4.4.0 Added 'ID' as an alias of 'id' for the `$field` parameter.
|
||||
* @since 5.8.0 Returns the global `$current_user` if it's the user being fetched.
|
||||
*
|
||||
* @global WP_User $current_user The current user object which holds the user data.
|
||||
*
|
||||
@ -100,18 +99,12 @@ if ( ! function_exists( 'get_user_by' ) ) :
|
||||
* @return WP_User|false WP_User object on success, false on failure.
|
||||
*/
|
||||
function get_user_by( $field, $value ) {
|
||||
global $current_user;
|
||||
|
||||
$userdata = WP_User::get_data_by( $field, $value );
|
||||
|
||||
if ( ! $userdata ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( $current_user instanceof WP_User && $current_user->ID === (int) $userdata->ID ) {
|
||||
return $current_user;
|
||||
}
|
||||
|
||||
$user = new WP_User;
|
||||
$user->init( $userdata );
|
||||
|
||||
@ -361,6 +354,8 @@ if ( ! function_exists( 'wp_mail' ) ) :
|
||||
$phpmailer->clearAttachments();
|
||||
$phpmailer->clearCustomHeaders();
|
||||
$phpmailer->clearReplyTos();
|
||||
$phpmailer->Body = '';
|
||||
$phpmailer->AltBody = '';
|
||||
|
||||
// Set "From" name and email.
|
||||
|
||||
|
@ -7694,36 +7694,6 @@ function wp_add_trashed_suffix_to_post_name_for_post( $post ) {
|
||||
return $post_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters the SQL clauses of an attachment query to include filenames.
|
||||
*
|
||||
* @since 4.7.0
|
||||
* @access private
|
||||
*
|
||||
* @global wpdb $wpdb WordPress database abstraction object.
|
||||
*
|
||||
* @param string[] $clauses An array including WHERE, GROUP BY, JOIN, ORDER BY,
|
||||
* DISTINCT, fields (SELECT), and LIMITS clauses.
|
||||
* @return string[] The modified array of clauses.
|
||||
*/
|
||||
function _filter_query_attachment_filenames( $clauses ) {
|
||||
global $wpdb;
|
||||
remove_filter( 'posts_clauses', __FUNCTION__ );
|
||||
|
||||
// Add a LEFT JOIN of the postmeta table so we don't trample existing JOINs.
|
||||
$clauses['join'] .= " LEFT JOIN {$wpdb->postmeta} AS sq1 ON ( {$wpdb->posts}.ID = sq1.post_id AND sq1.meta_key = '_wp_attached_file' )";
|
||||
|
||||
$clauses['groupby'] = "{$wpdb->posts}.ID";
|
||||
|
||||
$clauses['where'] = preg_replace(
|
||||
"/\({$wpdb->posts}.post_content (NOT LIKE|LIKE) (\'[^']+\')\)/",
|
||||
'$0 OR ( sq1.meta_value $1 $2 )',
|
||||
$clauses['where']
|
||||
);
|
||||
|
||||
return $clauses;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the last changed time for the 'posts' cache group.
|
||||
*
|
||||
|
@ -89,7 +89,7 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller {
|
||||
|
||||
// Filter query clauses to include filenames.
|
||||
if ( isset( $query_args['s'] ) ) {
|
||||
add_filter( 'posts_clauses', '_filter_query_attachment_filenames' );
|
||||
add_filter( 'wp_allow_query_attachment_by_filename', '__return_true' );
|
||||
}
|
||||
|
||||
return $query_args;
|
||||
|
@ -134,6 +134,35 @@ class WP_REST_Terms_Controller extends WP_REST_Controller {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the terms for a post can be read.
|
||||
*
|
||||
* @since 6.0.3
|
||||
*
|
||||
* @param WP_Post $post Post object.
|
||||
* @param WP_REST_Request $request Full details about the request.
|
||||
* @return bool Whether the terms for the post can be read.
|
||||
*/
|
||||
public function check_read_terms_permission_for_post( $post, $request ) {
|
||||
// If the requested post isn't associated with this taxonomy, deny access.
|
||||
if ( ! is_object_in_taxonomy( $post->post_type, $this->taxonomy ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Grant access if the post is publicly viewable.
|
||||
if ( is_post_publicly_viewable( $post ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Otherwise grant access if the post is readable by the logged in user.
|
||||
if ( current_user_can( 'read_post', $post->ID ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Otherwise, deny access.
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a request has access to read terms in the specified taxonomy.
|
||||
*
|
||||
@ -157,6 +186,30 @@ class WP_REST_Terms_Controller extends WP_REST_Controller {
|
||||
);
|
||||
}
|
||||
|
||||
if ( ! empty( $request['post'] ) ) {
|
||||
$post = get_post( $request['post'] );
|
||||
|
||||
if ( ! $post ) {
|
||||
return new WP_Error(
|
||||
'rest_post_invalid_id',
|
||||
__( 'Invalid post ID.' ),
|
||||
array(
|
||||
'status' => 400,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ( ! $this->check_read_terms_permission_for_post( $post, $request ) ) {
|
||||
return new WP_Error(
|
||||
'rest_forbidden_context',
|
||||
__( 'Sorry, you are not allowed to view terms for this post.' ),
|
||||
array(
|
||||
'status' => rest_authorization_required_code(),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1571,15 +1571,10 @@ function update_user_caches( $user ) {
|
||||
*
|
||||
* @since 3.0.0
|
||||
* @since 4.4.0 'clean_user_cache' action was added.
|
||||
* @since 5.8.0 Refreshes the global user instance if cleaning the user cache for the current user.
|
||||
*
|
||||
* @global WP_User $current_user The current user object which holds the user data.
|
||||
*
|
||||
* @param WP_User|int $user User object or ID to be cleaned from the cache
|
||||
*/
|
||||
function clean_user_cache( $user ) {
|
||||
global $current_user;
|
||||
|
||||
if ( is_numeric( $user ) ) {
|
||||
$user = new WP_User( $user );
|
||||
}
|
||||
@ -1602,13 +1597,6 @@ function clean_user_cache( $user ) {
|
||||
* @param WP_User $user User object.
|
||||
*/
|
||||
do_action( 'clean_user_cache', $user->ID, $user );
|
||||
|
||||
// Refresh the global user instance if the cleaning current user.
|
||||
if ( get_current_user_id() === (int) $user->ID ) {
|
||||
$user_id = (int) $user->ID;
|
||||
$current_user = null;
|
||||
wp_set_current_user( $user_id, '' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1534,7 +1534,7 @@ function wp_widget_rss_output( $rss, $args = array() ) {
|
||||
|
||||
if ( is_wp_error( $rss ) ) {
|
||||
if ( is_admin() || current_user_can( 'manage_options' ) ) {
|
||||
echo '<p><strong>' . __( 'RSS Error:' ) . '</strong> ' . $rss->get_error_message() . '</p>';
|
||||
echo '<p><strong>' . __( 'RSS Error:' ) . '</strong> ' . esc_html( $rss->get_error_message() ) . '</p>';
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -1657,7 +1657,7 @@ function wp_widget_rss_form( $args, $inputs = null ) {
|
||||
$args['show_date'] = isset( $args['show_date'] ) ? (int) $args['show_date'] : (int) $inputs['show_date'];
|
||||
|
||||
if ( ! empty( $args['error'] ) ) {
|
||||
echo '<p class="widget-error"><strong>' . __( 'RSS Error:' ) . '</strong> ' . $args['error'] . '</p>';
|
||||
echo '<p class="widget-error"><strong>' . __( 'RSS Error:' ) . '</strong> ' . esc_html( $args['error'] ) . '</p>';
|
||||
}
|
||||
|
||||
$esc_number = esc_attr( $args['number'] );
|
||||
|
@ -65,6 +65,9 @@ if ( 0 === $count ) {
|
||||
wp_die( __( 'There doesn’t seem to be any new mail.' ) );
|
||||
}
|
||||
|
||||
// Always run as an unauthenticated user.
|
||||
wp_set_current_user( 0 );
|
||||
|
||||
for ( $i = 1; $i <= $count; $i++ ) {
|
||||
|
||||
$message = $pop3->get( $i );
|
||||
@ -131,8 +134,6 @@ for ( $i = 1; $i <= $count; $i++ ) {
|
||||
}
|
||||
$author = sanitize_email( $author );
|
||||
if ( is_email( $author ) ) {
|
||||
/* translators: %s: Post author email address. */
|
||||
echo '<p>' . sprintf( __( 'Author is %s' ), $author ) . '</p>';
|
||||
$userdata = get_user_by( 'email', $author );
|
||||
if ( ! empty( $userdata ) ) {
|
||||
$post_author = $userdata->ID;
|
||||
|
@ -13,6 +13,9 @@ if ( empty( $wp ) ) {
|
||||
wp( array( 'tb' => '1' ) );
|
||||
}
|
||||
|
||||
// Always run as an unauthenticated user.
|
||||
wp_set_current_user( 0 );
|
||||
|
||||
/**
|
||||
* Response to a trackback.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user