check_read_post_permission example


    public function get_items_permissions_check( $request ) {

        if ( ! empty( $request['post'] ) ) {
            foreach ( (array) $request['post'] as $post_id ) {
                $post = get_post( $post_id );

                if ( ! empty( $post_id ) && $post && ! $this->check_read_post_permission( $post$request ) ) {
                    return new WP_Error(
                        'rest_cannot_read_post',
                        __( 'Sorry, you are not allowed to 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 are not allowed to read comments without a post.' ),
                        array( 'status' => rest_authorization_required_code() )
                    );
                }
Home | Imprint | This part of the site doesn't use cookies.