So yeah, it does give errors for trying to unschedule something that isn’t scheduled, but the answer is pretty easy and simple:
$timestamp = wp_next_scheduled( 'scheduled_hook' );
if ($timestamp) wp_unschedule_event( $timestamp, 'scheduled_hook' );
Since wp_next_scheduled will return false for unscheduled hooks, a simple if in front of the call to wp_unschedule_event will prevent it from being called it there’s nothing scheduled
Related Posts:
- Which action for triggering cron “wp”or “init”?
- wp_schedule_event in a class
- WP Cron – Run Cron after evey 15 minutes at a specific time for the next three hours
- Using wp_cron with custom time interval and the register activation hook
- WordPress scheduled task is called but not executed
- Problem creating cron job wordpress
- How Do I Make WordPress Run an Event Every Day?
- How can I change the frequency of a scheduled event?
- Hourly WP schedule, do I need at least 1 visitor hourly?
- WP Cron doesn’t save or in post body
- Is there any background process that I can run from plugin without depending on page hits on a website without affecting page-load speed?
- WordPress cron running twice
- Scheduling a task using class methods
- What is minimum time interval for which a cron be scheduled?
- Will cron job run if page loaded is being served from cache?
- Use wp_set_post_terms() instead of wp_insert_post()
- Programmatically detect if wp-cron is disabled?
- How to schedule a cron job in plugin without waiting for page load request?
- How to perform a heavy and long process in cron jobs?
- WordPress daily cron is executing more frequently than once a day
- wp-cron and execution of code in is_admin() included script
- How to Trigger WP CRON at Local Timestamp?
- WP Cron being triggered but not working as expected
- wp_schedule_event() set daily, but processed every second
- Looking for a better way to initiate cron job
- WordPress plugin cron working only if admin is logged in
- How to make a cronjob type plugin
- wp_schedule_single_event is set correctly but sometimes not fired
- How to Run Plugin on Server Without Web Browser
- Plugin with functions inside a class & how to trigger WP CRON
- Custom recurrence not working / Wp Cron event
- How and when would I implement some code which would take data from one part of the Db and put it in another?
- WP Cron as Fast as WordPress AJAX?
- Detect each active instance of a widget
- What is the use of wp_schedule_event hook?
- Can wp_schedule_single_event be used to run background proccess?
- Call do_action() within WordPress cronjob
- Running one-off cron jobs when WP_DISABLE_CRON is true: can I hit /wp-cron.php?
- wp cron does not run when i am not logged in to wp admin
- add_settings_field Data not passing to Options Page Like it should
- Valid filenames for add_action’s first parameter
- What to hook into to check a value before a post is published?
- How do I access the menus produced by Dashboard > Appearance > Menus
- Determining URIs for plugin pages
- Filter Categories widget to allow custom sorting?
- Correct syntax for database inserts from plugin?
- How to add a gradient component to a custom block
- Can’t get AJAX call working in custom plugin
- How leave selected checkboxes marked after they are selected and saved in the database
- Custom Rest Endpoint: Post/Put/Patch not working
- How to allow only two (or more) users access to a plugin
- Custom avatars in wordpress comments?
- Admin Subpages without Menu entry
- $wpdb->update() always need a second try
- How to Schedule Cronjobs for start of every month and year
- How to get post image root URL?
- Page is loading after submit before the file is processed
- Insert Into Post Not Working For Audio File Using jQuery
- Custom Plugin Options Won’t Update
- Enqueue a file that’s not js or css
- Auto-complete or auto-suggest from stored data in database
- Schedule some work in custom plugin
- What is the replacement for rich_edit_exists()?
- Disable Auto-Expanding Menu in WordPress Admin Menus
- Plugin Development – Multilangual – Different pages
- Passing values between enclosing and enclosed shortcodes
- why does get_option( ‘home’ ) not work while using in plugin [closed]
- Undefined is_user_logged_in() error with Plugin Query code
- How to get changed post title in my custom plug-in which fires when ‘save_post’ is called?
- Rewriting Image URLs from dynamic to original
- Creating open content area and restricted content area
- Javascript Function Called Too Early in PHP Script
- Need Help Determining Where Header Error is Happening
- post content and shortcode content displaying out of order
- How to save page URL as a favorite
- Getting Post ID at “stylesheet” and “template” hooks
- Is there a way to get rendered html content of a WP post after updating?
- How to check category name available or not
- How to store sensitive user data (passwords)
- How can we upload file to root directory of wordpress
- Quick Draft widget (dashboard.php) using custom post_type
- Generate Static Page to Show Search Results/Detail for API
- How do I use a plugin to swap out the template file for a custom post type?
- Custom Post not Deleting on Uninstall
- User avatar-ACF fields
- How can I specify the plugin language in WordPress?
- Prevent plugin activation and add admin notice
- How to make sure wordpress and woocommerce plugins work on all configurations
- WordPress Dropdown image select
- Plugin options with googlemap iframe
- How do I call the dashboard’s sortable javascript in a plugin page?
- Submitting a plugin form to database in admin page
- Only admin should run wordpress plugin shortcode
- How to view the code for a certain page?
- Customizing Woocommerce Email
- How can I create a custom plugin to call webapi after user registration?
- Displaying an Uploaded Image as a Custom Avatar in WordPress
- Developing an IP lookup function using an API
- Integrating Multiple WordPress Plugins into One Dashboard
- Template locked block does not show appender