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:
- 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
- add_filter OO with parameters
- 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
- 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()?
- When is it too late to call the action wp_enqueue_scripts?
- Odd behaviour with submenu link creation
- 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?
- Create a plugin to change the action to which a function is hooked
- 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
- Which action is triggered when a theme was modified?
- 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?
- 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?
- Plugin with action ‘save_post’ needs to press publish twice on order to publish
- Adding rewrite rule dynamically
- Prefixing plugin hooks (actions/filters) with a wrapper class or functions
- How to perform a heavy and long process in cron jobs?
- wp_set_object_terms not updating database without a die()
- How to filter content for specific content variable
- load_plugin_textdomain doestn’t work with add_action plugins_loaded
- Show error message after exception handled
- I have 2 plugins using the same wp_login action hook and one is not working
- WordPress daily cron is executing more frequently than once a day
- Valid filenames for add_action’s first parameter
- WordPress class, using add_action to call member function does not work
- Where do I put my add_action(… and add_filter(… and do I need to remove them?
- How dynamic action login_form_{action} is working
- How to get all queries’s results after they have executed?
- WP Cron being triggered but not working as expected
- Bug: Post needs to be updated twice when adding action for save_post hook
- wp_schedule_event() set daily, but processed every second
- Delete data from database using row action
- When does save_post hook fire on post save/update
- A question about add_action()
- Call to undefined function is_home() or any conditional tags
- 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
- Include HTML (Bootstrap Modal Box) with a plugin into my header
- wordpress automatic update does not run
- Using init hook for register_taxonomy is causing invalid_taxonomy in wp_insert_term()
- How Can I Add Code To A Preexisting Function Without Editing it
- Adding tables to dashboard pages programmatically?
- Setting post_id for single.php based on URL without a redirect
- wp_schedule_single_event is set correctly but sometimes not fired
- 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
- 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
- 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
- Custom recurrence not working / Wp Cron event
- Does WordPress have something like timer hook?
- WP Cron as Fast as WordPress AJAX?
- 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?
- 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]
- 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