Yes, you can do this like that.
You can call foo_init_setup
on init
or on wp
hook and it will work just fine.
I would call it as late as possible, I guess. This way you won’t affect loading time for requests that don’t end with page rendering (for example when template_redirect
is used for redirecting).
PS. There is much bigger problem with your code, though. You create custom table and store only one row with serialized array containing options for your plugin.
It would be much nicer, if you used Options API.
Related Posts:
- 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?
- WP Rest API: details of latest post including featured media url in one request?
- How do I exclude plugins from getting automatically updated?
- Where is the best place to use add_filter
- How to delete all records from or empty a custom database table?
- dbDelta only creates the last table
- How to only hook on Single.php after content?
- How To Determine If A Filter Is Called In A Sidebar/Widget Context?
- Change Page’s Tag Using functions.php File
- What characters are allowed as a shortcode tag and how should they be sanitized?
- How to disable Gutenberg editor?
- Edit plugin without hooks in functions.php
- Is their any way to Extend WPDB class and Overwrite the Default Query Function
- How to remove filter added by another plugin in a class
- WordPress apply_filters() Arguments Missing
- plugin_action_links Filter Hook Deprecated?
- No result after wpdb->insert
- Override filter variable not working
- Remove action added in plugin class from theme
- Customize plugin templates
- Show custom taxonomy in theme
- How to fix slow comment query?
- Using multi-dimensional array with filter
- ACF Taxonomy search on backend (Relationship field)
- Help needed with woocommerce (wc stripe) filter
- What action or filter can I use to change all the html returned from server for a page?
- Can I add content before post content without using the_content filter
- WordPress Add advertising ads befor and after content with periority [closed]
- Why can’t I shove an instance of a class into a variable from a do_action hook?
- Edit plugin filter
- Add Filter to get_next_posts_link
- Passing a parameter to filter and action functions
- trying to create simple plugin to filter categories from all authors
- Jetpack Comments Change Placeholder Text
- shortcode which is introduced into entry the blog, and appears in side bar
- How do i get all author posts on custom post type list
- How to filter a a variable in a plugin’s function?
- Write mysql credentials in plugin
- Retrive images from the_content()
- Action hook “wp_insert_post” works but not for last imported post
- passing ‘&’ in return function of add_filter
- Filter the HTML content of plugin
- apply_filters to content but ignore shortcodes
- Use of apply_filter in plugin/widget class
- change output location of plugin function using a custom hook
- Proper way to trigger a MySQL query via link in a plugin
- getpost content with all formatting for admin pages
- Filter for modifying image on upload
- making a glossary with wordpress
- Adding a Filter to Sidbar Login Plugin to Change Login Button Lable
- get_var result empty for query of custom table in plugin admin
- Strip shortcode from excerpt [duplicate]
- Which filters or actions involve with index page for plugin?
- How to add different CSS for galleries
- County Finder form/plugin?
- Simply Exclude – Category feed exclusion is excluding from category feed instead of just the main feed
- Add a filter to a different custom plugin
- Making plugin to use different table prefix cause permission problem
- How to change response of admin-ajax request?
- add query string to all pages after user logged in
- How to add a filter conditionally based on page related Conditional Tags
- Is it safe to increase/alter the size of the wp_post.guid column from VARCHAR(255) to VARCHAR(2048)?
- WP Members additional fields on user profile [closed]
- WordPress plugin add_filter returning a link does not work. What is the correct way?
- Get all the related data from WordPress DB
- $wpdb selects wrong database
- How to dispaly post informations (such as titles) in an admin plugin menu page?
- Order shipped by which driver[hook for woocoomerce order staus changed and popup in admin panel ] [closed]
- Which action/filter can i use for a Member Plugin [closed]
- FATAL ERROR: WP complains about redeclaration [closed]
- Unable to pass arguments from plugin form to filter hook using ajax, the data is transferring via ajax but unable to pass as arguments in filter hooks
- How to Add Extra Text In WordPress Title Before Post Publish
- How often should I execute add_filter and function declaration in Code Snippets?
- How to add product thumbnail on orders list on backend?
- Custom priority with the_content filter based on user input
- filter just a portion of plugin function
- WordPress REST API filter on blank custom ACF
- Selectively override Easy Digital Downloads protection via filter
- How to check record is exist or not in WordPress CRUD Operation with $wpdb
- Brands Filter Not Working For On Sale Products
- Deactivated a plugin with a filter, but it still enqueues JS files
- FacetWP custom display based on post type [closed]
- Change social icon in twenty twenty three theme
- Removing filters with arguments set in a class
- wp db request without refreshing the page
- is_singular() in mu-plugins not working
- Remove wpseo filter from polylang plugin
- WooCommerce Attribute Mapping
- How can we extent core/group or cover block?
- Hide attributes based on previous selection
- Customize WP Filter Hook
- wp_head filter not executed inside custom class
- What is the best way to ignore wordpress administration using add_filter($title) also when Ajax request
- remove filter added by plugin with anonymous function
- How to display title, description etc in block images?
- Possible to overwrite load_template function in plugin using functions.php
- How to customize WP_Error (REST JWT authentication plugin) [closed]
- How to create a dynamically created page on wordpress plugin?