public function get_item_permissions_check( $request ) {

		$id = (int) $request['id'];
		$user = get_userdata( $id );
		$types = get_post_types( array( 'show_in_rest' => true ), 'names' );

		if ( empty( $id ) || empty( $user->ID ) ) {
			return new WP_Error( 'rest_user_invalid_id', __( 'Invalid resource id.' ), array( 'status' => 404 ) );
		}

		if ( get_current_user_id() === $id ) {
			return true;
		}

		if ( 'edit' === $request['context'] && ! current_user_can( 'list_users' ) ) {
			return new WP_Error( 'rest_user_cannot_view', __( 'Sorry, you cannot view this resource with edit context.' ), array( 'status' => rest_authorization_required_code() ) );
		} elseif ( ! count_user_posts( $id, $types ) && ! current_user_can( 'edit_user', $id ) && ! current_user_can( 'list_users' ) ) {
			return new WP_Error( 'rest_user_cannot_view', __( 'Sorry, you cannot view this resource.' ), array( 'status' => rest_authorization_required_code() ) );
		}

		return true;
	}
public function get_item_permissions_check( $request ) {

		$id = (int) $request['id'];
		$user = get_userdata( $id );
		$types = get_post_types( array( 'show_in_rest' => true ), 'names' );

		if ( empty( $id ) || empty( $user->ID ) ) {
			return new WP_Error( 'rest_user_invalid_id', __( 'Invalid resource id.' ), array( 'status' => 404 ) );
		}

		if ( get_current_user_id() === $id ) {
			return true;
		}

		if ( 'edit' === $request['context'] && ! current_user_can( 'list_users' ) ) {
			return new WP_Error( 'rest_user_cannot_view', __( 'Sorry, you cannot view this resource with edit context.' ), array( 'status' => rest_authorization_required_code() ) );
		} elseif ( ! count_user_posts( $id, $types ) && ! current_user_can( 'edit_user', $id ) && ! current_user_can( 'list_users' ) ) {
			return new WP_Error( 'rest_user_cannot_view', __( 'Sorry, you cannot view this resource.' ), array( 'status' => rest_authorization_required_code() ) );
		}

		return true;
	}
public function get_item_permissions_check ( $ request ) { $ id = ( int ) $ request [ 'id' ] ; $ user = get_userdata ( $ id ) ; $ types = get_post_types ( array ( 'show_in_rest' => true ) , 'names' ) ; if ( empty ( $ id ) || empty ( $ user -> ID ) ) { return new WP_Error ( 'rest_user_invalid_id' , __ ( 'Invalid resource id.' ) , array ( 'status' => 404 ) ) ; } if ( get_current_user_id ( ) === $ id ) { return true ; } if ( 'edit' === $ request [ 'context' ] && ! current_user_can ( 'list_users' ) ) { return new WP_Error ( 'rest_user_cannot_view' , __ ( 'Sorry, you cannot view this resource with edit context.' ) , array ( 'status' => rest_authorization_required_code ( ) ) ) ; } elseif ( ! count_user_posts ( $ id , $ types ) && ! current_user_can ( 'edit_user' , $ id ) && ! current_user_can ( 'list_users' ) ) { return new WP_Error ( 'rest_user_cannot_view' , __ ( 'Sorry, you cannot view this resource.' ) , array ( 'status' => rest_authorization_required_code ( ) ) ) ; } return true ; }
Check if a given request has access to read a user

@param  WP_REST_Request $request Full details about the request.
@return WP_Error|boolean
Check if a given request has access to read a user