You can do this:
class testclass {
function test() {
echo 'howdy';
}
}
add_action('wp_head',array('testclass','test'));
Or this:
$t = new testclass();
add_action('wp_head',array($t,'test'));
It doesn’t work like…
$t = new testclass();
add_action('wp_head','t');
// or this either, for good measure
$t = new testclass();
add_action('wp_head',array('t'));
.. but I am not sure what you are trying to accomplish by using that pattern. You’ve already instantiated the class so the constructor, if present, has already ran. Without a callback method, I don’t know what you expect to happen.
Related Posts:
- add_action(), add_filter() before or after function
- Trouble understanding apply_filters()
- What is the very earliest action hook you can call?
- wp_headers vs send_headers. When to use each?
- How many filter/action hooks are healthy?
- Earliest hook to reliably get $post/$posts
- Remove Editor From Homepage
- What does (10, 2) mean when used with add_filter
- Valid characters for actions, hooks and filters
- Advanced Custom Fields and Yoast SEO keyword analysis [closed]
- How to check if a hook is hooked or not?
- Store source permalink on XMLRPC calls
- 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?
- How do I know if author field was changed on post save?
- Using hooks to place content in theme dynamically
- About Hooks and Filters
- PHP5, Inheritance, Singleton – action & filter hook limitations
- Should I use add_action(‘publish_post or add_filter(‘publish_post?
- Please explain me what the do_action does
- Apply the_title filter to post titles AND backend auto social-sharing plugin, but not nav menu
- add_action uses ‘echo’ add_filter uses ‘return’, why?
- changing variable through filters or action hooks
- Too many actions/filters!
- Apply a filter only once
- How to get list of all hooks of current theme / plugin?
- Making a class available via actions filters
- How does WordPress call functions attached to a certain action hook before calling functions attached to other hooks
- How to get current action?
- Conditionally call add_action depending on post_type?
- how to change appearence of the content of default post list columns?
- Anonymous function is executed twice in wp_head while added from the_posts filter?
- Explanation for remove_filter used in the below code [closed]
- How to change the blog title with add_filter? details below
- How To Get User Data in Callback Function for pre_user_nicename?
- What’s the best way to split admin-only functionality in the theme’s functions.php file?
- Filter list by a unique meta value dilemma
- return values from hooks do_action and apply_filters, which is better
- How to get all the predefined do_action() calls from an active theme
- Is it possible to track down Actions and Filters?
- When to use actions and when to use filters
- Return a custom value in a function added to an action hook
- Is possible dequeue/remove style from wp_footer() hook and add on wp_head() hook?
- Same Conditionals Not Working on Two Different Hooks
- How to call a function or method that is Namespaced using another plugin
- How to change currency programmatically on creating order action?
- add filter login_redirect does not contain original requested redirect
- get_header and hook avoid normal call
- Removing an action, or dequeueing style – Both not working
- 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
- Replace a word with a word in the URL string
- Is there a filter called ‘network_admin_init’?
- How to add ‘total’ value to custom column title on the posts list page
- Filter taxonomy admin pagination
- When to use add_action when registering/enqueuing scripts
- Insert term when page is published – avoid duplicates after edits
- Are there actions or filters I can use for Ajax calls?
- Capture post content before page renders
- Correct method of redirecting user login
- Shortcodes — Using add_action, add_filter in the shortcode
- How to remove action with slashes and arrows?
- Can the wordpress color palettes by changed through Javascript?
- How do I use remove_action on an add_action that uses an array?
- How to properly modify WP Vary or any existing headers?
- Changing WordPress core without hacking core
- How to pass variables to custom filter from multiple functions
- Building a request processor for multi-page forms, etc using $_GET requests
- Comment search plugin
- How to customize the “Insert/edit link” popup box?
- Proper after_setup_theme and wp_head cleanup
- How to get a single hook from wp_head()?
- How can I output all apply_filters and do_action?
- How to allow code block in wordpress comments
- Add a filter inside an action init
- remove_action: how to access to a method in an child class?
- Is it possible to apply_filter on a wp_ajax_ action?
- Filter for when the post is updated
- Add a filter to an action [closed]
- How can I specify the post status of an untrashed post?
- Filter get_page_by_path()
- why require – does not load filter
- Remove actions/filters that are set with create_function()
- Get The Caller (Plugin / Theme / Core) For All actions & Hook in WordPress
- Most performant/functional way to add actions/filters?
- Alter existing page contents based on url
- Remove tags without a specific meta key from “choose from the most used tags”
- Add/remove CRON action depending on variable
- How to access page variable inside action hook
- Register new user, assign custom role then send email
- How to include add_filter() in a condition based on $post data
- Admin: how to make a custom list filter button send GET queryvars
- What is the action hook to use if you want to capture the new password during password change?
- Use has_filter on comment_post
- Echo string in admin panel footer beside version no
- How to change default text for specific post type
- How can I edit comment meta value before it is saved?
- Disable sanitize_file_name on upload without modifying functions.php