@@ -479,6 +479,8 @@ protected function cleanup() {
479479 $ this ->cleanup_post_type ();
480480 $ this ->drop_tables ();
481481 $ this ->cleanup_options ();
482+ $ this ->cleanup_cron ();
483+ $ this ->cleanup_legacy_cron ();
482484
483485 // If we got this far, let's remove the cron event.
484486 wp_clear_scheduled_hook ( 'cloudinary_cleanup_event ' );
@@ -600,4 +602,51 @@ protected function cleanup_options() {
600602 delete_transient ( $ key );
601603 }
602604 }
605+
606+ /**
607+ * Remove all cron-related tasks.
608+ *
609+ * @return void
610+ */
611+ protected function cleanup_cron () {
612+ // Get the Cron instance.
613+ $ cron_instance = Cron::get_instance ();
614+ $ schedule = $ cron_instance ->get_schedule ();
615+
616+ // Unregister all registered schedules.
617+ if ( ! empty ( $ schedule ) ) {
618+ foreach ( array_keys ( $ schedule ) as $ schedule_name ) {
619+ $ cron_instance ->unregister_schedule ( $ schedule_name );
620+ }
621+ }
622+
623+ // Remove any lock files or objects used by the Locker instance.
624+ $ cron_instance ->cleanup_locker ();
625+
626+ // Delete the cron schedule option saved in database.
627+ delete_option ( Cron::CRON_META_KEY );
628+ }
629+
630+ /**
631+ * Cleanup legacy cron jobs.
632+ *
633+ * @return void
634+ */
635+ protected function cleanup_legacy_cron () {
636+ wp_clear_scheduled_hook ( 'cloudinary_status ' );
637+
638+ $ jobs = array (
639+ 'cloudinary_rest_api_connectivity ' ,
640+ 'cloudinary_resume_queue ' ,
641+ 'cloudinary_resume_upgrade ' ,
642+ 'cloudinary_sync_items ' ,
643+ );
644+
645+ foreach ( $ jobs as $ job ) {
646+ $ time = wp_next_scheduled ( $ job );
647+ if ( false !== $ time ) {
648+ wp_clear_scheduled_hook ( $ job );
649+ }
650+ }
651+ }
603652}
0 commit comments