WP_REST_Revisions_Controller example

function create_initial_rest_routes() {
    foreach ( get_post_types( array( 'show_in_rest' => true ), 'objects' ) as $post_type ) {
        $controller = $post_type->get_rest_controller();

        if ( ! $controller ) {
            continue;
        }

        $controller->register_routes();

        if ( post_type_supports( $post_type->name, 'revisions' ) ) {
            $revisions_controller = new WP_REST_Revisions_Controller( $post_type->name );
            $revisions_controller->register_routes();
        }

        if ( 'attachment' !== $post_type->name ) {
            $autosaves_controller = new WP_REST_Autosaves_Controller( $post_type->name );
            $autosaves_controller->register_routes();
        }
    }

    // Post types.     $controller = new WP_REST_Post_Types_Controller();
    

    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.