PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 28.5
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v28.5
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 19.0 All 129 releases
← All changes | src/builders/indexable-hierarchy-builder.php +21 -5 18.2 → 28.5 View file →
@@ -4,8 +4,9 @@
4 4
5 5 use WP_Post;
6 6 use WP_Term;
7 7 use WPSEO_Meta;
8 +use Yoast\WP\SEO\Helpers\Indexable_Helper;
8 9 use Yoast\WP\SEO\Helpers\Options_Helper;
9 10 use Yoast\WP\SEO\Helpers\Post_Helper;
10 11 use Yoast\WP\SEO\Models\Indexable;
11 12 use Yoast\WP\SEO\Repositories\Indexable_Hierarchy_Repository;
@@ -19,11 +20,11 @@
19 20 */
20 21 class Indexable_Hierarchy_Builder {
21 22
22 23 /**
23 - * Holds a list of indexables where the ancestors are saved for.
24 + * Holds a list of indexable ids where the ancestors are saved for.
24 25 *
25 - * @var array
26 + * @var array<int>
26 27 */
27 28 protected $saved_ancestors = [];
28 29
29 30 /**
@@ -61,8 +62,15 @@
61 62 */
62 63 private $post;
63 64
64 65 /**
66 + * Holds the Indexable_Helper instance.
67 + *
68 + * @var Indexable_Helper
69 + */
70 + private $indexable_helper;
71 +
72 + /**
65 73 * Indexable_Author_Builder constructor.
66 74 *
67 75 * @param Indexable_Hierarchy_Repository $indexable_hierarchy_repository The indexable hierarchy repository.
68 76 * @param Primary_Term_Repository $primary_term_repository The primary term repository.
@@ -67,19 +75,22 @@
67 75 * @param Indexable_Hierarchy_Repository $indexable_hierarchy_repository The indexable hierarchy repository.
68 76 * @param Primary_Term_Repository $primary_term_repository The primary term repository.
69 77 * @param Options_Helper $options The options helper.
70 78 * @param Post_Helper $post The post helper.
79 + * @param Indexable_Helper $indexable_helper The indexable helper.
71 80 */
72 81 public function __construct(
73 82 Indexable_Hierarchy_Repository $indexable_hierarchy_repository,
74 83 Primary_Term_Repository $primary_term_repository,
75 84 Options_Helper $options,
76 - Post_Helper $post
85 + Post_Helper $post,
86 + Indexable_Helper $indexable_helper
77 87 ) {
78 88 $this->indexable_hierarchy_repository = $indexable_hierarchy_repository;
79 89 $this->primary_term_repository = $primary_term_repository;
80 90 $this->options = $options;
81 91 $this->post = $post;
92 + $this->indexable_helper = $indexable_helper;
82 93 }
83 94
84 95 /**
85 96 * Sets the indexable repository. Done to avoid circular dependencies.
@@ -86,8 +97,10 @@
86 97 *
87 98 * @required
88 99 *
89 100 * @param Indexable_Repository $indexable_repository The indexable repository.
101 + *
102 + * @return void
90 103 */
91 104 public function set_indexable_repository( Indexable_Repository $indexable_repository ) {
92 105 $this->indexable_repository = $indexable_repository;
93 106 }
@@ -103,10 +116,13 @@
103 116 if ( $this->hierarchy_is_built( $indexable ) ) {
104 117 return $indexable;
105 118 }
106 119
120 + if ( ! $this->indexable_helper->should_index_indexable( $indexable ) ) {
121 + return $indexable;
122 + }
123 +
107 124 $this->indexable_hierarchy_repository->clear_ancestors( $indexable->id );
108 -
109 125 $indexable_id = $this->get_indexable_id( $indexable );
110 126 $ancestors = [];
111 127 if ( $indexable->object_type === 'post' ) {
112 128 $this->add_ancestors_for_post( $indexable_id, $indexable->object_id, $ancestors );
@@ -262,9 +278,9 @@
262 278
263 279 /**
264 280 * Find the deepest term in an array of term objects.
265 281 *
266 - * @param array $terms Terms set.
282 + * @param array<WP_Term> $terms Terms set.
267 283 *
268 284 * @return int The deepest term ID.
269 285 */
270 286 private function find_deepest_term_id( $terms ) {