Sometimes you want to run some code before deciding to add an action, or a filter. This may involve checking the user’s permissions, checking the type of page request, checking whether another plugin is active etc.
Some of those checks may not be possible until some way through WordPress’ execution – so it’s reasonably common to do that work in an init hook, rather than on plugin inclusion.
Doing everything like this means that your “initialisation” is all in one place, even if some of your actions don’t require it.
Related Posts:
- When can you get current page ID and initialize hooks right after?
- Using the ‘draft_to_publish’ hook (post status transition)
- Enqueue style inside shortcode but its loaded at the bottom of page (before footer scripts)
- Good tools for locating hooks in a wordpress page/admin interface/blog post?
- Is it possible to add an action to the currently running action?
- How to prevent action in ajax request, when in admin side?
- template_redirect not being called when using ajax
- add_action in functions.php, do_action in plugin?
- add action for displaying posts using a shortcode
- ‘wp_login’ action hook not working with wp-login.php file
- Any hook for pre-plugin-update -either bulk or single plugin update
- How to get all of the activate_plugin action parameters?
- Get Time Taken By Each Action Hook in WordPress
- Are functions in main plugin file called before function bound to register_activation_hook runs?
- Hook for page Request?
- The function called on the wp head hook becomes null
- Passing function into add_action always returns the first argument
- Plugin Hook: Get posts
- How wordpress plugin hooks works? [duplicate]
- How can I see all the actions attached to an “add_action” hook?
- Where is the best place to use add_filter
- How to only hook on Single.php after content?
- How to save the values of checkbox to the register setting?
- Edit plugin without hooks in functions.php
- What is the ‘admin_action_’ . $_REQUEST[‘action’] hook used for?
- WordPress admin notice in plugin function
- Use external link in the add sub menu
- Pass A Value From Outside To A Plugin Variable
- Built in admin ajax hooks?
- Failed to invoke other hook from the init hook
- How can I add a custom meta value on file upload?
- do_action and hook methods
- How can I filter blog name?
- How to register custom post types in a plugin?
- Can a plugin add to header/footer/body content?
- Is it possible to remove this action? (as it’s added just before it’s called)
- Action on post publish
- OOP: Display warning and deactivate the plugin if PHP version is less than 5.4
- WordPress Plugin Boilerplate – add_action hook in static “activate” function
- Determine plugin name from within plugin_action_links filter
- How to call bind function in wordpress actions or hooks
- Placement of Code in Plugin for hooking `save_post`
- publish_post plugin hook doesn’t always pass $post->post_content
- Can I use a method from an existing plugin as an action hook?
- Where to hook my plugin’s action
- How to pull code snippet from functionality plugin?
- Where (or when) should I register a new taxonomy?
- How do action and filter hooks understand where to look for the core function that we hooked our function to them
- wordpress plugin is not activating from widget
- Insert new user with form submit ‘init’ hook
- When to load auto-login code?
- How to stop activating a plugin and show admin notice when dependent plugins minimum version is not met
- How to check current user before all actions and filters?
- do_action() hook into load-(page)
- Howto check version of another plugin and then add a submenu page to it
- edit_user_profile and show_user_profile are not firing inside a class
- Add action to fire when a published post is updated
- How to pass variables to a function argument using add_action [duplicate]
- Submit Form data to another page via Ajax (WordPress Way)
- Why do plugins often ask to add in to templates?
- Does using `add_action( ‘init’…` cause performance issues?
- Create a post builder skin in a plugin
- remove_action not removing add_action from constructor
- How to get menu location in wp_update_nav_menu hook
- How do I add some javascript validation to the admin interface form’s onsubmit?
- Save user total active time after login in wordpress [closed]
- How to remove a class function from a plugin by using remove_action()?
- Advanced WordPress plugin activation detection
- wp_loaded with static Singleton
- is it possible to hook every page style?
- Custom CSS not being added by plugin
- How to use add_action for multiple instances of the same class
- What hook can I use to modify custom post data before it is displayed on the page?
- How to hook into action/filter call
- Quick press publish post hook
- How to deactivate my plugin upon deactivation of NextGen
- How to automatically activate users after registration without activation email?
- Creating a plugin that will display text on every page
- I cannot include a file in my plugin settings page
- Activation flow of a plugin in a multisite environment
- Add hook after content without formatting
- admin_post hook not firing function inside class
- Callback hooked to post_updated firing on new posts as well
- Why do actions with class and public method don’t fire __construct()
- Hooking into the HTML header container
- Get post content inside plugin class method
- {status}_{post_type} does not run correctly?
- WordPress Boilerplate Plugin doesn’t see callback functions for add_settings_field and add_settings_section
- Why can’t I shove an instance of a class into a variable from a do_action hook?
- Passing a parameter to filter and action functions
- Run only on plug-in activation instead of wp_head
- Display_rows() and column_cb() strange behaviour
- change output location of plugin function using a custom hook
- How to create and use Custom hooks
- OOP Plugin: Where should I place the action hooks in the class?
- add query string to all pages after user logged in
- Post curl function save twice using plugin hook function wordpress
- Hook automatic_updates_complete to autoupdate plugin
- Suitable hook when creating, updating and deleting posts programmatically
- is_user_logged_in() undefined at shutdown in plugin context