Make WordPress Core


Ignore:
Timestamp:
10/17/2022 06:01:26 PM (2 years ago)
Author:
audrasjb
Message:

Grouped backports to the 5.4 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.4 branch.
Props audrasjb, costdev, cu121, dd32, davidbaumwald, ehtis, johnbillion, johnjamesjacoby, martinkrcho, matveb, oztaser, paulkevan, peterwilsoncc, ravipatel, SergeyBiryukov, talldanwp, timothyblynjacobs, tykoted, voldemortensen, vortfu, xknown.

Location:
branches/5.4
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/5.4

  • branches/5.4/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php

    r47166 r54559  
    136136
    137137    /**
     138     * Checks if the terms for a post can be read.
     139     *
     140     * @since 6.0.3
     141     *
     142     * @param WP_Post         $post    Post object.
     143     * @param WP_REST_Request $request Full details about the request.
     144     * @return bool Whether the terms for the post can be read.
     145     */
     146    public function check_read_terms_permission_for_post( $post, $request ) {
     147        // If the requested post isn't associated with this taxonomy, deny access.
     148        if ( ! is_object_in_taxonomy( $post->post_type, $this->taxonomy ) ) {
     149            return false;
     150        }
     151
     152        // Grant access if the post is publicly viewable.
     153        if ( is_post_publicly_viewable( $post ) ) {
     154            return true;
     155        }
     156
     157        // Otherwise grant access if the post is readable by the logged in user.
     158        if ( current_user_can( 'read_post', $post->ID ) ) {
     159            return true;
     160        }
     161
     162        // Otherwise, deny access.
     163        return false;
     164    }
     165
     166    /**
    138167     * Checks if a request has access to read terms in the specified taxonomy.
    139168     *
     
    156185                array( 'status' => rest_authorization_required_code() )
    157186            );
     187        }
     188
     189        if ( ! empty( $request['post'] ) ) {
     190            $post = get_post( $request['post'] );
     191
     192            if ( ! $post ) {
     193                return new WP_Error(
     194                    'rest_post_invalid_id',
     195                    __( 'Invalid post ID.' ),
     196                    array(
     197                        'status' => 400,
     198                    )
     199                );
     200            }
     201
     202            if ( ! $this->check_read_terms_permission_for_post( $post, $request ) ) {
     203                return new WP_Error(
     204                    'rest_forbidden_context',
     205                    __( 'Sorry, you are not allowed to view terms for this post.' ),
     206                    array(
     207                        'status' => rest_authorization_required_code(),
     208                    )
     209                );
     210            }
    158211        }
    159212
Note: See TracChangeset for help on using the changeset viewer.