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
- Change the_title() of a page dynamically
- Adding more options to the instance of an image. (Attachment Display Settings)
- Trouble with Transient API when W3TC is activated [closed]
- Using wp_filesystem in Plugins
- WordPress REST API call generates nonce twice on every call
- Filters ‘request’ and ‘parse_query’ not firing in sites.php nor link-manager.php
- How to trap “Publish” button to check for meta box validation?
- How to use filter hook ‘post_updated_messages’ in coherence with action hook ‘save_post’
- wp_mail not recognizing cc and bcc headers
- How can I call “preview post” from wp_remote_get with authentication?
- Plugin Loading Scripts and Styles on Every Page – Even when not being used
- set_sale_price in WooCommerce [closed]
- Adding extra pages to plugin that shouldn’t appear in the sidebar
- How do I include background images in my stylesheets in a plugin?
- Custom plugin icon not showing up
- I’m designing a plugin to create database indexes. Suggestions?
- need to get user ID after a user logs in
- Plugin for Android Marketplace downloads?
- Parse form values before sending to options.php
- My WordPress plugin cannot load my JavaScript file
- Password field is empty when using wp_signon();
- How to make a implement queue for scheduling tasks in WordPress?
- Show error message after exception handled
- How to use github to update my plugin
- Plugin Options Array Set to Undefined
- is pre_get_comments not working?
- How do I have now a duplicated user entry if this is not allowed (and I cannot replicate it)?
- Settings API – format container of setting and setting’s description
- Delete option of a Plugin
- Automating the process of shortcode generation in a plugin – how is it done?
- I am trying to make a page in the admin section similar to the appearance of the Profile page for users
- Proper way to include stylesheet for panels
- Best way to include and use Zoho SDK in a wordpress plugin
- How to change WooCommerce loop product title HTML output in single product page and archive page
- How remove trashed WooCommerce orders from wc_get_orders() result?
- Unexpected T_FUNCTION
- How to avoid conflicts with db.php / $wpdb and other plugins that decide to use them?
- Plugin can’t be activated [closed]
- Is there an action_filter hook to add content before the post title?
- CSS not being applied using wp_enqueue_style
- Add quick edit functionnality to plugin table
- Hide / show settings field based on other field’s value
- $_SESSION inside php function executed by AJAX
- Two same AJAX calls – one is working, other doesn’t
- add pagination to wp_remote_get
- Adding and handling custom settings tab to fusion element
- How to get option values without requiring wp-load?
- Problem with baseurl and interaction with plugin
- Why setcookie function redirecting to home page in wordpress?
- Should all roles be allowed CRUD operation on the database?
- Associating special meaning with user id 0
- Filter get_user_by instead of replace function
- Downloading Generated XML File
- How to create a custom search form and handler?
- How to use permalink query to go to specific tabs in posts
- Conditional query tags do not work before the query is run. Before then, they always return false
- Method to retrieve category names and IDs only as an array?
- Send Webhook when post-status is publish or trash
- Using “add_image_size” to register custom image sizes inside plugins not working
- How will i add an option under customizer the event calendar section?
- Return custom product in ajax call loop