If I need to register an action inside the class itself would it work with
array($this, 'bar')?
Yes, it works. $thisDocs 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?
- How can I see all the actions attached to an “add_action” hook?
- Get plugin_dir_url() from one level deep within plugin
- How to use classes declared in another plugin?
- Changing the “Plugin Activated” Message Default
- Hooking in to plugins
- Generate dormant hook references
- Better to fire specific hooks or generic hooks with parameters?
- How to only hook on Single.php after content?
- How to save the values of checkbox to the register setting?
- Can we hook a static method of a class to add_action inside that class?
- What is the ‘admin_action_’ . $_REQUEST[‘action’] hook used for?
- Filter out results from REST API
- How can I remove a hooked action created by a plugin?
- 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?
- disable active plugins for specific theme
- Twillio How To Send SMS for Custom Post Type
- Hide WordPress Plugin Deactivation Links
- register child class in another plugin
- Find out if request is for custom post type archive before query runs
- Does the ‘nav_menu_css_class’ filter accept 2 or 3 arguments?
- do_action and hook methods
- the_posts hook, which set of posts?
- Is it possible to add an action to the currently running action?
- How to include and use custom class files in plugin?
- OOP: Display warning and deactivate the plugin if PHP version is less than 5.4
- Determine plugin name from within plugin_action_links filter
- How to prevent action in ajax request, when in admin side?
- Easy Digital Downloads (EDD) – Purchase Receipt emails couldn’t be logged
- Placement of Code in Plugin for hooking `save_post`
- Can I use a method from an existing plugin as an action hook?
- Reposition Woocommerce Message
- How to initialize something in unit test before the init hook being called?
- Calling custom plugin class methods from a template
- Prevent a plugin from being automatically activated
- How get a value from a plugin into another plugin through action/filter
- Any hook for pre-plugin-update -either bulk or single plugin update
- plugin class inheritance. cannot change variable
- Modifying the comments section through a plugin regardless of theme
- wp_get_post_terms is difference obj model than the one in rest api response
- Get Time Taken By Each Action Hook in WordPress
- Are functions in main plugin file called before function bound to register_activation_hook runs?
- Best place for short bio,image and button [closed]
- Using plugin functions/methods within templates
- password_reset hook is not working
- The Hook registration_errors was not called
- Hook into existing tinyMCE button
- Object method calling for global $wpdb in header.php
- How to get post ID with hooks publish_post, new_to_publish, etc
- Add sub menu page in your plugin
- how to change automatic placing of social plugins below content?
- Why is my custom post type not being activated on plug-in activation?
- the_post hook is not firing for me
- Deactivate JS Script in Plugin Shortcode
- Plugin Development – Functions or Hooks?
- Adding Plugin Assets to Header
- Add item to the woocommerce dashboard menu from a plugin
- What are admin hooks
- How do I add $_SESSION[”] to my wordpress page?
- How to use filter to disable adding a product to wishlist?
- Built a second plugin but it overwrote the first one
- WordPress: Add custom add_filter for custom functions
- Function added to hook “new_to_publish” not executing – custom plugin
- WordPress Object Oriented plugin development [closed]
- How to access OOP plugin function inside themes or other plugin
- Hook for plugin to insert into entry-meta
- Use a hook or filter, or overwrite this Gamipress function?
- Hook from plugin doesn’t fire up from external PHP script
- Is there a hook similar to “save_post” which only fires AFTER the post is completely published?
- Randomize post (and page) IDs on generation
- save_post hook partly firing in update post
- My plugin runs on every single WordPress page, but I want it to run only on activation
- The function called on the wp head hook becomes null
- Show post object of any page in frontend
- WordPress plugin blog creation
- Use action, filter, or hook to append HTML to WordPress plugin function
- Woocommerce functions in custom class, avoid errors
- Passing function into add_action always returns the first argument
- Hook to display element as product on category page
- Is it possible to disable a theme programmatically?
- plugin not hooking to my custom hook
- wp_login_form() ignoring login_form action hook
- Modify a plugin’s content
- Plugin hook breaks new WP 4.0 media library grid view?
- How do add_action and WP_Query
- Variable scope in plugin outside loop [closed]
- Plugin won’t activate, fatal error (widget class not found)
- Checking url from plugin [duplicate]
- Global Handle to Class unavailable in Plugin?
- User register hook can’t access form request
- WordPress Hooks : Where to place callbacks that repetitively yield the same effect?
- Can’t use updated variables in handle function
- Is it possible to use Classes between WordPress plugins with separate namespaces?
- I have to select text from gutenberg editor. Purpose is to store and replace text
- Similar hook to ‘init’ for when plugin page loads