summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorSergey Biryukov <sergeybiryukov@git.wordpress.org>2022-10-17 18:10:19 +0000
committerSergey Biryukov <sergeybiryukov@git.wordpress.org>2022-10-17 18:10:19 +0000
commit4b9e2542644c11d613636e43c0eb67142e5c82f9 (patch)
tree9bed75791e5c5d1f26c7637f2cb163d2960cfab0
parent0d8b08ce013a35ed4ef203a03edeb7a51ac66dc5 (diff)
downloadwordpress-4b9e2542644c11d613636e43c0eb67142e5c82f9.tar.gz
wordpress-4b9e2542644c11d613636e43c0eb67142e5c82f9.zip
Grouped backports to the 4.8 branch.
- 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, - Media: Refactor search by filename within the admin, - Pings/trackbacks: Apply KSES to all trackbacks, - Comments: Apply kses when editing comments, - Customize: Escape blogname option in underscores templates, - REST API: Lockdown post parameter of the terms endpoint, - Mail: Reset PHPMailer properties between use, - Query: Validate relation in `WP_Date_Query`, - Widgets: Escape RSS error messages for display. Merges [54521], [54522], [54523], [54524], [54525], [54526], [54527], [54528], [54529], [54530], [54541] to the 4.8 branch. Props voldemortensen, johnbillion, paulkevan, peterwilsoncc, xknown, dd32, audrasjb, martinkrcho, vortfu, davidbaumwald, tykoted, timothyblynjacobs, johnjamesjacoby, ehtis, matveb, talldanwp. git-svn-id: https://develop.svn.wordpress.org/branches/4.8@54568 602fd350-edb4-49c9-b593-d223f7449a82
-rw-r--r--src/wp-admin/includes/ajax-actions.php2
-rw-r--r--src/wp-admin/includes/post.php2
-rw-r--r--src/wp-includes/class-wp-query.php30
-rw-r--r--src/wp-includes/comment.php13
-rw-r--r--src/wp-includes/customize/class-wp-customize-header-image-control.php4
-rw-r--r--src/wp-includes/customize/class-wp-customize-site-icon-control.php2
-rw-r--r--src/wp-includes/date.php23
-rw-r--r--src/wp-includes/deprecated.php18
-rw-r--r--src/wp-includes/functions.php13
-rw-r--r--src/wp-includes/media-template.php2
-rw-r--r--src/wp-includes/pluggable.php2
-rw-r--r--src/wp-includes/post.php123
-rw-r--r--src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php2
-rw-r--r--src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php62
-rw-r--r--src/wp-includes/widgets.php4
-rw-r--r--src/wp-mail.php5
-rw-r--r--src/wp-trackback.php3
-rw-r--r--tests/phpunit/tests/query/search.php49
-rw-r--r--tests/phpunit/tests/rest-api/rest-comments-controller.php8
19 files changed, 299 insertions, 68 deletions
diff --git a/src/wp-admin/includes/ajax-actions.php b/src/wp-admin/includes/ajax-actions.php
index 8d57c00367..5347073c2f 100644
--- a/src/wp-admin/includes/ajax-actions.php
+++ b/src/wp-admin/includes/ajax-actions.php
@@ -2466,7 +2466,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' );
}
/**
diff --git a/src/wp-admin/includes/post.php b/src/wp-admin/includes/post.php
index 52148be5d6..a2e3533645 100644
--- a/src/wp-admin/includes/post.php
+++ b/src/wp-admin/includes/post.php
@@ -1169,7 +1169,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;
diff --git a/src/wp-includes/class-wp-query.php b/src/wp-includes/class-wp-query.php
index affd3caaec..0b44608a56 100644
--- a/src/wp-includes/class-wp-query.php
+++ b/src/wp-includes/class-wp-query.php
@@ -487,6 +487,13 @@ class WP_Query {
private $compat_methods = array( 'init_query_flags', 'parse_tax_query' );
/**
+ * Controls whether an attachment query should include filenames or not.
+ *
+ * @since 6.0.3
+ * @var bool
+ */
+ protected $allow_query_attachment_by_filename = false;
+ /**
* Resets query flags to false.
*
* The query flags are what page info WordPress was able to figure out.
@@ -1346,7 +1353,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 ';
}
@@ -1683,6 +1695,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 );
@@ -2087,7 +2109,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";
}
@@ -2136,6 +2158,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'];
diff --git a/src/wp-includes/comment.php b/src/wp-includes/comment.php
index 6a125fca12..7d00719c96 100644
--- a/src/wp-includes/comment.php
+++ b/src/wp-includes/comment.php
@@ -2146,6 +2146,15 @@ function wp_update_comment($commentarr) {
return 0;
}
+ $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);
@@ -2156,6 +2165,10 @@ function wp_update_comment($commentarr) {
$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 );
diff --git a/src/wp-includes/customize/class-wp-customize-header-image-control.php b/src/wp-includes/customize/class-wp-customize-header-image-control.php
index 2fe55f4204..a65cee4d92 100644
--- a/src/wp-includes/customize/class-wp-customize-header-image-control.php
+++ b/src/wp-includes/customize/class-wp-customize-header-image-control.php
@@ -103,10 +103,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' ) { #>
diff --git a/src/wp-includes/customize/class-wp-customize-site-icon-control.php b/src/wp-includes/customize/class-wp-customize-site-icon-control.php
index ec662776d0..9cb1469c94 100644
--- a/src/wp-includes/customize/class-wp-customize-site-icon-control.php
+++ b/src/wp-includes/customize/class-wp-customize-site-icon-control.php
@@ -69,7 +69,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"><?php bloginfo( 'name' ); ?></span>
+ <span class="browser-title" aria-hidden="true"><?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>
diff --git a/src/wp-includes/date.php b/src/wp-includes/date.php
index 96a784e58d..c6b3e65432 100644
--- a/src/wp-includes/date.php
+++ b/src/wp-includes/date.php
@@ -151,8 +151,8 @@ class WP_Date_Query {
* 'comment_date', 'comment_date_gmt'.
*/
public function __construct( $date_query, $default_column = 'post_date' ) {
- 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';
}
@@ -232,6 +232,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.
@@ -1017,4 +1020,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';
+ }
+ }
}
diff --git a/src/wp-includes/deprecated.php b/src/wp-includes/deprecated.php
index 027194a8cd..42698b92d7 100644
--- a/src/wp-includes/deprecated.php
+++ b/src/wp-includes/deprecated.php
@@ -3878,3 +3878,21 @@ function _sort_nav_menu_items( $a, $b ) {
else
return strcmp( $a->$_menu_item_sort_prop, $b->$_menu_item_sort_prop );
}
+
+/**
+ * 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;
+}
+
diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php
index 2dda110f01..154cd2829c 100644
--- a/src/wp-includes/functions.php
+++ b/src/wp-includes/functions.php
@@ -2369,7 +2369,7 @@ function wp_check_filetype_and_ext( $file, $filename, $mimes = null ) {
} else {
if ( $type !== $real_mime ) {
/*
- * Everything else including image/* and application/*:
+ * Everything else including image/* and application/*:
* If the real content type doesn't match the file extension, assume it's dangerous.
*/
$type = $ext = false;
@@ -2378,7 +2378,7 @@ function wp_check_filetype_and_ext( $file, $filename, $mimes = null ) {
}
}
- // The mime type must be allowed
+ // The mime type must be allowed
if ( $type ) {
$allowed = get_allowed_mime_types();
@@ -2650,9 +2650,12 @@ function wp_nonce_ays( $action ) {
} else {
$html = __( 'Are you sure you want to do this?' );
if ( wp_get_referer() ) {
- $html .= '</p><p>';
- $html .= sprintf( '<a href="%s">%s</a>',
- esc_url( remove_query_arg( 'updated', 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( $wp_http_referer ),
__( 'Please try again.' )
);
}
diff --git a/src/wp-includes/media-template.php b/src/wp-includes/media-template.php
index efab0d50ea..beaddc01e5 100644
--- a/src/wp-includes/media-template.php
+++ b/src/wp-includes/media-template.php
@@ -1252,7 +1252,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"><?php bloginfo( 'name' ); ?></span>
+ <span class="browser-title" aria-hidden="true"><?php echo esc_js( get_bloginfo( 'name' ) ); ?></span>
</div>
<strong aria-hidden="true"><?php _e( 'As an app icon' ); ?></strong>
diff --git a/src/wp-includes/pluggable.php b/src/wp-includes/pluggable.php
index 546378111a..fbfd5c9d13 100644
--- a/src/wp-includes/pluggable.php
+++ b/src/wp-includes/pluggable.php
@@ -312,6 +312,8 @@ function wp_mail( $to, $subject, $message, $headers = '', $attachments = array()
$phpmailer->clearAttachments();
$phpmailer->clearCustomHeaders();
$phpmailer->clearReplyTos();
+ $phpmailer->Body = '';
+ $phpmailer->AltBody = '';
// From email and name
// If we don't have a name from the input headers
diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php
index 59e7ec9295..0363f9d0ee 100644
--- a/src/wp-includes/post.php
+++ b/src/wp-includes/post.php
@@ -1631,7 +1631,99 @@ function is_post_type_viewable( $post_type ) {
}
}
- return $post_type->publicly_queryable || ( $post_type->_builtin && $post_type->public );
+ if ( ! is_object( $post_type ) ) {
+ return false;
+ }
+
+ $is_viewable = $post_type->publicly_queryable || ( $post_type->_builtin && $post_type->public );
+
+ /**
+ * Filters whether a post type is considered "viewable".
+ *
+ * The returned filtered value must be a boolean type to ensure
+ * `is_post_type_viewable()` only returns a boolean. This strictness
+ * is by design to maintain backwards-compatibility and guard against
+ * potential type errors in PHP 8.1+. Non-boolean values (even falsey
+ * and truthy values) will result in the function returning false.
+ *
+ * @since 5.9.0
+ *
+ * @param bool $is_viewable Whether the post type is "viewable" (strict type).
+ * @param WP_Post_Type $post_type Post type object.
+ */
+ return true === apply_filters( 'is_post_type_viewable', $is_viewable, $post_type );
+}
+
+/**
+ * Determines whether a post status is considered "viewable".
+ *
+ * For built-in post statuses such as publish and private, the 'public' value will be evaluated.
+ * For all others, the 'publicly_queryable' value will be used.
+ *
+ * @since 5.7.0
+ * @since 5.9.0 Added `is_post_status_viewable` hook to filter the result.
+ *
+ * @param string|stdClass $post_status Post status name or object.
+ * @return bool Whether the post status should be considered viewable.
+ */
+function is_post_status_viewable( $post_status ) {
+ if ( is_scalar( $post_status ) ) {
+ $post_status = get_post_status_object( $post_status );
+
+ if ( ! $post_status ) {
+ return false;
+ }
+ }
+
+ if (
+ ! is_object( $post_status ) ||
+ $post_status->internal ||
+ $post_status->protected
+ ) {
+ return false;
+ }
+
+ $is_viewable = $post_status->publicly_queryable || ( $post_status->_builtin && $post_status->public );
+
+ /**
+ * Filters whether a post status is considered "viewable".
+ *
+ * The returned filtered value must be a boolean type to ensure
+ * `is_post_status_viewable()` only returns a boolean. This strictness
+ * is by design to maintain backwards-compatibility and guard against
+ * potential type errors in PHP 8.1+. Non-boolean values (even falsey
+ * and truthy values) will result in the function returning false.
+ *
+ * @since 5.9.0
+ *
+ * @param bool $is_viewable Whether the post status is "viewable" (strict type).
+ * @param stdClass $post_status Post status object.
+ */
+ return true === apply_filters( 'is_post_status_viewable', $is_viewable, $post_status );
+}
+
+/**
+ * Determines whether a post is publicly viewable.
+ *
+ * Posts are considered publicly viewable if both the post status and post type
+ * are viewable.
+ *
+ * @since 5.7.0
+ *
+ * @param int|WP_Post|null $post Optional. Post ID or post object. Defaults to global $post.
+ * @return bool Whether the post is publicly viewable.
+ */
+function is_post_publicly_viewable( $post = null ) {
+ $post = get_post( $post );
+
+ if ( ! $post ) {
+ return false;
+ }
+
+ $post_type = get_post_type( $post );
+ $post_status = get_post_status( $post );
+
+ return is_post_type_viewable( $post_type ) && is_post_status_viewable( $post_status );
}
/**
@@ -6241,32 +6333,3 @@ function wp_add_trashed_suffix_to_post_name_for_post( $post ) {
clean_post_cache( $post->ID );
return $post_name;
}
-
-/**
- * Filter the SQL clauses of an attachment query to include filenames.
- *
- * @since 4.7.0
- * @access private
- *
- * @global wpdb $wpdb WordPress database abstraction object.
- *
- * @param array $clauses An array including WHERE, GROUP BY, JOIN, ORDER BY,
- * DISTINCT, fields (SELECT), and LIMITS clauses.
- * @return array The modified 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;
-}
diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
index 43d057e167..a0f05fc9c2 100644
--- a/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
+++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
@@ -49,7 +49,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;
diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php
index 299b034329..1cad17acca 100644
--- a/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php
+++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php
@@ -133,6 +133,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.
*
* @since 4.7.0
@@ -143,12 +172,43 @@ class WP_REST_Terms_Controller extends WP_REST_Controller {
*/
public function get_items_permissions_check( $request ) {
$tax_obj = get_taxonomy( $this->taxonomy );
+
if ( ! $tax_obj || ! $this->check_is_taxonomy_allowed( $this->taxonomy ) ) {
return false;
}
+
if ( 'edit' === $request['context'] && ! current_user_can( $tax_obj->cap->edit_terms ) ) {
- return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to edit terms in this taxonomy.' ), array( 'status' => rest_authorization_required_code() ) );
+ return new WP_Error(
+ 'rest_forbidden_context',
+ __( 'Sorry, you are not allowed to edit terms in this taxonomy.' ),
+ array( 'status' => rest_authorization_required_code() )
+ );
+ }
+
+ 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;
}
diff --git a/src/wp-includes/widgets.php b/src/wp-includes/widgets.php
index fbbdcf5f55..9cf2d12f76 100644
--- a/src/wp-includes/widgets.php
+++ b/src/wp-includes/widgets.php
@@ -1233,7 +1233,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;
}
@@ -1342,7 +1342,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'] );
diff --git a/src/wp-mail.php b/src/wp-mail.php
index 35fb24aed2..ccbfcb1671 100644
--- a/src/wp-mail.php
+++ b/src/wp-mail.php
@@ -60,6 +60,9 @@ if( 0 === $count ) {
wp_die( __('There doesn&#8217;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);
@@ -124,8 +127,6 @@ for ( $i = 1; $i <= $count; $i++ ) {
$author = trim($line);
$author = sanitize_email($author);
if ( is_email($author) ) {
- /* translators: 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;
diff --git a/src/wp-trackback.php b/src/wp-trackback.php
index 86e17b965d..7250859cc9 100644
--- a/src/wp-trackback.php
+++ b/src/wp-trackback.php
@@ -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.
*
diff --git a/tests/phpunit/tests/query/search.php b/tests/phpunit/tests/query/search.php
index dedfa47e26..3b5a61076a 100644
--- a/tests/phpunit/tests/query/search.php
+++ b/tests/phpunit/tests/query/search.php
@@ -370,7 +370,7 @@ class Tests_Query_Search extends WP_UnitTestCase {
) );
add_post_meta( $attachment, '_wp_attached_file', 'some-image1.png', true );
- add_filter( 'posts_clauses', '_filter_query_attachment_filenames' );
+ add_filter( 'wp_allow_query_attachment_by_filename', '__return_true' );
// Pass post_type a string value.
$q = new WP_Query( array(
@@ -396,7 +396,7 @@ class Tests_Query_Search extends WP_UnitTestCase {
) );
add_post_meta( $attachment, '_wp_attached_file', 'some-image2.png', true );
- add_filter( 'posts_clauses', '_filter_query_attachment_filenames' );
+ add_filter( 'wp_allow_query_attachment_by_filename', '__return_true' );
// Pass post_type an array value.
$q = new WP_Query( array(
@@ -447,7 +447,7 @@ class Tests_Query_Search extends WP_UnitTestCase {
add_post_meta( $attachment, '_wp_attached_file', 'some-image4.png', true );
add_post_meta( $attachment, '_test_meta_key', 'value', true );
- add_filter( 'posts_clauses', '_filter_query_attachment_filenames' );
+ add_filter( 'wp_allow_query_attachment_by_filename', '__return_true' );
// Pass post_type a string value.
$q = new WP_Query( array(
@@ -483,7 +483,7 @@ class Tests_Query_Search extends WP_UnitTestCase {
wp_set_post_terms( $attachment, 'test', 'post_tag' );
add_post_meta( $attachment, '_wp_attached_file', 'some-image5.png', true );
- add_filter( 'posts_clauses', '_filter_query_attachment_filenames' );
+ add_filter( 'wp_allow_query_attachment_by_filename', '__return_true' );
// Pass post_type a string value.
$q = new WP_Query( array(
@@ -506,22 +506,37 @@ class Tests_Query_Search extends WP_UnitTestCase {
/**
* @ticket 22744
*/
- public function test_filter_query_attachment_filenames_unhooks_itself() {
- add_filter( 'posts_clauses', '_filter_query_attachment_filenames' );
+ public function test_wp_query_removes_filter_wp_allow_query_attachment_by_filename() {
+ $attachment = self::factory()->post->create(
+ array(
+ 'post_type' => 'attachment',
+ 'post_status' => 'publish',
+ 'post_title' => 'bar foo',
+ 'post_content' => 'foo bar',
+ 'post_excerpt' => 'This post has foo',
+ )
+ );
- apply_filters( 'posts_clauses', array(
- 'where' => '',
- 'groupby' => '',
- 'join' => '',
- 'orderby' => '',
- 'distinct' => '',
- 'fields' => '',
- 'limit' => '',
- ) );
+ add_post_meta( $attachment, '_wp_attached_file', 'some-image1.png', true );
+ add_filter( 'wp_allow_query_attachment_by_filename', '__return_true' );
- $result = has_filter( 'posts_clauses', '_filter_query_attachment_filenames' );
+ $q = new WP_Query(
+ array(
+ 's' => 'image1',
+ 'fields' => 'ids',
+ 'post_type' => 'attachment',
+ 'post_status' => 'inherit',
+ )
+ );
+
+ $this->assertSame( array( $attachment ), $q->posts );
- $this->assertFalse( $result );
+ /*
+ * WP_Query should have removed the wp_allow_query_attachment_by_filename filter
+ * and thus not match the attachment created above
+ */
+ $q->get_posts();
+ $this->assertEmpty( $q->posts );
}
public function filter_posts_search( $sql ) {
diff --git a/tests/phpunit/tests/rest-api/rest-comments-controller.php b/tests/phpunit/tests/rest-api/rest-comments-controller.php
index 502a6d2c5b..c7aa20bfba 100644
--- a/tests/phpunit/tests/rest-api/rest-comments-controller.php
+++ b/tests/phpunit/tests/rest-api/rest-comments-controller.php
@@ -2590,6 +2590,7 @@ class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase
'content' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>',
'author_name' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>',
'author_user_agent' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>',
+ 'author' => self::$editor_id,
), array(
'content' => array(
'raw' => 'div <strong>strong</strong> oh noes',
@@ -2597,6 +2598,7 @@ class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase
),
'author_name' => 'div strong',
'author_user_agent' => 'div strong',
+ 'author' => self::$editor_id,
) );
} else {
$this->assertTrue( current_user_can( 'unfiltered_html' ) );
@@ -2604,6 +2606,7 @@ class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase
'content' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>',
'author_name' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>',
'author_user_agent' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>',
+ 'author' => self::$editor_id,
), array(
'content' => array(
'raw' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>',
@@ -2611,6 +2614,7 @@ class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase
),
'author_name' => 'div strong',
'author_user_agent' => 'div strong',
+ 'author' => self::$editor_id,
) );
}
}
@@ -2622,6 +2626,7 @@ class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase
'content' => '\\\&\\\ &amp; &invalid; < &lt; &amp;lt;',
'author_name' => '\\\&\\\ &amp; &invalid; < &lt; &amp;lt;',
'author_user_agent' => '\\\&\\\ &amp; &invalid; < &lt; &amp;lt;',
+ 'author' => self::$superadmin_id,
), array(
'content' => array(
'raw' => '\\\&\\\ &amp; &invalid; < &lt; &amp;lt;',
@@ -2629,6 +2634,7 @@ class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase
),
'author_name' => '\\\&amp;\\\ &amp; &amp;invalid; &lt; &lt; &amp;lt;',
'author_user_agent' => '\\\&\\\ &amp; &invalid; &lt; &lt; &amp;lt;',
+ 'author' => self::$superadmin_id,
) );
}
@@ -2639,6 +2645,7 @@ class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase
'content' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>',
'author_name' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>',
'author_user_agent' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>',
+ 'author' => self::$superadmin_id,
), array(
'content' => array(
'raw' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>',
@@ -2646,6 +2653,7 @@ class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase
),
'author_name' => 'div strong',
'author_user_agent' => 'div strong',
+ 'author' => self::$superadmin_id,
) );
}