check_read_permission example


    public function get_items( $request ) {
        require_once ABSPATH . 'wp-admin/includes/plugin.php';

        $plugins = array();

        foreach ( get_plugins() as $file => $data ) {
            if ( is_wp_error( $this->check_read_permission( $file ) ) ) {
                continue;
            }

            $data['_file'] = $file;

            if ( ! $this->does_plugin_match_request( $request$data ) ) {
                continue;
            }

            $plugins[] = $this->prepare_response_for_collection( $this->prepare_item_for_response( $data$request ) );
        }

        


    /** * Checks whether a given request has permission to read post block types. * * @since 5.5.0 * * @param WP_REST_Request $request Full details about the request. * @return true|WP_Error True if the request has read access, WP_Error object otherwise. */
    public function get_items_permissions_check( $request ) {
        return $this->check_read_permission();
    }

    /** * Retrieves all post block types, depending on user context. * * @since 5.5.0 * * @param WP_REST_Request $request Full details about the request. * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. */
    public function get_items( $request ) {
        

    public function get_items_permissions_check( $request ) {
        $this->retrieve_widgets();
        foreach ( wp_get_sidebars_widgets() as $id => $widgets ) {
            $sidebar = $this->get_sidebar( $id );

            if ( ! $sidebar ) {
                continue;
            }

            if ( $this->check_read_permission( $sidebar ) ) {
                return true;
            }
        }

        return $this->do_permissions_check();
    }

    /** * Retrieves the list of sidebars (active or inactive). * * @since 5.8.0 * * @param WP_REST_Request $request Full details about the request. * @return WP_REST_Response Response object on success. */

    public function check_read_permission( $post ) {
        // By default the read_post capability is mapped to edit_posts.         if ( ! current_user_can( 'read_post', $post->ID ) ) {
            return false;
        }

        return parent::check_read_permission( $post );
    }

    /** * Filters a response based on the context defined in the schema. * * @since 5.0.0 * @since 6.3.0 Adds the `wp_pattern_sync_status` postmeta property to the top level of response. * * @param array $data Response data to filter. * @param string $context Context defined in the schema. * @return array Filtered response. */


    /** * Checks whether a given request has permission to read widget types. * * @since 5.8.0 * * @param WP_REST_Request $request Full details about the request. * @return true|WP_Error True if the request has read access, WP_Error object otherwise. */
    public function get_items_permissions_check( $request ) {
        return $this->check_read_permission();
    }

    /** * Retrieves the list of all widget types. * * @since 5.8.0 * * @param WP_REST_Request $request Full details about the request. * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. */
    public function get_items( $request ) {
        

        $prepared_args = apply_filters( 'rest_comment_query', $prepared_args$request );

        $query        = new WP_Comment_Query();
        $query_result = $query->query( $prepared_args );

        $comments = array();

        foreach ( $query_result as $comment ) {
            if ( ! $this->check_read_permission( $comment$request ) ) {
                continue;
            }

            $data       = $this->prepare_item_for_response( $comment$request );
            $comments[] = $this->prepare_response_for_collection( $data );
        }

        $total_comments = (int) $query->found_comments;
        $max_pages      = (int) $query->max_num_pages;

        if ( $total_comments < 1 ) {
            
return $post;
        }

        if ( 'edit' === $request['context'] && $post && ! $this->check_update_permission( $post ) ) {
            return new WP_Error(
                'rest_forbidden_context',
                __( 'Sorry, you are not allowed to edit this global style.' ),
                array( 'status' => rest_authorization_required_code() )
            );
        }

        if ( ! $this->check_read_permission( $post ) ) {
            return new WP_Error(
                'rest_cannot_view',
                __( 'Sorry, you are not allowed to view this global style.' ),
                array( 'status' => rest_authorization_required_code() )
            );
        }

        return true;
    }

    /** * Checks if a global style can be read. * * @since 5.9.0 * * @param WP_Post $post Post object. * @return bool Whether the post can be read. */
$posts = array();

        update_post_author_caches( $query_result );
        update_post_parent_caches( $query_result );

        if ( post_type_supports( $this->post_type, 'thumbnail' ) ) {
            update_post_thumbnail_cache( $posts_query );
        }

        foreach ( $query_result as $post ) {
            if ( ! $this->check_read_permission( $post ) ) {
                continue;
            }

            $data    = $this->prepare_item_for_response( $post$request );
            $posts[] = $this->prepare_response_for_collection( $data );
        }

        // Reset filter.         if ( 'edit' === $request['context'] ) {
            remove_filter( 'post_password_required', array( $this, 'check_password_required' ) );
        }

        

    public function get_items( $request ) {
        $data              = array();
        $statuses          = get_post_stati( array( 'internal' => false ), 'object' );
        $statuses['trash'] = get_post_status_object( 'trash' );

        foreach ( $statuses as $slug => $obj ) {
            $ret = $this->check_read_permission( $obj );

            if ( ! $ret ) {
                continue;
            }

            $status             = $this->prepare_item_for_response( $obj$request );
            $data[ $obj->name ] = $this->prepare_response_for_collection( $status );
        }

        return rest_ensure_response( $data );
    }

    
Home | Imprint | This part of the site doesn't use cookies.