PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 28.6
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v28.6
28.6 28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 All 130 releases
wordpress-seo / src / dashboard / application / taxonomies / taxonomies-repository.php

taxonomies-repository.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 28.6, at src/dashboard/application/taxonomies/taxonomies-repository.php

67 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong
4 namespace Yoast\WP\SEO\Dashboard\Application\Taxonomies;
5
6 use Yoast\WP\SEO\Dashboard\Application\Filter_Pairs\Filter_Pairs_Repository;
7 use Yoast\WP\SEO\Dashboard\Domain\Taxonomies\Taxonomy;
8 use Yoast\WP\SEO\Dashboard\Infrastructure\Taxonomies\Taxonomies_Collector;
9
10 /**
11 * The repository to get taxonomies.
12 */
13 class Taxonomies_Repository {
14
15 /**
16 * The taxonomies collector.
17 *
18 * @var Taxonomies_Collector
19 */
20 private $taxonomies_collector;
21
22 /**
23 * The filter pairs repository.
24 *
25 * @var Filter_Pairs_Repository
26 */
27 private $filter_pairs_repository;
28
29 /**
30 * The constructor.
31 *
32 * @param Taxonomies_Collector $taxonomies_collector The taxonomies collector.
33 * @param Filter_Pairs_Repository $filter_pairs_repository The filter pairs repository.
34 */
35 public function __construct(
36 Taxonomies_Collector $taxonomies_collector,
37 Filter_Pairs_Repository $filter_pairs_repository
38 ) {
39 $this->taxonomies_collector = $taxonomies_collector;
40 $this->filter_pairs_repository = $filter_pairs_repository;
41 }
42
43 /**
44 * Returns the object of the filtering taxonomy of a content type.
45 *
46 * @param string $content_type The content type that the taxonomy filters.
47 *
48 * @return Taxonomy|null The filtering taxonomy of the content type.
49 */
50 public function get_content_type_taxonomy( string $content_type ) {
51 // First we check if there's a filter that overrides the filtering taxonomy for this content type.
52 $taxonomy = $this->taxonomies_collector->get_custom_filtering_taxonomy( $content_type );
53 if ( $taxonomy ) {
54 return $taxonomy;
55 }
56
57 // Then we check if there is a filter explicitly made for this content type.
58 $taxonomy = $this->filter_pairs_repository->get_taxonomy( $content_type );
59 if ( $taxonomy ) {
60 return $taxonomy;
61 }
62
63 // If everything else returned empty, we can always try the fallback taxonomy.
64 return $this->taxonomies_collector->get_fallback_taxonomy( $content_type );
65 }
66 }
67