Yoast\WP\SEO\Dashboard\User_Interface\Scores

Abstract_Scores_Route::get_validated_term_id()protectedYoast 1.0

Gets the term ID validated against the given taxonomy.

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

Хуков нет.

Возвращает

true|false. The validated term ID.

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->get_validated_term_id( ?int $term_id, ?Taxonomy $taxonomy ): ?int;
?int $term_id (обязательный)
-
?Taxonomy $taxonomy (обязательный)
-

Код Abstract_Scores_Route::get_validated_term_id() Yoast 24.4

protected function get_validated_term_id( ?int $term_id, ?Taxonomy $taxonomy ): ?int {
	if ( $term_id !== null && $taxonomy === null ) {
		throw new Exception( 'Term needs a provided taxonomy.', 400 );
	}

	if ( $term_id === null && $taxonomy !== null ) {
		throw new Exception( 'Taxonomy needs a provided term.', 400 );
	}

	if ( $term_id !== null ) {
		$term = \get_term( $term_id );
		if ( ! $term || \is_wp_error( $term ) ) {
			throw new Exception( 'Invalid term.', 400 );
		}

		if ( $taxonomy !== null && $term->taxonomy !== $taxonomy->get_name() ) {
			throw new Exception( 'Invalid term.', 400 );
		}
	}

	return $term_id;
}