| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yoast\WP\SEO\Integrations\Admin; |
| 4 |
|
| 5 |
use Yoast\WP\SEO\Conditionals\No_Conditionals; |
| 6 |
use Yoast\WP\SEO\Helpers\Indexable_Helper; |
| 7 |
use Yoast\WP\SEO\Helpers\Options_Helper; |
| 8 |
use Yoast\WP\SEO\Integrations\Cleanup_Integration; |
| 9 |
use Yoast\WP\SEO\Integrations\Integration_Interface; |
| 10 |
|
| 11 |
/** |
| 12 |
* This integration registers a run of the cleanup routine whenever the plugin is activated. |
| 13 |
*/ |
| 14 |
class Activation_Cleanup_Integration implements Integration_Interface { |
| 15 |
|
| 16 |
use No_Conditionals; |
| 17 |
|
| 18 |
/** |
| 19 |
* The indexable helper. |
| 20 |
* |
| 21 |
* @var Indexable_Helper |
| 22 |
*/ |
| 23 |
protected $indexable_helper; |
| 24 |
|
| 25 |
/** |
| 26 |
* The options helper. |
| 27 |
* |
| 28 |
* @var Options_Helper |
| 29 |
*/ |
| 30 |
private $options_helper; |
| 31 |
|
| 32 |
/** |
| 33 |
* Activation_Cleanup_Integration constructor. |
| 34 |
* |
| 35 |
* @param Options_Helper $options_helper The options helper. |
| 36 |
* @param Indexable_Helper $indexable_helper The indexable helper. |
| 37 |
*/ |
| 38 |
public function __construct( Options_Helper $options_helper, Indexable_Helper $indexable_helper ) { |
| 39 |
$this->options_helper = $options_helper; |
| 40 |
$this->indexable_helper = $indexable_helper; |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Registers the action to register a cleanup routine run after the plugin is activated. |
| 45 |
* |
| 46 |
* @return void |
| 47 |
*/ |
| 48 |
public function register_hooks() { |
| 49 |
\add_action( 'wpseo_activate', [ $this, 'register_cleanup_routine' ], 11 ); |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* Registers a run of the cleanup routine if this has not happened yet. |
| 54 |
* |
| 55 |
* @return void |
| 56 |
*/ |
| 57 |
public function register_cleanup_routine() { |
| 58 |
if ( ! $this->indexable_helper->should_index_indexables() ) { |
| 59 |
return; |
| 60 |
} |
| 61 |
$first_activated_on = $this->options_helper->get( 'first_activated_on', false ); |
| 62 |
|
| 63 |
if ( ! $first_activated_on || \time() > ( $first_activated_on + ( \MINUTE_IN_SECONDS * 5 ) ) ) { |
| 64 |
if ( ! \wp_next_scheduled( Cleanup_Integration::START_HOOK ) ) { |
| 65 |
\wp_schedule_single_event( ( \time() + \DAY_IN_SECONDS ), Cleanup_Integration::START_HOOK ); |
| 66 |
} |
| 67 |
} |
| 68 |
} |
| 69 |
} |
| 70 |
|