The rule of thumb is to never do anything which is not triggered by action or filter.
In this case you try register a hook before wordpress even finished to “boot”. This may work sometimes, but totally not an healthy idea. Use at least the ‘init’ hook (and even better the ‘wp_loaded’ if you can), to trigger you initialization, and do not do anything before that unless you have a very good reason.
As for the activation hook, be very careful with trusting it being triggered as it will not be triggered on multisite install, and not when updates are done, so you might as well plan in advance and detect by yourself when DB initialization or updates are required.
Related Posts:
- Difference Between Filter and Action Hooks?
- How many times will this code run? (or, how rich is grandma?)
- Admin settings update updating every time home page is hit?
- Global Objects and Public Methods
- Using filters and actions for plugin API?
- Explanation of the “posts_join” and “posts_fields” filter hooks?
- How do you use the plugin boilerplate loader class to hook actions and filters?
- How Do I Load My Action Earlier Enough?
- Does WP fire delete_post when trashed posts are automatically deleted?
- Why does do_action pass a blank string as the first parameter if no $arg is set?
- How to add a link to WordPress Plugin install Listing
- I can’t find where a hook is being defined in a plugin – Easy Digital Downloads
- Call activation hook multiple times
- What’s the difference between hooks, filters and actions? [duplicate]
- Two-step login process – Is it possible?
- How can I hook into existing WordPress Bulk actions?
- Get returned variable from a function to add_shortcode function
- Earliest WP Hook to Safely and Reliably Redirect
- Define a function outside a class and call the function using action or filter hook
- Is it possible to modify the media library admin screen?
- What function to hook for changes made in status and visibility of a post
- Can I differentiate between “Delete Post Permanently” and “Empty Trash” and do something for each accordingly?
- Synchronize Custom post type tags to WordPress default posts tags
- Order of Operation for these three hooks
- comment_email hook doesn’t seem to work for comment editor field
- Modifying values with add_action to be sent to db
- unable to stop loop when using wp_insert_post with publish_post hook
- save_post hook not triggered in WP v3.6.1
- Hook into theme-switching later than `setup_theme`
- Is it possible to delay execution of shortcode output callback?
- WordPress Ajax callback function from plugin – OOP
- Hook to get image filename when it is uploaded
- How to display a message about updates in the plugin list
- How do I change the initial quantity of a product in woocommerce?
- Act on user meta updated, but only once
- Where and how does WordPress store and use its plugin and hook information?
- Is there any way to allow a plugin to write over a previous version?
- edit_{$taxonomy} | Hook
- WordPress after content Hook & external template part
- How to update an existing table while updating plugin?
- best practice for query string values – get_query_var always empty for my value supplied in query string
- get_current_screen() return null
- Modifying meta tags after doing ajax call in plugin
- how to add custom functionality after woocommerce place order button
- Storing product price data in the database
- Where to add hooks in a class
- How to use output buffering in WordPress hooked functions?
- Conditional hook based on the core function that is calling it
- Adding option to Gallery shortcode
- I have 2 plugins using the same wp_login action hook and one is not working
- Gutenberg table block with Bootstrap .table class
- use of do_action() without any functions attached
- How dynamic action login_form_{action} is working
- dbDelta not installing database
- What happens when two or more plugins use the same hook?
- How to get all queries’s results after they have executed?
- Add child pages to submenu automatically
- Odd map_meta_cap $args on post edit — sometimes integer, sometimes string
- How can I create a custom plugin that allows anonymous users to signup without registering?
- Bind a function with its own argument to show something dynamically after every content
- What’s the hook for filtering every texts of site?
- Hook add_attachment error
- Associate multiple email addresses with the same user account, so they can log in with either
- Update variable value via add_filter
- Custom filter not working
- hook update_option/updated_option empty $old_value and $value
- Configure WordPress to Generate Scheme-less Relative URLs
- How to find list of all functions bind to a particular hook from my plugin?
- Ajax +wordpress onClick link redirect to new page and create html content
- How to replace settings in WordPress plugin from a theme
- Why doesn’t my Table get created?
- Serial Number from custom table not appear in woocommerce_email_before_order_table action
- Creating posts with links from a txt file
- apply_filters() and call_user_func() to define and call a function outside a class
- Is there any way to get post meta from publish_post hook?
- Problem in plugin debuging in wordpress
- WordPress Plugin Boilerplate – add actions and/or filters based on user’s role
- OOP development and hooks
- Plugin Development – Call to undefined function comment_exists()
- Add_action not calling callback function
- how to retrieve post_id under woocommerce_add_to_cart_validation hook?
- add_option_{$option} action hook not being called
- Function not working on any file other than the main plugin file
- Does WordPress have something like timer hook?
- Multi hook deploiement
- Can I use a hook other than ‘init’ to handle form submissions?
- woocommerce single product page hook not working
- How can I set a dynamic value for post_updated_messages based on return value of post_updated?
- Google does not index data from custom table used for a plugin
- What is the use of wp_schedule_event hook?
- How do I replace title with my plugin?
- Looking for Hook that is fired after a plugin or wp upgrade is installed/updated
- Woocommerce: block user removing cart item
- Insert plugin html content to a specific spot in the frontpage
- get_term_by() returning null on plugin
- Ninja Forms: Front-End Forms, Post ID?
- Execute callback after REST API request completes + Response is sent
- How to customize password reset message page on success if no error in password reset
- Is there a hook for updated image metadata upon using image editor?
- how to execute a function only when i send an order to trash [closed]