WP_Post_Type::get_autosave_rest_controller(): WP_REST_Controller|null

In this article

Gets the REST API autosave controller for this post type.

Description

Will only instantiate the controller class once per request.

Return

WP_REST_Controller|null The controller instance, or null if the post type is set not to show in rest.

Source

public function get_autosave_rest_controller() {
	if ( ! $this->show_in_rest ) {
		return null;
	}

	if ( 'attachment' === $this->name ) {
		return null;
	}

	$class = $this->autosave_rest_controller_class ? $this->autosave_rest_controller_class : WP_REST_Autosaves_Controller::class;

	if ( ! class_exists( $class ) ) {
		return null;
	}

	if ( ! is_subclass_of( $class, WP_REST_Controller::class ) ) {
		return null;
	}

	if ( ! $this->autosave_rest_controller ) {
		$this->autosave_rest_controller = new $class( $this->name );
	}

	if ( ! ( $this->autosave_rest_controller instanceof $class ) ) {
		return null;
	}

	return $this->autosave_rest_controller;
}

Changelog

VersionDescription
6.4.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.