Make WordPress Core


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

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

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

Location:
branches/5.1
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/5.1

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

    r56873 r60835  
    192192
    193193                if ( 'edit' === $request['context'] && ! current_user_can( 'list_users' ) ) {
    194                         return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to list users.' ), array( 'status' => rest_authorization_required_code() ) );
     194                        return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to edit users.' ), array( 'status' => rest_authorization_required_code() ) );
    195195                }
    196196
     
    306306
    307307                foreach ( $query->results as $user ) {
     308                        if ( 'edit' === $request['context'] && ! current_user_can( 'edit_user', $user->ID ) ) {
     309                                continue;
     310                        }
     311
    308312                        $data    = $this->prepare_item_for_response( $user, $request );
    309313                        $users[] = $this->prepare_response_for_collection( $data );
     
    400404                }
    401405
    402                 if ( 'edit' === $request['context'] && ! current_user_can( 'list_users' ) ) {
    403                         return new WP_Error( 'rest_user_cannot_view', __( 'Sorry, you are not allowed to list users.' ), array( 'status' => rest_authorization_required_code() ) );
    404                 } elseif ( ! count_user_posts( $user->ID, $types ) && ! current_user_can( 'edit_user', $user->ID ) && ! current_user_can( 'list_users' ) ) {
     406                if ( 'edit' === $request['context'] && ! current_user_can( 'edit_user', $user->ID ) ) {
     407                        return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to edit this user.' ), array( 'status' => rest_authorization_required_code() ) );
     408                }
     409
     410                if ( ! current_user_can( 'edit_user', $user->ID ) && ! current_user_can( 'list_users' ) && ! count_user_posts( $user->ID, $types ) ) {
    405411                        return new WP_Error( 'rest_user_cannot_view', __( 'Sorry, you are not allowed to list users.' ), array( 'status' => rest_authorization_required_code() ) );
    406412                }
     
    923929                }
    924930
    925                 if ( in_array( 'roles', $fields, true ) ) {
     931                if ( in_array( 'roles', $fields, true ) && ( current_user_can( 'list_users' ) || current_user_can( 'edit_user', $user->ID ) ) ) {
    926932                        // Defensively call array_values() to ensure an array is returned.
    927933                        $data['roles'] = array_values( $user->roles );
Note: See TracChangeset for help on using the changeset viewer.