| @@ -2,9 +2,8 @@ | ||
| 2 | 2 | |
| 3 | 3 | namespace Yoast\WP\SEO\Integrations\Watchers; |
| 4 | 4 | |
| 5 | 5 | use Yoast\WP\SEO\Conditionals\No_Conditionals; |
| 6 | -use Yoast\WP\SEO\Helpers\Wordproof_Helper; | |
| 7 | 6 | use Yoast\WP\SEO\Integrations\Integration_Interface; |
| 8 | 7 | |
| 9 | 8 | /** |
| 10 | 9 | * Watcher for the wpseo option. |
| @@ -15,24 +14,8 @@ | ||
| 15 | 14 | |
| 16 | 15 | use No_Conditionals; |
| 17 | 16 | |
| 18 | 17 | /** |
| 19 | - * Holds the WordProof helper instance. | |
| 20 | - * | |
| 21 | - * @var Wordproof_Helper | |
| 22 | - */ | |
| 23 | - protected $wordproof; | |
| 24 | - | |
| 25 | - /** | |
| 26 | - * The constructor for a watcher of WPSEO options. | |
| 27 | - * | |
| 28 | - * @param Wordproof_Helper $wordproof The WordProof helper instance. | |
| 29 | - */ | |
| 30 | - public function __construct( Wordproof_Helper $wordproof ) { | |
| 31 | - $this->wordproof = $wordproof; | |
| 32 | - } | |
| 33 | - | |
| 34 | - /** | |
| 35 | 18 | * Initializes the integration. |
| 36 | 19 | * |
| 37 | 20 | * This is the place to register hooks and filters. |
| 38 | 21 | * |
| @@ -40,9 +23,9 @@ | ||
| 40 | 23 | */ |
| 41 | 24 | public function register_hooks() { |
| 42 | 25 | \add_action( 'update_option_wpseo', [ $this, 'check_semrush_option_disabled' ], 10, 2 ); |
| 43 | 26 | \add_action( 'update_option_wpseo', [ $this, 'check_wincher_option_disabled' ], 10, 2 ); |
| 44 | - \add_action( 'update_option_wpseo', [ $this, 'check_wordproof_option_disabled' ], 10, 2 ); | |
| 27 | + \add_action( 'update_option_wpseo', [ $this, 'check_toggle_usage_tracking' ], 10, 2 ); | |
| 45 | 28 | } |
| 46 | 29 | |
| 47 | 30 | /** |
| 48 | 31 | * Checks if the SEMrush integration is disabled; if so, deletes the tokens. |
| @@ -75,8 +58,9 @@ | ||
| 75 | 58 | $disabled = $this->check_token_option_disabled( 'wincher_integration_active', 'wincher_tokens', $new_value ); |
| 76 | 59 | if ( $disabled ) { |
| 77 | 60 | \YoastSEO()->helpers->options->set( 'wincher_website_id', '' ); |
| 78 | 61 | } |
| 62 | + | |
| 79 | 63 | return $disabled; |
| 80 | 64 | } |
| 81 | 65 | |
| 82 | 66 | /** |
| @@ -84,8 +68,11 @@ | ||
| 84 | 68 | * |
| 85 | 69 | * We delete them if the WordProof integration is disabled, no matter if the |
| 86 | 70 | * value has actually changed or not. |
| 87 | 71 | * |
| 72 | + * @deprecated 22.10 | |
| 73 | + * @codeCoverageIgnore | |
| 74 | + * | |
| 88 | 75 | * @param array $old_value The old value of the option. |
| 89 | 76 | * @param array $new_value The new value of the option. |
| 90 | 77 | * |
| 91 | 78 | * @return bool Whether the WordProof tokens have been deleted or not. |
| @@ -90,13 +77,31 @@ | ||
| 90 | 77 | * |
| 91 | 78 | * @return bool Whether the WordProof tokens have been deleted or not. |
| 92 | 79 | */ |
| 93 | 80 | public function check_wordproof_option_disabled( $old_value, $new_value ) { |
| 94 | - $disabled = $this->check_token_option_disabled( 'wordproof_integration_active', 'wordproof_tokens', $new_value ); | |
| 95 | - if ( $disabled ) { | |
| 96 | - $this->wordproof->remove_site_options(); | |
| 81 | + \_deprecated_function( __METHOD__, 'Yoast SEO 22.10' ); | |
| 82 | + | |
| 83 | + return true; | |
| 84 | + } | |
| 85 | + | |
| 86 | + /** | |
| 87 | + * Checks if the usage tracking feature is toggled; if so, set an option to stop us from messing with it. | |
| 88 | + * | |
| 89 | + * @param array $old_value The old value of the option. | |
| 90 | + * @param array $new_value The new value of the option. | |
| 91 | + * | |
| 92 | + * @return bool Whether the option is set. | |
| 93 | + */ | |
| 94 | + public function check_toggle_usage_tracking( $old_value, $new_value ) { | |
| 95 | + $option_name = 'tracking'; | |
| 96 | + | |
| 97 | + if ( \array_key_exists( $option_name, $old_value ) && \array_key_exists( $option_name, $new_value ) && $old_value[ $option_name ] !== $new_value[ $option_name ] && $old_value['toggled_tracking'] === false ) { | |
| 98 | + \YoastSEO()->helpers->options->set( 'toggled_tracking', true ); | |
| 99 | + | |
| 100 | + return true; | |
| 97 | 101 | } |
| 98 | - return $disabled; | |
| 102 | + | |
| 103 | + return false; | |
| 99 | 104 | } |
| 100 | 105 | |
| 101 | 106 | /** |
| 102 | 107 | * Checks if the passed integration is disabled; if so, deletes the tokens. |
| @@ -112,9 +117,11 @@ | ||
| 112 | 117 | */ |
| 113 | 118 | protected function check_token_option_disabled( $integration_option, $target_option, $new_value ) { |
| 114 | 119 | if ( \array_key_exists( $integration_option, $new_value ) && $new_value[ $integration_option ] === false ) { |
| 115 | 120 | \YoastSEO()->helpers->options->set( $target_option, [] ); |
| 121 | + | |
| 116 | 122 | return true; |
| 117 | 123 | } |
| 124 | + | |
| 118 | 125 | return false; |
| 119 | 126 | } |
| 120 | 127 | } |