public function get_items_permissions_check( $request ) {

		if ( ! empty( $request['post'] ) ) {
			foreach ( (array) $request['post'] as $post_id ) {
				$post = $this->get_post( $post_id );
				if ( ! empty( $post_id ) && $post && ! $this->check_read_post_permission( $post ) ) {
					return new WP_Error( 'rest_cannot_read_post', __( 'Sorry, you cannot read the post for this comment.' ), array( 'status' => rest_authorization_required_code() ) );
				} elseif ( 0 === $post_id && ! current_user_can( 'moderate_comments' ) ) {
					return new WP_Error( 'rest_cannot_read', __( 'Sorry, you cannot read comments without a post.' ), array( 'status' => rest_authorization_required_code() ) );
				}
			}
		}

		if ( ! empty( $request['context'] ) && 'edit' === $request['context'] && ! current_user_can( 'moderate_comments' ) ) {
			return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you cannot view comments with edit context.' ), array( 'status' => rest_authorization_required_code() ) );
		}

		if ( ! current_user_can( 'edit_posts' ) ) {
			$protected_params = array( 'author', 'author_exclude', 'karma', 'author_email', 'type', 'status' );
			$forbidden_params = array();
			foreach ( $protected_params as $param ) {
				if ( 'status' === $param ) {
					if ( 'approve' !== $request[ $param ] ) {
						$forbidden_params[] = $param;
					}
				} elseif ( 'type' === $param ) {
					if ( 'comment' !== $request[ $param ] ) {
						$forbidden_params[] = $param;
					}
				} elseif ( ! empty( $request[ $param ] ) ) {
					$forbidden_params[] = $param;
				}
			}
			if ( ! empty( $forbidden_params ) ) {
				return new WP_Error( 'rest_forbidden_param', sprintf( __( 'Query parameter not permitted: %s' ), implode( ', ', $forbidden_params ) ), array( 'status' => rest_authorization_required_code() ) );
			}
		}

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

		if ( ! empty( $request['post'] ) ) {
			foreach ( (array) $request['post'] as $post_id ) {
				$post = $this->get_post( $post_id );
				if ( ! empty( $post_id ) && $post && ! $this->check_read_post_permission( $post ) ) {
					return new WP_Error( 'rest_cannot_read_post', __( 'Sorry, you cannot read the post for this comment.' ), array( 'status' => rest_authorization_required_code() ) );
				} elseif ( 0 === $post_id && ! current_user_can( 'moderate_comments' ) ) {
					return new WP_Error( 'rest_cannot_read', __( 'Sorry, you cannot read comments without a post.' ), array( 'status' => rest_authorization_required_code() ) );
				}
			}
		}

		if ( ! empty( $request['context'] ) && 'edit' === $request['context'] && ! current_user_can( 'moderate_comments' ) ) {
			return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you cannot view comments with edit context.' ), array( 'status' => rest_authorization_required_code() ) );
		}

		if ( ! current_user_can( 'edit_posts' ) ) {
			$protected_params = array( 'author', 'author_exclude', 'karma', 'author_email', 'type', 'status' );
			$forbidden_params = array();
			foreach ( $protected_params as $param ) {
				if ( 'status' === $param ) {
					if ( 'approve' !== $request[ $param ] ) {
						$forbidden_params[] = $param;
					}
				} elseif ( 'type' === $param ) {
					if ( 'comment' !== $request[ $param ] ) {
						$forbidden_params[] = $param;
					}
				} elseif ( ! empty( $request[ $param ] ) ) {
					$forbidden_params[] = $param;
				}
			}
			if ( ! empty( $forbidden_params ) ) {
				return new WP_Error( 'rest_forbidden_param', sprintf( __( 'Query parameter not permitted: %s' ), implode( ', ', $forbidden_params ) ), array( 'status' => rest_authorization_required_code() ) );
			}
		}

		return true;
	}
public function get_items_permissions_check ( $ request ) { if ( ! empty ( $ request [ 'post' ] ) ) { foreach ( ( array ) $ request [ 'post' ] as $ post_id ) { $ post = $ this -> get_post ( $ post_id ) ; if ( ! empty ( $ post_id ) && $ post && ! $ this -> check_read_post_permission ( $ post ) ) { return new WP_Error ( 'rest_cannot_read_post' , __ ( 'Sorry, you cannot read the post for this comment.' ) , array ( 'status' => rest_authorization_required_code ( ) ) ) ; } elseif ( 0 === $ post_id && ! current_user_can ( 'moderate_comments' ) ) { return new WP_Error ( 'rest_cannot_read' , __ ( 'Sorry, you cannot read comments without a post.' ) , array ( 'status' => rest_authorization_required_code ( ) ) ) ; } } } if ( ! empty ( $ request [ 'context' ] ) && 'edit' === $ request [ 'context' ] && ! current_user_can ( 'moderate_comments' ) ) { return new WP_Error ( 'rest_forbidden_context' , __ ( 'Sorry, you cannot view comments with edit context.' ) , array ( 'status' => rest_authorization_required_code ( ) ) ) ; } if ( ! current_user_can ( 'edit_posts' ) ) { $ protected_params = array ( 'author' , 'author_exclude' , 'karma' , 'author_email' , 'type' , 'status' ) ; $ forbidden_params = array ( ) ; foreach ( $ protected_params as $ param ) { if ( 'status' === $ param ) { if ( 'approve' !== $ request [ $ param ] ) { $ forbidden_params [ ] = $ param ; } } elseif ( 'type' === $ param ) { if ( 'comment' !== $ request [ $ param ] ) { $ forbidden_params [ ] = $ param ; } } elseif ( ! empty ( $ request [ $ param ] ) ) { $ forbidden_params [ ] = $ param ; } } if ( ! empty ( $ forbidden_params ) ) { return new WP_Error ( 'rest_forbidden_param' , sprintf ( __ ( 'Query parameter not permitted: %s' ) , implode ( ', ' , $ forbidden_params ) ) , array ( 'status' => rest_authorization_required_code ( ) ) ) ; } } return true ; }
Check if a given request has access to read comments

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