add_action
‘s second parameter is a callable
, it can accept a string (like what you did in the example) or an array of class-instance and function name.
For example, if you want to call a method get_age()
from Person
class, you can do this:
$person = new Person();
add_action( 'hook_name', array($person , 'get_age') );
Related Posts:
- Trouble understanding apply_filters()
- How many filter/action hooks are healthy?
- Earliest hook to reliably get $post/$posts
- What does (10, 2) mean when used with add_filter
- Valid characters for actions, hooks and filters
- How to check if a hook is hooked or not?
- How to make post and comment count unclickable with dashboard_glance_items hook
- Hook into admin post list page
- Anyway to edit the titlebar of WordPress Widgets in the Admin area?
- About Hooks and Filters
- Should I use add_action(‘publish_post or add_filter(‘publish_post?
- Please explain me what the do_action does
- Too many actions/filters!
- How to get list of all hooks of current theme / plugin?
- How does WordPress call functions attached to a certain action hook before calling functions attached to other hooks
- Conditionally call add_action depending on post_type?
- Is it possible to track down Actions and Filters?
- When to use actions and when to use filters
- Is possible dequeue/remove style from wp_footer() hook and add on wp_head() hook?
- Same Conditionals Not Working on Two Different Hooks
- add filter login_redirect does not contain original requested redirect
- get_header and hook avoid normal call
- Can the wp_filter object hold multiple values with the same key
- How to change the order (priority) of registered filters (or actions) (e.g. for the_content)?
- apply_filters/do_action tag characters limit
- Filter taxonomy admin pagination
- Insert term when page is published – avoid duplicates after edits
- Capture post content before page renders
- How to remove action with slashes and arrows?
- Changing WordPress core without hacking core
- Comment search plugin
- How can I output all apply_filters and do_action?
- Remove actions/filters that are set with create_function()
- Get The Caller (Plugin / Theme / Core) For All actions & Hook in WordPress
- Remove tags without a specific meta key from “choose from the most used tags”
- How to access page variable inside action hook
- What is the action hook to use if you want to capture the new password during password change?
- Use has_filter on comment_post
- How can I edit comment meta value before it is saved?
- Action hook to control access to certain parts of my site
- Replace Data In Post & Update Meta Field Post Is Saved
- style_loader_tag not changing stylesheet to preload
- Hook to change the site URL
- Hook to add content after date in post?
- Hook inside a hook
- Can you call a filter hook by “add_action”?
- Is there any action filter/hook for validating a custom field before publishing the post?
- Passing Additional Parameters to add_filter Callable
- Modify WordPress Rest Api Request/Response
- How to add some custom HTML into wordpress admin bar?
- Custom theme hooks / filters – passing arguments
- How to hook wp_list_pages?
- How to use the_excerpt in a filter hook?
- Use external link in the add sub menu
- Change WordPress RSS link with filter?
- add_filter() function misunderstanding
- Filter or Hook to catch pre-rendering of post content
- Accepted arguments value in hook functions
- how to determine how many and what kind of arguments are passed to hooks
- Which action hook to use for function?
- Is there a filter called ‘network_admin_init’?
- Modify a function without editing template
- How to modify core when there is no hook?
- Post Content, Special Characters and Filters
- Correct method of redirecting user login
- Better extend a class or use add filter/action hooks?
- Plugin options, presets and filters : can you help me improve my workflow?
- Filter Posts from the Main Query
- how to customize rss feed tags using hooks?
- Filtering the post list in the admin area
- Issue understanding and using WordPress filters and actions
- Woocommerce “added to cart” message on main(home) page
- Wrapping my head around add_filter
- Gutenberg Block – Post Featured Image Filter Hook
- Change custom post type GUID in RSS
- Call to undefined function is_home() or any conditional tags
- How can I specify the post status of an untrashed post?
- filter hook to load a different post/page on current post/page
- Redirect to woocommerce checkout after adding to cart – item already in cart
- Insert Content Before div#main from the functions.php File
- alternative to the_content filter
- What filter or action hook to use in order to load some code before the template begins printing in BuddyPress? [closed]
- Display custom product option in admin order details
- Same URL for portfolio and for a page creates 404 error. Is there any filter that i can use for a child page?
- How do I add a line break to a string that is output by PHP?
- Filter widget_posts_args not working
- Right filter for rewriting page statuscode
- adding an action inside if condition not working
- How to filter wp_get_recent_posts() to only posts that have thumbnails?
- What action/filter can be used for modifying the page to be rendered?
- Adding user filter – Not updating data in URL
- How to check which submission button was clicked?
- check, if any “add_action” function contains string XXXXXXXXX
- How would I remove an inline googleAPI font script in the the parent theme header.php?
- Which hook should be used in this case?
- How to add custom checkout field in user details mail template
- Getting entry ID from frm_email_message filter in formidable
- Auto append text after the title?
- How to use apply_filters(‘get_calendar’) to change get_calendar() output?
- How to elect position of new item output in a dropdown when using add_filter