get_rest_controller example


    protected function check_read_post_permission( $post$request ) {
        $post_type = get_post_type_object( $post->post_type );

        // Return false if custom post type doesn't exist         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;

        
add_filter( 'rest_pre_dispatch', 'rest_handle_options_request', 10, 3 );
    add_filter( 'rest_index', 'rest_add_application_passwords_to_index' );
}

/** * Registers default REST API routes. * * @since 4.7.0 */
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();
        }

        
/** * Constructor. * * @since 5.0.0 * * @param string $parent_post_type Post type of the parent. */
    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';
    }

    
/** * Constructor. * * @since 4.7.0 * * @param string $parent_post_type Post type of the parent. */
    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';
    }

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