private function delete_event_by_id($args, $assoc_args)
{
$jid = absint($assoc_args['event_id']);
// Validate ID
if (!$jid) {
\WP_CLI::error(__('Invalid event ID', 'automattic-cron-control'));
}
\WP_CLI::line(__('Locating event...', 'automattic-cron-control') . "\n");
// Look up full object and confirm that the entry belongs to this plugin's CPT
global $wpdb;
$event_post = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->posts} WHERE post_type = %s AND ID = %d LIMIT 1", \Automattic\WP\Cron_Control\Cron_Options_CPT::POST_TYPE, $jid));
if (is_object($event_post) && !is_wp_error($event_post)) {
// Parse basic event data and output, lest someone delete the wrong thing
$event_details = $this->get_event_details_from_post_title($event_post->post_title);
// Warning about Internal Events
if (\Automattic\WP\Cron_Control\is_internal_event($event_details['action'])) {
\WP_CLI::warning(__('This is an event created by the Cron Control plugin. It will recreated automatically.', 'automattic-cron-control'));
}
\WP_CLI::line(sprintf(__('Execution time: %s GMT', 'automattic-cron-control'), date(TIME_FORMAT, $event_details['timestamp'])));
\WP_CLI::line(sprintf(__('Action: %s', 'automattic-cron-control'), $event_details['action']));
\WP_CLI::line(sprintf(__('Instance identifier: %s', 'automattic-cron-control'), $event_details['instance']));
\WP_CLI::line('');
\WP_CLI::confirm(sprintf(__('Are you sure you want to delete this event?', 'automattic-cron-control')));
// Try to delete the item and provide some relevant output
$trashed = wp_delete_post($event_post->ID, true);
if (false === $trashed) {
\WP_CLI::error(sprintf(__('Failed to delete event %d', 'automattic-cron-control'), $jid));
} else {
\Automattic\WP\Cron_Control\_flush_internal_caches();
\WP_CLI::success(sprintf(__('Removed event %d', 'automattic-cron-control'), $jid));
return;
}
}
\WP_CLI::error(sprintf(__('Failed to delete event %d. Please confirm that the entry exists and that the ID is that of an event.', 'automattic-cron-control'), $jid));
}