Make WordPress Core


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

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

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

Location:
branches/4.9
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.9

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

    r56865 r60837  
    180180
    181181        if ( 'edit' === $request['context'] && ! current_user_can( 'list_users' ) ) {
    182             return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to list users.' ), array( 'status' => rest_authorization_required_code() ) );
     182            return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to edit users.' ), array( 'status' => rest_authorization_required_code() ) );
    183183        }
    184184
     
    294294
    295295        foreach ( $query->results as $user ) {
     296            if ( 'edit' === $request['context'] && ! current_user_can( 'edit_user', $user->ID ) ) {
     297                continue;
     298            }
     299
    296300            $data = $this->prepare_item_for_response( $user, $request );
    297301            $users[] = $this->prepare_response_for_collection( $data );
     
    388392        }
    389393
    390         if ( 'edit' === $request['context'] && ! current_user_can( 'list_users' ) ) {
    391             return new WP_Error( 'rest_user_cannot_view', __( 'Sorry, you are not allowed to list users.' ), array( 'status' => rest_authorization_required_code() ) );
    392         } elseif ( ! count_user_posts( $user->ID, $types ) && ! current_user_can( 'edit_user', $user->ID ) && ! current_user_can( 'list_users' ) ) {
     394        if ( 'edit' === $request['context'] && ! current_user_can( 'edit_user', $user->ID ) ) {
     395            return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to edit this user.' ), array( 'status' => rest_authorization_required_code() ) );
     396        }
     397
     398        if ( ! current_user_can( 'edit_user', $user->ID ) && ! current_user_can( 'list_users' ) && ! count_user_posts( $user->ID, $types ) ) {
    393399            return new WP_Error( 'rest_user_cannot_view', __( 'Sorry, you are not allowed to list users.' ), array( 'status' => rest_authorization_required_code() ) );
    394400        }
     
    891897        }
    892898
    893         if ( in_array( 'roles', $fields, true ) ) {
     899        if ( in_array( 'roles', $fields, true ) && ( current_user_can( 'list_users' ) || current_user_can( 'edit_user', $user->ID ) ) ) {
    894900            // Defensively call array_values() to ensure an array is returned.
    895901            $data['roles'] = array_values( $user->roles );
Note: See TracChangeset for help on using the changeset viewer.