It doesn’t really matter. If you simply must have it inside a class, I would use a constant and a static method.
// in the main plugin file
define( 'MYPLUGIN_FILE', __FILE__ );
// include another file with this class in
class MyPlugin {
public static function init() {
register_activation_hook( MYPLUGIN_FILE, array( 'MyPlugin', 'install' ));
}
public static function install() {
echo "little lamb, who made thee? is it wordpress or is it me";
}
}
// call the static method
MyPlugin::init();
Related Posts:
- Detect when any plugin is activated or deactivated
- Are functions in main plugin file called before function bound to register_activation_hook runs?
- WordPress user account activation
- Advanced WordPress plugin activation detection
- Uninstall, Activate, Deactivate a plugin: typical features & how-to
- Passing a parameter to filter and action functions
- Get a list of all registered actions
- How can I edit post data before it is saved?
- How To Activate Plugins via Code?
- Activate a plugin through PHPMyAdmin or FTP?
- How can I see all the actions attached to an “add_action” hook?
- Where is the best place to use add_filter
- How to check if a theme is active?
- Deactivate plugin for a specific user group
- Auto Load Plugin Hooks inside Must Use Plugin
- How to only hook on Single.php after content?
- Pluggable function and activation check?
- Removing an action from an external plugin class
- When can you get current page ID and initialize hooks right after?
- How can I log a user out of WordPress before the page loads?
- What is the ‘admin_action_’ . $_REQUEST[‘action’] hook used for?
- Automatically install wordpress plugin at theme activation
- Show a confirm message before plug-in activation
- Autogenerate wordpress shortcodes using array?
- WordPress admin notice in plugin function
- Using the ‘draft_to_publish’ hook (post status transition)
- Function to activate WordPress theme inside a plugin
- Enqueue style inside shortcode but its loaded at the bottom of page (before footer scripts)
- How can I limit functionality in one version of a plugin?
- Is there a global action for when a plugin is uninstalled?
- Shortcode display outside the div
- Which hook callback has priority if both plugin and theme use the same hook?
- Good tools for locating hooks in a wordpress page/admin interface/blog post?
- Activate Plugin which is in subfolder?
- Use external link in the add sub menu
- explanation for activate_plugin function in wordpress core
- Remote plugin activation hook
- How to remove action from plugin?
- delay function on publish?
- Very stubborn wp_register_script / add_action vs remove
- How to prepend to the_title for admin-side plugin’s use
- How can I enqueue a style only when a particular widget is active?
- Add custom buttons with custom actions in Edit Post screen in WordPress?
- do_action and hook methods
- Force plugin to fail activation
- Can a plugin add to header/footer/body content?
- Is it possible to add an action to the currently running action?
- Is there an action that is called when a post is restored from the trash?
- WordPress register_activation_hook table creation not working
- Multisite: Activate plugin for subsites only?
- How to filter content post only on save
- Filter or action hook to insert content on admin pages before tag
- The plugin generated x characters of unexpected output, $wpdb not defined
- Is it possible to remove this action? (as it’s added just before it’s called)
- Correct way to use register_activation_hook
- Action on post publish
- How to add inline css/js inside a shortcode
- WordPress Plugin Boilerplate – add_action hook in static “activate” function
- How to call bind function in wordpress actions or hooks
- How to prevent action in ajax request, when in admin side?
- What is the purpose of $merged_filters?
- template_redirect not being called when using ajax
- Cannot run the code after I activate the plugin
- add action wp_head not working
- Can I use a method from an existing plugin as an action hook?
- Plugin custom Action Hook not working
- wordpress in nginx docker container connected to php:8-fpm container and mariadb container isn’t creating any tables on plugin activation
- Unable to activate wordpress importer after installing it
- What are the benefit in adding hook in the init() hook?
- How to include plugin without activation?
- add_action in functions.php, do_action in plugin?
- Auto add content such as pages upon plugin activation?
- How to automate wordpress plugin activate and deactivate by php logic?
- Default Plugin Settings Not Writing to Database
- add action for displaying posts using a shortcode
- Plugin won’t activate – cannot declare class (already in use)
- ‘wp_login’ action hook not working with wp-login.php file
- Where to hook my plugin’s action
- Plugin Deactivate Self on Activation Errors
- How to activate plugins for my WordPress sites from a remote server
- Overwrite or Replace code in WP_Footer
- register_activation_hook with include file [closed]
- Prevent a plugin from being automatically activated
- How to Use Parameters with a Do_Action Function Within PHP Tags
- How do action and filter hooks understand where to look for the core function that we hooked our function to them
- Is any information available in PHP files in WP about plugin activation history?
- WordPress filter that hook after each action/filter hook
- How to stop or remove an action being called inside a function of an extended class
- Get posts from WP_Query and format them on admin_head
- Automatically add attributes to woocommerce product?
- Any hook for pre-plugin-update -either bulk or single plugin update
- Activated plugin is stored as an object, rather than as a path
- Own plugin corrups plugin-activation
- wordpress plugin is not activating from widget
- Insert new user with form submit ‘init’ hook
- When to load auto-login code?
- How to get all of the activate_plugin action parameters?
- How to check if tables in WordPress still exists after activations
- How to block plugin activations with no known user or coming from unknown IP address range?
- Calling plugin function inside custom plugin for onclick event