PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 18.2
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v18.2
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
wordpress-seo / src / integrations / watchers / indexable-category-permalink-watcher.php

indexable-category-permalink-watcher.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 18.2, at src/integrations/watchers/indexable-category-permalink-watcher.php

54 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Yoast\WP\SEO\Integrations\Watchers;
4
5 use Yoast\WP\SEO\Config\Indexing_Reasons;
6
7 /**
8 * Watches the stripcategorybase key in wpseo_titles, in order to clear the permalink of the category indexables.
9 */
10 class Indexable_Category_Permalink_Watcher extends Indexable_Permalink_Watcher {
11
12 /**
13 * Initializes the integration.
14 *
15 * This is the place to register hooks and filters.
16 *
17 * @return void
18 */
19 public function register_hooks() {
20 \add_action( 'update_option_wpseo_titles', [ $this, 'check_option' ], 10, 2 );
21 }
22
23 /**
24 * Checks if the stripcategorybase key in wpseo_titles has a change in value, and if so,
25 * clears the permalink for category indexables.
26 *
27 * @param array $old_value The old value of the wpseo_titles option.
28 * @param array $new_value The new value of the wpseo_titles option.
29 *
30 * @return void
31 */
32 public function check_option( $old_value, $new_value ) {
33 // If this is the first time saving the option, in which case its value would be false.
34 if ( $old_value === false ) {
35 $old_value = [];
36 }
37
38 // If either value is not an array, return.
39 if ( ! \is_array( $old_value ) || ! \is_array( $new_value ) ) {
40 return;
41 }
42
43 // If both values aren't set, they haven't changed.
44 if ( ! isset( $old_value['stripcategorybase'] ) && ! isset( $new_value['stripcategorybase'] ) ) {
45 return;
46 }
47
48 // If a new value has been set for 'stripcategorybase', clear the category permalinks.
49 if ( $old_value['stripcategorybase'] !== $new_value['stripcategorybase'] ) {
50 $this->indexable_helper->reset_permalink_indexables( 'term', 'category', Indexing_Reasons::REASON_CATEGORY_BASE_PREFIX );
51 }
52 }
53 }
54