If I need to register an action inside the class itself would it work with
array($this, 'bar')
?
Yes, it works. $this
Docs is referring to the concrete instance needed for the callback. That’s exactly like the $foo
example you give. It’s just that $this
is bit more special, but it represents basically the same and it works flawlessly with callbacks in PHP.
Additional:
if I have a class foo and a static method bar I can register that as the callback by passing the array
array("foo","bar")
as the function name.
Yes you can do so, for the static function, you can write it as a string instead of the array as well: foo::bar
, see Callbacks Docs. Might be handy.
Related Posts:
- Plugin activation hook in an abstract class
- profile_update hook doesn’t works inside a class
- Plugin: Hooking up classes that have their own hooks
- WordPress Custom Hook with Class method
- OOP Plugin: Where should I place the action hooks in the class?
- Passing a parameter to filter and action functions
- Get a list of all registered actions
- Should all plugins be encapsulated in a Class?
- How can I edit post data before it is saved?
- Why does wp_enqueue_style() in plugin not load stylesheet?
- Preventing a plugin from updating
- Customizing subject in comment notification e-mails
- WP showing “warning: call_user_func_array()”, What to do?
- How do I extend one plugin I’m writing with another I’m writing using classes?
- Adding an admin page – OOP approach not working
- Modify featured image URL at runtime
- scheduled event not getting executed
- Which hook should be used to validate custom form fields on the login form?
- Using the media uploader in a custom plugin
- Hook (upgrader_process_complete) running moment
- Adding dynamic section to WordPress
- why does the add_action(‘the_content’) overwrite my page
- Fatal error: Class not found in
- woocommerce product attributes
- How to filter content post only on save
- Filter or action hook to insert content on admin pages before tag
- Showing Notifications While Activating Plugin
- plugin_action_links_{$plugin_file} hook not in the main plugin file
- merging an array to an existing array using add_filter
- Creating a menu page in a Object Oriented developed plugin
- template_redirect not being called when using ajax
- How to add rewrite rules and pagination to retrieve attachments files?
- Hook before & after plugin / core update
- Plugin custom Action Hook not working
- What are ideal hooks to call register_sidebars?
- AddFilter option_active_plugins is executed 6 times. Why?
- get_plugins() doesn’t work after plugins_loaded
- Hook to generate a dynamic sitemap with “All in One SEO Pack” Plugin
- add_action in functions.php, do_action in plugin?
- How to correctly detect accessing wp-content/uploads?
- Deactivate Plugin on Theme Switch
- Getting user roles in plugin files
- How to pull code snippet from functionality plugin?
- Using a post-signup hook to get user details
- woocommerce_package_rates not fired when wordpress woocommerce accessed as non ajax
- Trigger Elementor Popup via code [closed]
- Most efficient way to use classes to create admin pages using Settings API
- Filtering WooCommerce Orders by Category
- do_action() hook into load-(page)
- Howto check version of another plugin and then add a submenu page to it
- Add sub menu page in your plugin
- how to change automatic placing of social plugins below content?
- Turning on output buffering in a wordpress plugin
- Are there action hooks for comments?
- How to use template_include hook with form submission?
- What are admin hooks
- WooCommerce: after install hook
- How to use filter to disable adding a product to wishlist?
- wp_trash_post hook – problem with page updating if using wp_die
- is it possible to hook every page style?
- Comment Approve – Add custom function when comment is approved
- Add action to custom Function
- Hook on creating a menu entry?
- Prevent plug-in scripts on a specific template?
- using wp_footer hook in a plugin
- Plugin Hook When New Author Added
- Use a hook or filter, or overwrite this Gamipress function?
- Fail on admin_enqueue_scripts when I try it to upload a CSS file to my WordPress Plugin
- How to remove a hook written with $this?
- update_option_{$option} not working (do function after options are saved)
- Alternative Hook to the_content for Changing Background Color
- Unpublished Pages Failing To Appear On Custom Path
- add a hook of Woocommerce to a plugin but it only shows and doesn’t function properly
- save_post hook partly firing in update post
- ACF Fields are not showing up on Homepage
- Hooking into the HTML header container
- Hide WordPress Site URL from Source Code
- Show post object of any page in frontend
- When/where would want to attach other classes to the base class in a WordPress plugin?
- Plugin function in child theme
- Edit plugin’s HTML output with Hooks
- {status}_{post_type} does not run correctly?
- Identify if the_post hook is being called from the admin post list
- Reorganization of namespaces
- Why can’t I shove an instance of a class into a variable from a do_action hook?
- Creating Custom Hook for my plugin
- accessibility of an object created in a plugin, from the header
- Passing a parameter to filter and action functions
- WordPress hook source
- Manually return false for function_exists
- How to `remove_action` from plugin
- Plugin hook breaks new WP 4.0 media library grid view?
- Plugin Hook: Get posts
- Transition Post status not working
- functions.php conditional output for a single plugin
- How to make plugin work in each template in wordpress
- WordPress Hooks : Where to place callbacks that repetitively yield the same effect?
- Suitable hook when creating, updating and deleting posts programmatically
- Change social icon in twenty twenty three theme
- is_user_logged_in() undefined at shutdown in plugin context