Make WordPress Core


Ignore:
Timestamp:
09/30/2025 05:06:32 PM (6 months ago)
Author:
desrosj
Message:

Grouped backports for the 4.8 branch.

  • REST API: Increase the specificity of capability checks for collections when the edit context is in use.
  • Menus: Prevent HTML in menu item titles from being rendered unexpectedly.

Merges [60814], [60815], [60816] to the 4.8 branch.

Props andraganescu, desrosj, ehti, hurayraiit, iandunn, joehoyle, johnbillion, jorbin, mnelson4, noisysocks, peterwilsoncc, phillsav, rmccue, timothyblynjacobs, vortfu, westonruter , whyisjake, zieladam.

Location:
branches/4.8
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.8

  • branches/4.8/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php

    r56864 r60838  
    185185
    186186        if ( 'edit' === $request['context'] && ! current_user_can( 'list_users' ) ) {
    187             return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to list users.' ), array( 'status' => rest_authorization_required_code() ) );
     187            return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to edit users.' ), array( 'status' => rest_authorization_required_code() ) );
    188188        }
    189189
     
    283283
    284284        foreach ( $query->results as $user ) {
     285            if ( 'edit' === $request['context'] && ! current_user_can( 'edit_user', $user->ID ) ) {
     286                continue;
     287            }
    285288            $data = $this->prepare_item_for_response( $user, $request );
    286289            $users[] = $this->prepare_response_for_collection( $data );
     
    378381        }
    379382
    380         if ( 'edit' === $request['context'] && ! current_user_can( 'list_users' ) ) {
    381             return new WP_Error( 'rest_user_cannot_view', __( 'Sorry, you are not allowed to list users.' ), array( 'status' => rest_authorization_required_code() ) );
     383        if ( 'edit' === $request['context'] && ! current_user_can( 'edit_user', $user->ID ) ) {
     384            return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to edit this user.' ), array( 'status' => rest_authorization_required_code() ) );
    382385        } elseif ( ! count_user_posts( $user->ID, $types ) && ! current_user_can( 'edit_user', $user->ID ) && ! current_user_can( 'list_users' ) ) {
    383386            return new WP_Error( 'rest_user_cannot_view', __( 'Sorry, you are not allowed to list users.' ), array( 'status' => rest_authorization_required_code() ) );
     
    880883        }
    881884
    882         if ( ! empty( $schema['properties']['roles'] ) ) {
     885        if ( ! empty( $schema['properties']['roles'] ) && ( current_user_can( 'list_users' ) || current_user_can( 'edit_user', $user->ID ) ) ) {
    883886            // Defensively call array_values() to ensure an array is returned.
    884887            $data['roles'] = array_values( $user->roles );
Note: See TracChangeset for help on using the changeset viewer.