WP_Post_Type::get_rest_controller() public WP 5.3.0
Gets the REST API controller for this post type.
Will only instantiate the controller class once per request.
{} It's a method of the class: WP_Post_Type{}
No Hooks.
Return
WP_REST_Controller|null
. The controller instance, or null if the post type is set not to show in rest.
Usage
$WP_Post_Type = new WP_Post_Type(); $WP_Post_Type->get_rest_controller();
Changelog
Since 5.3.0 | Introduced. |
Code of WP_Post_Type::get_rest_controller() WP Post Type::get rest controller WP 5.7
public function get_rest_controller() {
if ( ! $this->show_in_rest ) {
return null;
}
$class = $this->rest_controller_class ? $this->rest_controller_class : WP_REST_Posts_Controller::class;
if ( ! class_exists( $class ) ) {
return null;
}
if ( ! is_subclass_of( $class, WP_REST_Controller::class ) ) {
return null;
}
if ( ! $this->rest_controller ) {
$this->rest_controller = new $class( $this->name );
}
if ( ! ( $this->rest_controller instanceof $class ) ) {
return null;
}
return $this->rest_controller;
}