Skip to content

Commit 295d519

Browse files
remove crons on uninstallation
1 parent 18347a6 commit 295d519

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

uninstall.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,53 @@
3232
delete_option( 'feedzy_fresh_install' );
3333
delete_option( 'feedzy_wizard_data' );
3434
delete_option( 'feedzy_usage' );
35+
36+
/**
37+
* Clear scheduled hook.
38+
*
39+
* @param string $hook The name of the hook to clear.
40+
* @param array $args Optional. Arguments that were to be passed to the hook's callback function. Default empty array.
41+
* @return mixed The scheduled action ID if a scheduled action was found, or null if no matching action found. If WP_Cron is used, on success an integer indicating number of events unscheduled, false or WP_Error if unscheduling one or more events fail.
42+
*/
43+
function clear_scheduled_hook( $hook, $args = array() ) {
44+
if ( function_exists( 'as_unschedule_all_actions' ) ) {
45+
return as_unschedule_all_actions( $hook, $args );
46+
}
47+
48+
return wp_clear_scheduled_hook( $hook, $args );
49+
}
50+
51+
clear_scheduled_hook( 'feedzy_rss_feeds_log_activity' );
52+
53+
clear_scheduled_hook( 'feedzy_cron' );
54+
55+
clear_scheduled_hook( 'task_feedzy_cleanup_logs' );
56+
57+
clear_scheduled_hook( 'task_feedzy_send_error_report' );
58+
59+
// Remove import jobs based cron jobs.
60+
$import_job_crons = get_posts(
61+
array(
62+
'post_type' => 'feedzy_imports',
63+
'post_status' => 'publish',
64+
'numberposts' => 99,
65+
'fields' => 'ids',
66+
// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
67+
'meta_query' => array(
68+
'relation' => 'AND',
69+
array(
70+
'key' => 'fz_cron_schedule',
71+
'compare' => 'EXISTS',
72+
),
73+
),
74+
)
75+
);
76+
77+
78+
if ( ! empty( $import_job_crons ) ) {
79+
80+
foreach ( $import_job_crons as $job_id ) {
81+
$fz_cron_schedule = get_post_meta( $job_id, 'fz_cron_schedule', true );
82+
clear_scheduled_hook( 'feedzy_cron', array( 100, $job_id ) );
83+
}
84+
}

0 commit comments

Comments
 (0)