PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 28.2
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v28.2
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 / admin / activation-cleanup-integration.php

activation-cleanup-integration.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 28.2, at src/integrations/admin/activation-cleanup-integration.php

70 lines 1.8 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\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