It looks like you know what’s going on – here’s a way to avoid running the activation method more than once:
class AdminSupport {
protected static $activated = false;
public function onInitialize(){
add_action('my_hourly_event', array($this, 'do_this_hourly' ));
}
public function my_activation() {
if ( self::$activated ) {
return;
}
wp_schedule_event( time(), 'hourly', 'my_hourly_event' );
self::$activated = true;
}
public function do_this_hourly() {
// do something every hour
$this->assessplugins();
}
public function my_deactivation() {
wp_clear_scheduled_hook( 'my_hourly_event' );
}
public function assessplugins(){
//Does some things
}
}
Related Posts:
- What’s the difference between term_id and term_taxonomy_id
- Is it ever okay to include inline CSS in plugins?
- How do I programatically insert a new menu item?
- When would I use either function for plugins?
- Test to see if jQuery or Prototype is queued by another plugin?
- How to tell if an option has been created vs an empty option?
- jQuery in header or footer
- Notice: _usort_terms_by_ID is deprecated since version 4.7.0! Use wp_list_sort instead
- How to add a new plugin page under desired Options page?
- Plugin screenshots not showing in the repository
- How to make WordPress use non-greedy shortcode parsing?
- Multiple Parameters for a Shortcode
- WP Cron doesn’t save or in post body
- Pages 404 in wordpress
- How to properly load text domain of custom mu plugin
- Post from front-end with post types, categories and taxonomies
- product-attribute-slug-is-too-long-28-characters-max
- Multiple entries in get_option results? or why is _multiwidget set to 1?
- Check if I am in the Admin Panel (wp-admin)?
- Fully automated theme install and activation via a plugin
- Using Ajax call in jQuery doesn’t work in widget
- Why is WP_Mock not used instead of WP_UnitTestCase for writing unit tests by most plugins?
- Confusion on WP Nonce usage in my Plugin
- Metabox Not Showing on Custom Post Type But On Pages and Post
- Using Checkboxes on Plugin Options Page for Custom Plugin
- Add media and attach images to pages
- Why cant the WP Filesystem API read googlefonts.json?
- Create a Page via plugin
- Generating User(s) with Settings API
- How to redirect to action on custom page within admin section
- Show comments fields in two columns
- Processing shortcodes in groups (separated by line breaks)?
- How to determine if the current file is loaded in a plugin or in a theme?
- How to convert this cURL to wp_remote_get?
- Which action is triggered when a theme was modified?
- Check if someone is editing a post (this content is currently locked)
- Including a JS source with an admin page
- Should action callbacks start with a verb?
- How insert negative values in Gutenberg box-control
- WordPress setting with select – where is my mistake?
- What filter should I use to insert a button inside on Media>Add New
- is user logged in not working
- Override class inside $atts shortcode_atts in WordPress
- How to use a hook to override an update_post_meta call in a plugin?
- External Authentication, session_tokens not destroyed on logout
- Adding custom fields to WordPress nav menus
- How to programmatically add a custom template that appears in Site Editor from a plugin?
- In woocommerce cart item we can add custom text but how can i add custom link? [closed]
- Is it possible to restrict all admin pages except theme customisation and storefront using plugin?
- Updating Woocommerce Settings API when WordPress Settings API saved and vise versa
- How to Upload Images From a Folder (Not WP_Uploads)
- Build a translation correcter plugin
- Secure REST with nonce works only when not logged
- Shortcode returning localized HTML part
- Custom WordPress Plugin will install new and not update
- get_option() will not work without access to wp-config.php
- register_activation_hook on multisite
- Use ‘get’ form action within a WordPress plugin admin page
- Template directory in plugin
- WordPress Admin Login Custom Logo
- Woocommerce order empty items array
- Bind a function with its own argument to show something dynamically after every content
- Drawing the line between theme & plugin on large scale bespoke projects
- HowTo to add my rewrite rules at the beginning, redirect to the right page and flush the rules on plugin activation?
- Apply styles to blockquote element with the WYSIWYG editor
- Do I need to create an endpoint?
- How to check whether checkbox is checked in WordPress customizer
- How to find list of all functions bind to a particular hook from my plugin?
- How to list all images used on a specific page?
- Create fixed static pages
- How to output CSS to the beginning of the stylesheet in a WordPress Plugin
- Set page to draft on plugin deactivation
- Can one plugin activate another plugin via script?
- How to create wordpress media library UI on plugin page
- Why my theme’s css not working on another site
- Insert and read media from the WordPress library and call in the plugin
- How to create dynamic content with get_post_meta?
- Override category archive page title (not the head title)
- Enable a role named ‘backend_user’ to access my plugin pages
- get_queried_object_id combined with wp_redirect gets wrong id
- Using WordPress Boilerplate (WPBP) for WP Multisite Plugin
- Hiding class namespace from plugin’s extensions
- How to trigger WooCommerce user profile edit change?
- Return raw image proxy for wordpress plugin
- How to handle ajax Request in a complex-structured plugin?
- Stop unauthorised file access
- Changed media upload path for plugin, but generates error & shows wrong url
- How to pass a more variable with page/subpage in Wordprees URL?
- Use a page as a template for a custom post type
- Dynamic sidebar areas not working on the Theme Customizer
- Woo-commerce: Adding additional page sections using a child theme
- Plugin dev: How to multiply instances of a plugin in the same metabox?
- Merge Codes using redux framework
- Getting Plugin to read all script files
- How to use get_pages( ) correctly with ‘child_of’ to replace page with child page
- Problem with Poedit [closed]
- get_term_by() returning null on plugin
- Reinitiate Gutenburg’s blocks using javascript
- Generating Multiple Divi Pages from Database
- Is it smart to require_once wp-admin/includes/plugin.php when you need only one function from it