Neither.
register_activation_hook( __FILE__, 'trigger_me' );
function trigger_me() {
if ( !wp_next_scheduled( 'my_plugin_cron' ) ) {
wp_schedule_event(time(), 'hourly', 'my_plugin_cron');
}
}
Why parse code on every request when you don’t need to?
Related Posts:
- Difference Between Filter and Action Hooks?
- How to create an API for my plugin?
- How to override existing plugin action with new action
- Which hook should be used to add an action containing a redirect?
- WordPress Update Plugin Hook/Action? Since 3.9
- add_action with a class method is causing fatal errors
- wp_schedule_event in a class
- How do you use the plugin boilerplate loader class to hook actions and filters?
- add_filter OO with parameters
- How do I print a notice only on certain admin pages?
- Do I need to call do_action in my plugin?
- How Do I Load My Action Earlier Enough?
- WP Cron – Run Cron after evey 15 minutes at a specific time for the next three hours
- Which to use to execute code during the saving of a plugin settings page?
- Does WP fire delete_post when trashed posts are automatically deleted?
- What’s the earliest point I can get the queried object ID?
- How do I Make a Theme “plugin-ready”?
- Using wp_cron with custom time interval and the register activation hook
- WordPress scheduled task is called but not executed
- A Post is saved twice or more during add_action(save_post)
- 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?
- Actions or filters fired when data is saved in a custom table
- WP Cron doesn’t save or in post body
- In a plugin, why is add_action(‘init’) not executed before the plugin is activated?
- What’s the difference between hooks, filters and actions? [duplicate]
- How to use filter hook ‘post_updated_messages’ in coherence with action hook ‘save_post’
- What action is called when drafts are saved?
- Is it possible to create an action hook using do_action() within add_action()?
- How can I hook into existing WordPress Bulk actions?
- When is it too late to call the action wp_enqueue_scripts?
- Odd behaviour with submenu link creation
- 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
- What is the Difference between directly call a function and call a function using add_action?
- How to add custom content under plugin row in WordPress admin plugin list?
- Define a function outside a class and call the function using action or filter hook
- Create a plugin to change the action to which a function is hooked
- Modifying values with add_action to be sent to db
- Woocommerce – Hide a Column in Cart Table
- How to redirect to action on custom page within admin section
- Scheduling a task using class methods
- admin_notices not displaying in plugin
- Hook to get image filename when it is uploaded
- How to run an add_action hook for specific page
- Which action is triggered when a theme was modified?
- wp_transition_post_status does not change the status of the post
- What is minimum time interval for which a cron be scheduled?
- Will cron job run if page loaded is being served from cache?
- Getting admin notices working for plugin errors
- Which are the hooks run before/after when a category’s deletion?
- Should action callbacks start with a verb?
- Execute Hook on the footer or header after activating a plugin
- Use wp_set_post_terms() instead of wp_insert_post()
- An echo line in a transition_post_status action leads to “cannot modify header information – headers already sent by”
- Namespaced action and filter tags
- Issue plugin commands in admin settings page
- My plugin class doesn’t work! [closed]
- Programmatically detect if wp-cron is disabled?
- add_action not calling back to function
- How to schedule a cron job in plugin without waiting for page load request?
- Tried in different ways but sidebar not working?
- conditionally load javascript & CSS for do_action() calls from plugin
- Plugin with action ‘save_post’ needs to press publish twice on order to publish
- How to do admin ajax request in a plugin for rest api
- Action / Hook when a new plugin is added
- apply_filters() and call_user_func() to define and call a function outside a class
- How to Run Plugin on Server Without Web Browser
- Where do I hook to have the server do something in PHP on block attribute change?
- ajax-action.php can’t find added action
- Post is uncatagorized in publish_post action
- WordPress Plugin Boilerplate – add actions and/or filters based on user’s role
- do_action from within a class does not seem to work
- wp_ajax add_action fuction won’t fire on custom jQuery action
- Plugin with functions inside a class & how to trigger WP CRON
- remove different admin menu for specific users
- WordPress Reset password Strength set to medium
- 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?
- add_option_{$option} action hook not being called
- Does WordPress have something like timer hook?
- WP Cron as Fast as WordPress AJAX?
- action callback, for action dispatched as reported by hook sniffer, not called
- How can I set a dynamic value for post_updated_messages based on return value of post_updated?
- 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?
- How to execute add_action() function from custom plugin to Crontrol plugin or do_action()?
- Call do_action() within WordPress cronjob
- Sending Parameter Failed
- How to remove a class [closed]
- Insert plugin html content to a specific spot in the frontpage
- Apply function on all action hooks?
- 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
- Ninja Forms: Front-End Forms, Post ID?
- WordPress Cron Job not importing products
- Weekly cron is either missing the schedule or triggered too many times on Fridays