| @@ -23,8 +23,9 @@ | ||
| 23 | 23 | */ |
| 24 | 24 | public function register_hooks() { |
| 25 | 25 | \add_action( 'update_option_wpseo', [ $this, 'check_semrush_option_disabled' ], 10, 2 ); |
| 26 | 26 | \add_action( 'update_option_wpseo', [ $this, 'check_wincher_option_disabled' ], 10, 2 ); |
| 27 | + \add_action( 'update_option_wpseo', [ $this, 'check_toggle_usage_tracking' ], 10, 2 ); | |
| 27 | 28 | } |
| 28 | 29 | |
| 29 | 30 | /** |
| 30 | 31 | * Checks if the SEMrush integration is disabled; if so, deletes the tokens. |
| @@ -57,12 +58,53 @@ | ||
| 57 | 58 | $disabled = $this->check_token_option_disabled( 'wincher_integration_active', 'wincher_tokens', $new_value ); |
| 58 | 59 | if ( $disabled ) { |
| 59 | 60 | \YoastSEO()->helpers->options->set( 'wincher_website_id', '' ); |
| 60 | 61 | } |
| 62 | + | |
| 61 | 63 | return $disabled; |
| 62 | 64 | } |
| 63 | 65 | |
| 64 | 66 | /** |
| 67 | + * Checks if the WordProof integration is disabled; if so, deletes the tokens | |
| 68 | + * | |
| 69 | + * We delete them if the WordProof integration is disabled, no matter if the | |
| 70 | + * value has actually changed or not. | |
| 71 | + * | |
| 72 | + * @deprecated 22.10 | |
| 73 | + * @codeCoverageIgnore | |
| 74 | + * | |
| 75 | + * @param array $old_value The old value of the option. | |
| 76 | + * @param array $new_value The new value of the option. | |
| 77 | + * | |
| 78 | + * @return bool Whether the WordProof tokens have been deleted or not. | |
| 79 | + */ | |
| 80 | + public function check_wordproof_option_disabled( $old_value, $new_value ) { | |
| 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; | |
| 101 | + } | |
| 102 | + | |
| 103 | + return false; | |
| 104 | + } | |
| 105 | + | |
| 106 | + /** | |
| 65 | 107 | * Checks if the passed integration is disabled; if so, deletes the tokens. |
| 66 | 108 | * |
| 67 | 109 | * We delete the tokens if the integration is disabled, no matter if |
| 68 | 110 | * the value has actually changed or not. |
| @@ -68,9 +110,9 @@ | ||
| 68 | 110 | * the value has actually changed or not. |
| 69 | 111 | * |
| 70 | 112 | * @param string $integration_option The intergration option name. |
| 71 | 113 | * @param string $target_option The target option to remove the tokens from. |
| 72 | - * @param array $new_value The new value of the option. | |
| 114 | + * @param array $new_value The new value of the option. | |
| 73 | 115 | * |
| 74 | 116 | * @return bool Whether the tokens have been deleted or not. |
| 75 | 117 | */ |
| 76 | 118 | protected function check_token_option_disabled( $integration_option, $target_option, $new_value ) { |
| @@ -75,9 +117,11 @@ | ||
| 75 | 117 | */ |
| 76 | 118 | protected function check_token_option_disabled( $integration_option, $target_option, $new_value ) { |
| 77 | 119 | if ( \array_key_exists( $integration_option, $new_value ) && $new_value[ $integration_option ] === false ) { |
| 78 | 120 | \YoastSEO()->helpers->options->set( $target_option, [] ); |
| 121 | + | |
| 79 | 122 | return true; |
| 80 | 123 | } |
| 124 | + | |
| 81 | 125 | return false; |
| 82 | 126 | } |
| 83 | 127 | } |