PluginProbe ʕ •ᴥ•ʔ
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 27.7
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v27.7
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 19.1 19.10 19.11 19.12 19.13 19.14 19.2 19.3 19.4 19.5 19.5.1 19.6 19.6.1 19.7 19.7.1 19.7.2 19.8 19.9 20.0 20.1 20.10 20.11 20.12 20.13 20.2 20.2.1 20.3 20.4 20.5 20.6 20.7 20.8 20.9 21.0 21.1 21.2 21.3 21.4 21.5 21.6 21.7 21.8 21.8.1 21.9 21.9.1 22.0 22.1 22.2 22.3 22.4 22.5 22.6 22.7 22.8 22.9 23.0 23.1 23.2 23.3 23.4 23.5 23.6 23.7 23.8 23.9 24.0 24.1 24.2 24.3 24.4 24.5 24.6 24.7 24.8 24.8.1 24.9 25.0 25.1 25.2 25.3 25.3.1 25.4 25.5 25.6 25.7 25.8 25.9 26.0 26.1 26.1.1 26.2 26.3 26.4 26.5 26.6 26.7 26.8 26.9 27.0 27.1 27.1.1 27.2 27.3 27.4
wordpress-seo / src / integrations / watchers / indexable-term-watcher.php
wordpress-seo / src / integrations / watchers Last commit date
addon-update-watcher.php 3 months ago auto-update-watcher.php 2 years ago indexable-ancestor-watcher.php 3 months ago indexable-attachment-watcher.php 1 year ago indexable-author-archive-watcher.php 3 months ago indexable-author-watcher.php 1 year ago indexable-category-permalink-watcher.php 2 years ago indexable-date-archive-watcher.php 2 years ago indexable-home-page-watcher.php 1 year ago indexable-homeurl-watcher.php 5 years ago indexable-permalink-watcher.php 2 years ago indexable-post-meta-watcher.php 2 years ago indexable-post-type-archive-watcher.php 1 year ago indexable-post-type-change-watcher.php 1 year ago indexable-post-watcher.php 3 months ago indexable-static-home-page-watcher.php 2 years ago indexable-system-page-watcher.php 2 years ago indexable-taxonomy-change-watcher.php 1 year ago indexable-term-watcher.php 1 year ago option-titles-watcher.php 3 months ago option-wpseo-watcher.php 1 year ago primary-category-quick-edit-watcher.php 2 years ago primary-term-watcher.php 1 year ago search-engines-discouraged-watcher.php 3 months ago woocommerce-beta-editor-watcher.php 3 months ago
indexable-term-watcher.php
153 lines
1 <?php
2
3 namespace Yoast\WP\SEO\Integrations\Watchers;
4
5 use Yoast\WP\SEO\Builders\Indexable_Builder;
6 use Yoast\WP\SEO\Builders\Indexable_Link_Builder;
7 use Yoast\WP\SEO\Conditionals\Migrations_Conditional;
8 use Yoast\WP\SEO\Helpers\Indexable_Helper;
9 use Yoast\WP\SEO\Helpers\Site_Helper;
10 use Yoast\WP\SEO\Integrations\Integration_Interface;
11 use Yoast\WP\SEO\Repositories\Indexable_Repository;
12
13 /**
14 * Watches Terms/Taxonomies to fill the related Indexable.
15 */
16 class Indexable_Term_Watcher implements Integration_Interface {
17
18 /**
19 * The indexable repository.
20 *
21 * @var Indexable_Repository
22 */
23 protected $repository;
24
25 /**
26 * The indexable builder.
27 *
28 * @var Indexable_Builder
29 */
30 protected $builder;
31
32 /**
33 * The link builder.
34 *
35 * @var Indexable_Link_Builder
36 */
37 protected $link_builder;
38
39 /**
40 * The indexable helper.
41 *
42 * @var Indexable_Helper
43 */
44 private $indexable_helper;
45
46 /**
47 * Represents the site helper.
48 *
49 * @var Site_Helper
50 */
51 protected $site;
52
53 /**
54 * Returns the conditionals based on which this loadable should be active.
55 *
56 * @return array
57 */
58 public static function get_conditionals() {
59 return [ Migrations_Conditional::class ];
60 }
61
62 /**
63 * Indexable_Term_Watcher constructor.
64 *
65 * @param Indexable_Repository $repository The repository to use.
66 * @param Indexable_Builder $builder The post builder to use.
67 * @param Indexable_Link_Builder $link_builder The lint builder to use.
68 * @param Indexable_Helper $indexable_helper The indexable helper.
69 * @param Site_Helper $site The site helper.
70 */
71 public function __construct(
72 Indexable_Repository $repository,
73 Indexable_Builder $builder,
74 Indexable_Link_Builder $link_builder,
75 Indexable_Helper $indexable_helper,
76 Site_Helper $site
77 ) {
78 $this->repository = $repository;
79 $this->builder = $builder;
80 $this->link_builder = $link_builder;
81 $this->indexable_helper = $indexable_helper;
82 $this->site = $site;
83 }
84
85 /**
86 * Registers the hooks.
87 *
88 * @return void
89 */
90 public function register_hooks() {
91 \add_action( 'created_term', [ $this, 'build_indexable' ], \PHP_INT_MAX );
92 \add_action( 'edited_term', [ $this, 'build_indexable' ], \PHP_INT_MAX );
93 \add_action( 'delete_term', [ $this, 'delete_indexable' ], \PHP_INT_MAX );
94 }
95
96 /**
97 * Deletes a term from the index.
98 *
99 * @param int $term_id The Term ID to delete.
100 *
101 * @return void
102 */
103 public function delete_indexable( $term_id ) {
104 $indexable = $this->repository->find_by_id_and_type( $term_id, 'term', false );
105
106 if ( ! $indexable ) {
107 return;
108 }
109
110 $indexable->delete();
111 \do_action( 'wpseo_indexable_deleted', $indexable );
112 }
113
114 /**
115 * Update the taxonomy meta data on save.
116 *
117 * @param int $term_id ID of the term to save data for.
118 *
119 * @return void
120 */
121 public function build_indexable( $term_id ) {
122 // Bail if this is a multisite installation and the site has been switched.
123 if ( $this->site->is_multisite_and_switched() ) {
124 return;
125 }
126
127 $term = \get_term( $term_id );
128
129 if ( $term === null || \is_wp_error( $term ) ) {
130 return;
131 }
132
133 if ( ! \is_taxonomy_viewable( $term->taxonomy ) ) {
134 return;
135 }
136
137 $indexable = $this->repository->find_by_id_and_type( $term_id, 'term', false );
138
139 // If we haven't found an existing indexable, create it. Otherwise update it.
140 $indexable = $this->builder->build_for_id_and_type( $term_id, 'term', $indexable );
141
142 if ( ! $indexable ) {
143 return;
144 }
145
146 // Update links.
147 $this->link_builder->build( $indexable, $term->description );
148
149 $indexable->object_last_modified = \max( $indexable->object_last_modified, \current_time( 'mysql' ) );
150 $this->indexable_helper->save_indexable( $indexable );
151 }
152 }
153