Make WordPress Core


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

Grouped backports for the 4.7 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.7 branch.

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

Location:
branches/4.7
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.7

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

    r56862 r60839  
    184184
    185185        if ( 'edit' === $request['context'] && ! current_user_can( 'list_users' ) ) {
    186             return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to list users.' ), array( 'status' => rest_authorization_required_code() ) );
     186            return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to edit users.' ), array( 'status' => rest_authorization_required_code() ) );
    187187        }
    188188
     
    282282
    283283        foreach ( $query->results as $user ) {
     284            if ( 'edit' === $request['context'] && ! current_user_can( 'edit_user', $user->ID ) ) {
     285                continue;
     286            }
    284287            $data = $this->prepare_item_for_response( $user, $request );
    285288            $users[] = $this->prepare_response_for_collection( $data );
     
    377380        }
    378381
    379         if ( 'edit' === $request['context'] && ! current_user_can( 'list_users' ) ) {
    380             return new WP_Error( 'rest_user_cannot_view', __( 'Sorry, you are not allowed to list users.' ), array( 'status' => rest_authorization_required_code() ) );
    381         } elseif ( ! count_user_posts( $user->ID, $types ) && ! current_user_can( 'edit_user', $user->ID ) && ! current_user_can( 'list_users' ) ) {
     382        if ( 'edit' === $request['context'] && ! current_user_can( 'edit_user', $user->ID ) ) {
     383            return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to edit this user.' ), array( 'status' => rest_authorization_required_code() ) );
     384        }
     385
     386        if ( ! current_user_can( 'edit_user', $user->ID ) && ! current_user_can( 'list_users' ) && ! count_user_posts( $user->ID, $types ) ) {
    382387            return new WP_Error( 'rest_user_cannot_view', __( 'Sorry, you are not allowed to list users.' ), array( 'status' => rest_authorization_required_code() ) );
    383388        }
     
    879884        }
    880885
    881         if ( ! empty( $schema['properties']['roles'] ) ) {
     886        if ( ! empty( $schema['properties']['roles'] ) && ( current_user_can( 'list_users' ) || current_user_can( 'edit_user', $user->ID ) ) ) {
    882887            // Defensively call array_values() to ensure an array is returned.
    883888            $data['roles'] = array_values( $user->roles );
Note: See TracChangeset for help on using the changeset viewer.