-
+
diff --git a/wp-includes/pluggable.php b/wp-includes/pluggable.php
index c0dc11940e..2896d32410 100644
--- a/wp-includes/pluggable.php
+++ b/wp-includes/pluggable.php
@@ -314,6 +314,8 @@ if ( ! function_exists( 'wp_mail' ) ) :
$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/wp-includes/post.php b/wp-includes/post.php
index 50edde5c79..3aa8581dcd 100644
--- a/wp-includes/post.php
+++ b/wp-includes/post.php
@@ -1883,6 +1883,7 @@ function set_post_type( $post_id = 0, $post_type = 'post' ) {
* @since 4.4.0
* @since 4.5.0 Added the ability to pass a post type name in addition to object.
* @since 4.6.0 Converted the `$post_type` parameter to accept a `WP_Post_Type` object.
+ * @since 5.9.0 Added `is_post_type_viewable` hook to filter the result.
*
* @param string|WP_Post_Type $post_type Post type name or object.
* @return bool Whether the post type should be considered viewable.
@@ -1890,12 +1891,105 @@ function set_post_type( $post_id = 0, $post_type = 'post' ) {
function is_post_type_viewable( $post_type ) {
if ( is_scalar( $post_type ) ) {
$post_type = get_post_type_object( $post_type );
+
if ( ! $post_type ) {
return false;
}
}
- 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 );
}
/**
@@ -6862,36 +6956,6 @@ function wp_add_trashed_suffix_to_post_name_for_post( $post ) {
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;
-}
-
/**
* Sets the last changed time for the 'posts' cache group.
*
diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
index fe7bd06ee0..8cad40b912 100644
--- a/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
+++ b/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
@@ -48,7 +48,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/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php
index f4751eb205..4047e666af 100644
--- a/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php
+++ b/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php
@@ -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.
*
@@ -144,12 +173,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/wp-includes/widgets.php b/wp-includes/widgets.php
index c2c3067ec9..ddfd926dbf 100644
--- a/wp-includes/widgets.php
+++ b/wp-includes/widgets.php
@@ -1446,7 +1446,7 @@ function wp_widget_rss_output( $rss, $args = array() ) {
if ( is_wp_error( $rss ) ) {
if ( is_admin() || current_user_can( 'manage_options' ) ) {
- echo '