\rest_authorization_required_code() ) ); } /** * Check whether a request has read access to the collection. * * A trait method wins over an inherited one, so this overrides the core controller's check * and defers to it once the reader gate has passed. * * @since 9.3.0 * * @param \WP_REST_Request $request Full details about the request. * @return true|\WP_Error True if the request has read access, WP_Error otherwise. */ public function get_items_permissions_check( $request ) { $permission = $this->check_reader_capability(); if ( \is_wp_error( $permission ) ) { return $permission; } return parent::get_items_permissions_check( $request ); } /** * Check whether the current user may read the feed of the given actor(s). * * Users who can list users may read any actor's feed, everybody else is * limited to their own. * * @since 9.3.0 * * @param int|int[] $user_ids One or more local user IDs a record belongs to. * @return bool True if the current user may read it, false otherwise. */ protected function can_read_feed_of( $user_ids ) { /* * Same reason the login check leads in `check_reader_capability()`: a logged-out request * has user ID 0, and so does the blog actor, so the identity match below would hand the * blog actor's feed to anybody. This predicate is also reached from callers that never * pass through that gate, such as core's comments controller. */ if ( ! \is_user_logged_in() ) { return false; } // Blanket access: an actor with no relationship at all has nothing to check per target. if ( \current_user_can( 'list_users' ) ) { return true; } $user_ids = \array_map( 'intval', (array) $user_ids ); if ( \in_array( \get_current_user_id(), $user_ids, true ) ) { return true; } foreach ( $user_ids as $user_id ) { if ( \current_user_can( 'edit_user', $user_id ) ) { return true; } } return false; } }