WP_Taxonomy::get_rest_controller() WordPress Method

The WP_Taxonomy::get_rest_controller() method returns a WP_REST_Controller instance for a given taxonomy.

WP_Taxonomy::get_rest_controller() #

Gets the REST API controller for this taxonomy.


Description

Will only instantiate the controller class once per request.


Top ↑

Return

(WP_REST_Controller|null) The controller instance, or null if the taxonomy is set not to show in rest.


Top ↑

Source

File: wp-includes/class-wp-taxonomy.php

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

		$class = $this->rest_controller_class ? $this->rest_controller_class : WP_REST_Terms_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;
	}

Top ↑

Changelog

Changelog
VersionDescription
5.5.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.