wordpress-seo
/
src
/
alerts
/
user-interface
/
default-seo-data
/
default-seo-data-cron-scheduler.php
default-seo-data-cron-scheduler.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 28.4, at src/alerts/user-interface/default-seo-data/default-seo-data-cron-scheduler.php
| 1 | <?php |
| 2 | |
| 3 | // phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong |
| 4 | namespace Yoast\WP\SEO\Alerts\User_Interface\Default_Seo_Data; |
| 5 | |
| 6 | use Yoast\WP\SEO\Conditionals\No_Conditionals; |
| 7 | use Yoast\WP\SEO\Integrations\Integration_Interface; |
| 8 | |
| 9 | /** |
| 10 | * Responsible for scheduling and unscheduling the cron. |
| 11 | */ |
| 12 | class Default_SEO_Data_Cron_Scheduler implements Integration_Interface { |
| 13 | |
| 14 | use No_Conditionals; |
| 15 | |
| 16 | /** |
| 17 | * The name of the cron job. |
| 18 | */ |
| 19 | public const CRON_HOOK = 'wpseo_detect_default_seo_data'; |
| 20 | |
| 21 | /** |
| 22 | * Register hooks. |
| 23 | * |
| 24 | * @return void |
| 25 | */ |
| 26 | public function register_hooks() { |
| 27 | \add_action( 'admin_init', [ $this, 'schedule_default_seo_data_detection' ] ); |
| 28 | \add_action( 'wpseo_deactivate', [ $this, 'unschedule_default_seo_data_detection' ] ); |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * Schedules the default SEO data detection cron. |
| 33 | * |
| 34 | * @return void |
| 35 | */ |
| 36 | public function schedule_default_seo_data_detection(): void { |
| 37 | if ( ! \wp_next_scheduled( self::CRON_HOOK ) ) { |
| 38 | \wp_schedule_event( ( \time() + \DAY_IN_SECONDS ), 'daily', self::CRON_HOOK ); |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Unschedules the default SEO data detection cron. |
| 44 | * |
| 45 | * @return void |
| 46 | */ |
| 47 | public function unschedule_default_seo_data_detection() { |
| 48 | $scheduled = \wp_next_scheduled( self::CRON_HOOK ); |
| 49 | if ( $scheduled ) { |
| 50 | \wp_unschedule_event( $scheduled, self::CRON_HOOK ); |
| 51 | } |
| 52 | } |
| 53 | } |
| 54 |