PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / trunk
Yoast SEO – Advanced SEO with real-time guidance and built-in AI vtrunk
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 trunk, at src/integrations/watchers/indexable-category-permalink-watcher.php

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