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?
- 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?
- Does WP fire delete_post when trashed posts are automatically deleted?
- What’s the earliest point I can get the queried object ID?
- Using wp_cron with custom time interval and the register activation hook
- 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]
- What action is called when drafts are saved?
- How can I hook into existing WordPress Bulk actions?
- 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?
- 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
- 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
- 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
- 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
- Adding rewrite rule dynamically
- How to hook a custom user function to a wordpress core ajax action?
- Prefixing plugin hooks (actions/filters) with a wrapper class or functions
- Unable to change footer using wp_footer action hook
- How to filter content for specific content variable
- load_plugin_textdomain doestn’t work with add_action plugins_loaded
- 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?
- wp-cron and execution of code in is_admin() included script
- How dynamic action login_form_{action} is working
- What action hook can I use to add a JavaScript to a page post using a theme template that is not including get_header() nor get_footer()?
- How to Trigger WP CRON at Local Timestamp?
- How to get all queries’s results after they have executed?
- wp_schedule_event() set daily, but processed every second
- A question about add_action()
- Hook add_attachment error
- Will I get an error if I try unscheduling a WP Cron scheduled task that wasn’t scheduled?
- Looking for a better way to initiate cron job
- How to find list of all functions bind to a particular hook from my plugin?
- WordPress plugin cron working only if admin is logged in
- Can I Hook Into the TinyMCE Insert/Edit Link Button to Use Shortlink For Post?
- wordpress automatic update does not run
- How to make a cronjob type plugin
- How Can I Add Code To A Preexisting Function Without Editing it
- Adding tables to dashboard pages programmatically?
- How to do admin ajax request in a plugin for rest api
- apply_filters() and call_user_func() to define and call a function outside a class
- How to Run Plugin on Server Without Web Browser
- ajax-action.php can’t find added 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
- remove different admin menu for specific users
- WordPress Reset password Strength set to medium
- 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
- 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()?
- Sending Parameter Failed
- How to remove a class [closed]
- Insert plugin html content to a specific spot in the frontpage
- Running one-off cron jobs when WP_DISABLE_CRON is true: can I hit /wp-cron.php?
- Ninja Forms: Front-End Forms, Post ID?