Simply check if the event is scheduled, and if not, schedule it:
add_action(
'init',
function () {
if ( ! wp_next_scheduled( 'my_scheduled_event' ) ) {
wp_schedule_event( time(), 'hourly', 'my_scheduled_event' );
}
}
);
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
- Will I get an error if I try unscheduling a WP Cron scheduled task that wasn’t scheduled?
- 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
- Get a path to a different plugin
- How to check uniqueness of plugin prefix?
- Plugin API for easy admin list table generation, handling & exporting of MySQL tables?
- How to post data to same page in wordpress
- Change default admin page for specific role(s)
- Check for dependent plugin and if false dont activate plugin
- How to check username/password without signing in the user
- Understanding WordPress functions’ naming conventions
- Show message on wordpress admin dashboard
- How to edit the properties of a page programmatically?
- Log in from one wordpress website to another wordpress website
- What’s the earliest point I can get the queried object ID?
- Custom admin_notices Messages Ignored During Redirects
- Add content to widget title in admin area within the widget?
- Show a user their recently viewed posts
- How is the data stored in the database?
- Is it save to require plugin.php early to be able to use get_plugin_data() earlier?
- When is it appropriate to put functions on page template vs. functions.php?
- How to use the settings API to set multidimensional arrays
- How to prevent loading of all plugin’s resources?
- Unit Testing a Plugin functionality with cron
- How to enable users to down-vote in this simple voting counter (that uses the post meta)?
- Plugin development, hooks, generate content
- Add a reset button to the options page (using Settings API)?
- Mediaelement.js feature doesn’t work
- Is it possible for a plugin to register a page template file?
- How to alter the order of custom form fields
- Help with callback using do_action_ref_array
- How to allow Unfiltered HTML in a wordpress multisite install
- Best way for plugin to accept POSTs?
- wp_remote_get keeps timing out
- What are the really difference writing WordPress 3.x widget plugins?
- Script to get a list of all images that are detached?
- Error “Call to a member function switch_to_locale() on null” during insert_with_markers
- multiple functions with same filter
- Calling plugins API within a theme
- How do you output enqueued scripts to an admin page?
- Woocommerce – Hide a Column in Cart Table
- How to get orders with used coupon in WooCommerce
- Generate dynamic page through data from another page
- Does WordPress’s HTTP API use any caching?
- query users by role
- call_user_func_array() expects parameter 1 to be a valid callback, array must have exactly two members
- How to Create Custom HTML Tag on Editor in `Text(HTML)` mode
- null callback in add_settings_section
- Comments do not respect display_name setting, how to make plugin to overcome this
- Is there a Filter that I can use to filter the tags before they are inserted in to the database?
- How long should it take for a plugin to fully load into the WordPress.org plugin repository?
- Which directory in my plugin repo does WordPress Plugin Directory package?
- How can I pass get_the_author_meta(‘user_email’) through the REST API?
- get post attachment using ajax
- Replace default Blogroll Links with Social Media Links
- Append varible to url or set session
- How to stop activation addon if the main plugin is not activated
- How would you compose a complex plugin with lots of routes and functions? [closed]
- How to enqueue or include json file to a plugin
- Search and Filter
- Show error, when selecting image in WordPress media uploader if params mismatch
- Trying to code a simple plugin, infinite loop?
- Update own Plugin Repository on Multisite
- Custom Plugin theme filter