PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 18.0
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v18.0
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 / option-wpseo-watcher.php

option-wpseo-watcher.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 18.0, at src/integrations/watchers/option-wpseo-watcher.php

84 lines 2.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 Yoast\WP\SEO\Conditionals\No_Conditionals;
6 use Yoast\WP\SEO\Integrations\Integration_Interface;
7
8 /**
9 * Watcher for the wpseo option.
10 *
11 * Represents the option wpseo watcher.
12 */
13 class Option_Wpseo_Watcher implements Integration_Interface {
14
15 use No_Conditionals;
16
17 /**
18 * Initializes the integration.
19 *
20 * This is the place to register hooks and filters.
21 *
22 * @return void
23 */
24 public function register_hooks() {
25 \add_action( 'update_option_wpseo', [ $this, 'check_semrush_option_disabled' ], 10, 2 );
26 \add_action( 'update_option_wpseo', [ $this, 'check_wincher_option_disabled' ], 10, 2 );
27 }
28
29 /**
30 * Checks if the SEMrush integration is disabled; if so, deletes the tokens.
31 *
32 * We delete the tokens if the SEMrush integration is disabled, no matter if
33 * the value has actually changed or not.
34 *
35 * @param array $old_value The old value of the option.
36 * @param array $new_value The new value of the option.
37 *
38 * @return bool Whether the SEMrush tokens have been deleted or not.
39 */
40 public function check_semrush_option_disabled( $old_value, $new_value ) {
41 return $this->check_token_option_disabled( 'semrush_integration_active', 'semrush_tokens', $new_value );
42 }
43
44 /**
45 * Checks if the Wincher integration is disabled; if so, deletes the tokens
46 * and website id.
47 *
48 * We delete them if the Wincher integration is disabled, no matter if the
49 * value has actually changed or not.
50 *
51 * @param array $old_value The old value of the option.
52 * @param array $new_value The new value of the option.
53 *
54 * @return bool Whether the Wincher tokens have been deleted or not.
55 */
56 public function check_wincher_option_disabled( $old_value, $new_value ) {
57 $disabled = $this->check_token_option_disabled( 'wincher_integration_active', 'wincher_tokens', $new_value );
58 if ( $disabled ) {
59 \YoastSEO()->helpers->options->set( 'wincher_website_id', '' );
60 }
61 return $disabled;
62 }
63
64 /**
65 * Checks if the passed integration is disabled; if so, deletes the tokens.
66 *
67 * We delete the tokens if the integration is disabled, no matter if
68 * the value has actually changed or not.
69 *
70 * @param string $integration_option The intergration option name.
71 * @param string $target_option The target option to remove the tokens from.
72 * @param array $new_value The new value of the option.
73 *
74 * @return bool Whether the tokens have been deleted or not.
75 */
76 protected function check_token_option_disabled( $integration_option, $target_option, $new_value ) {
77 if ( \array_key_exists( $integration_option, $new_value ) && $new_value[ $integration_option ] === false ) {
78 \YoastSEO()->helpers->options->set( $target_option, [] );
79 return true;
80 }
81 return false;
82 }
83 }
84