WP_REST_Posts_Controller example


    public function __construct( $parent_post_type ) {
        $this->parent_post_type = $parent_post_type;
        $post_type_object       = get_post_type_object( $parent_post_type );
        $parent_controller      = $post_type_object->get_rest_controller();

        if ( ! $parent_controller ) {
            $parent_controller = new WP_REST_Posts_Controller( $parent_post_type );
        }

        $this->parent_controller = $parent_controller;
        $this->rest_base         = 'revisions';
        $this->parent_base       = ! empty( $post_type_object->rest_base ) ? $post_type_object->rest_base : $post_type_object->name;
        $this->namespace         = ! empty( $post_type_object->rest_namespace ) ? $post_type_object->rest_namespace : 'wp/v2';
    }

    /** * Registers the routes for revisions based on post types supporting revisions. * * @since 4.7.0 * * @see register_rest_route() */
        if ( ! $post_type ) {
            return false;
        }

        $posts_controller = $post_type->get_rest_controller();

        /* * Ensure the posts controller is specifically a WP_REST_Posts_Controller instance * before using methods specific to that controller. */
        if ( ! $posts_controller instanceof WP_REST_Posts_Controller ) {
            $posts_controller = new WP_REST_Posts_Controller( $post->post_type );
        }

        $has_password_filter = false;

        // Only check password if a specific post was queried for or a single comment         $requested_post    = ! empty( $request['post'] ) && ( ! is_array( $request['post'] ) || 1 === count( $request['post'] ) );
        $requested_comment = ! empty( $request['id'] );
        if ( ( $requested_post || $requested_comment ) && $posts_controller->can_access_password_content( $post$request ) ) {
            add_filter( 'post_password_required', '__return_false' );

            $has_password_filter = true;
        }

    public function __construct( $parent_post_type ) {
        $this->parent_post_type = $parent_post_type;
        $post_type_object       = get_post_type_object( $parent_post_type );
        $parent_controller      = $post_type_object->get_rest_controller();

        if ( ! $parent_controller ) {
            $parent_controller = new WP_REST_Posts_Controller( $parent_post_type );
        }

        $this->parent_controller    = $parent_controller;
        $this->revisions_controller = new WP_REST_Revisions_Controller( $parent_post_type );
        $this->rest_base            = 'autosaves';
        $this->parent_base          = ! empty( $post_type_object->rest_base ) ? $post_type_object->rest_base : $post_type_object->name;
        $this->namespace            = ! empty( $post_type_object->rest_namespace ) ? $post_type_object->rest_namespace : 'wp/v2';
    }

    /** * Registers the routes for autosaves. * * @since 5.0.0 * * @see register_rest_route() */
Home | Imprint | This part of the site doesn't use cookies.