| 1 |
<?php |
| 2 |
|
| 3 |
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong |
| 4 |
namespace Yoast\WP\SEO\Dashboard\Infrastructure\Taxonomies; |
| 5 |
|
| 6 |
use WP_Taxonomy; |
| 7 |
|
| 8 |
/** |
| 9 |
* Class that validates taxonomies. |
| 10 |
*/ |
| 11 |
class Taxonomy_Validator { |
| 12 |
|
| 13 |
/** |
| 14 |
* Returns whether the taxonomy in question is valid and associated with a given content type. |
| 15 |
* |
| 16 |
* @param WP_Taxonomy|false|null $taxonomy The taxonomy to check. |
| 17 |
* @param string $content_type The name of the content type to check. |
| 18 |
* |
| 19 |
* @return bool Whether the taxonomy in question is valid. |
| 20 |
*/ |
| 21 |
public function is_valid_taxonomy( $taxonomy, string $content_type ): bool { |
| 22 |
return \is_a( $taxonomy, 'WP_Taxonomy' ) |
| 23 |
&& $taxonomy->public |
| 24 |
&& $taxonomy->show_in_rest |
| 25 |
&& \in_array( $taxonomy->name, \get_object_taxonomies( $content_type ), true ); |
| 26 |
} |
| 27 |
} |
| 28 |
|