Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion inc/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,9 @@ public function activate() {
*/
public function deactivate() {
// Clear registered cron events.
wp_clear_scheduled_hook( 'optml_daily_sync' );
wp_clear_scheduled_hook( Optml_Admin::SYNC_CRON );
wp_clear_scheduled_hook( Optml_Admin::ENRICH_CRON );
// Pre-4.0.0 hook name, still scheduled on upgraded sites.
wp_clear_scheduled_hook( 'optml_pull_image_data_init' );
}

Expand Down
16 changes: 16 additions & 0 deletions tests/test-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,22 @@ public function test_svg_background_restore_is_sanitized_without_user(): void {
wp_delete_attachment( $attachment_id, true );
}

/**
* Test deactivation clears every recurring cron event the plugin schedules.
*/
public function test_deactivate_clears_recurring_cron_events(): void {
$hooks = [ Optml_Admin::SYNC_CRON, Optml_Admin::ENRICH_CRON, 'optml_pull_image_data_init' ];
foreach ( $hooks as $hook ) {
wp_schedule_event( time(), 'hourly', $hook );
}

Optml_Main::instance()->deactivate();

foreach ( $hooks as $hook ) {
$this->assertFalse( wp_next_scheduled( $hook ), "$hook is still scheduled." );
}
}

/**
* Mock the cloud URL lookup and the download of a scripted SVG during a restore.
*
Expand Down
Loading