| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yoast\WP\SEO\MyYoast_Client\User_Interface; |
| 4 |
|
| 5 |
use Yoast\WP\SEO\Conditionals\MyYoast_Connection_Conditional; |
| 6 |
use Yoast\WP\SEO\Integrations\Integration_Interface; |
| 7 |
use Yoast\WP\SEO\MyYoast_Client\Application\MyYoast_Client_Cleanup; |
| 8 |
|
| 9 |
/** |
| 10 |
* Handles cleanup of all MyYoast client data on plugin uninstall or through Yoast Test Helper. |
| 11 |
*/ |
| 12 |
class MyYoast_Cleanup_Integration implements Integration_Interface { |
| 13 |
|
| 14 |
/** |
| 15 |
* The cleanup service. |
| 16 |
* |
| 17 |
* @var MyYoast_Client_Cleanup |
| 18 |
*/ |
| 19 |
private $cleanup; |
| 20 |
|
| 21 |
/** |
| 22 |
* MyYoast_Cleanup_Integration constructor. |
| 23 |
* |
| 24 |
* @param MyYoast_Client_Cleanup $cleanup The cleanup service. |
| 25 |
*/ |
| 26 |
public function __construct( MyYoast_Client_Cleanup $cleanup ) { |
| 27 |
$this->cleanup = $cleanup; |
| 28 |
} |
| 29 |
|
| 30 |
/** |
| 31 |
* Returns the conditionals based on which this integration should be loaded. |
| 32 |
* |
| 33 |
* @return array<string> The array of conditionals. |
| 34 |
*/ |
| 35 |
public static function get_conditionals() { |
| 36 |
return [ MyYoast_Connection_Conditional::class ]; |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* Registers hooks. |
| 41 |
* |
| 42 |
* @return void |
| 43 |
*/ |
| 44 |
public function register_hooks(): void { |
| 45 |
\add_action( 'uninstall_' . \WPSEO_BASENAME, [ $this, 'cleanup' ] ); |
| 46 |
|
| 47 |
/** |
| 48 |
* Public action that wipes all local MyYoast OAuth client state |
| 49 |
* (registered client, site/user tokens, key pairs, OIDC/JWKS/DPoP caches). |
| 50 |
* |
| 51 |
* Intended for development tooling that needs to reset state without |
| 52 |
* uninstalling the plugin. The handler is the same one that runs on |
| 53 |
* uninstall, so the effect is identical. |
| 54 |
* |
| 55 |
* @internal |
| 56 |
*/ |
| 57 |
\add_action( 'wpseo_myyoast_clear_client_state', [ $this, 'cleanup' ] ); |
| 58 |
} |
| 59 |
|
| 60 |
/** |
| 61 |
* Cleans up all MyYoast client data. |
| 62 |
* |
| 63 |
* @return void |
| 64 |
*/ |
| 65 |
public function cleanup(): void { |
| 66 |
$this->cleanup->execute(); |
| 67 |
} |
| 68 |
} |
| 69 |
|