ACF_Rest_Request::set_object_types()privateACF 1.0

Determine the object type and sub type from the requested route. We need to know both the underlying WordPress object type as well as post type or taxonomy in order to provide the right context when getting/updating fields.

Метод класса: ACF_Rest_Request{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

// private - только в коде основоного (родительского) класса
$result = $this->set_object_types();

Код ACF_Rest_Request::set_object_types() ACF 6.0.4

private function set_object_types() {
	$base       = $this->get_url_param( 'rest_base' );
	$child_base = $this->get_url_param( 'child_rest_base' );

	// We need a matched rest base to proceed here. If we haven't matched one while parsing the request, bail.
	if ( is_null( $base ) ) {
		return;
	}

	// Determine the matching object type from the rest base. Start with users as that is simple. From there,
	// check post types then check taxonomies if a matching post type cannot be found.
	if ( $base === 'users' ) {
		$this->object_type = $this->object_sub_type = 'user';
	} elseif ( $base === 'comments' ) {
		$this->object_type = $this->object_sub_type = 'comment';
	} elseif ( $post_type = $this->get_post_type_by_rest_base( $base ) ) {
		$this->object_type     = 'post';
		$this->object_sub_type = $post_type->name;

		// Autosaves and revisions are mostly handled the same by WP, and share the same schema.
		if ( in_array( $this->get_url_param( 'child_rest_base' ), array( 'revisions', 'autosaves' ) ) ) {
			$this->child_object_type = $this->object_sub_type . '-revision';
		}
	} elseif ( $taxonomy = $this->get_taxonomy_by_rest_base( $base ) ) {
		$this->object_type     = 'term';
		$this->object_sub_type = $taxonomy->name;
	}
}