If this is your own class that you’re doing this for, and can modify it, then you could pass the instance of the class as an addition argument to the filter callbacks:
class Foo {
...constructor, etc.
function to_filter() {
$output="<div class="wrap">";
$output .= $this->another_function();
$output .= more html
return apply_filters( 'to_filter_name', $output, $this );
}
}
function filter_foo( $output, $foo ) {
$output .= $foo->another_function();
return $output;
}
add_filter( 'to_filter_name', 'filter_foo', 10, 2 );
The important part is that 2
in the add_filter()
call. It passes through both arguments to the callback.
Related Posts:
- How to add defer=”defer” tag in plugin javascripts?
- How do filters and hooks really work in PHP
- Trouble understanding apply_filters()
- How would one modify the filtering Gutenberg applies to pasted content?
- Gutenberg: Is there a way to know if current block is inside InnerBlocks?
- How to reorder billing fields in WooCommerce Checkout template? [closed]
- How to add a custom CSS class to core blocks in Gutenberg editor?
- How to add filter with 2 args?
- WordPress Internal @ Mentions
- Filter translations (gettext strings) on specific admin pages
- Is it possible to use object in add_action?
- Filter hook before create order WooCommerce
- Add Class to Specific Paragraph of the_content()
- add_filter for specific pages
- apply_filters() slices away needed arguments
- How to add attribute to output with wp_video_shortcode add_filter
- Search content for shortcodes and get parameters
- How to override the email function by using filters? [closed]
- Remove WPML’s home_url filter
- Change default settings used by gallery shortcode
- PHP5, Inheritance, Singleton – action & filter hook limitations
- Apply the_title filter to post titles AND backend auto social-sharing plugin, but not nav menu
- Add ‘if exists’ to filter
- How to add attributes to tag when template cannot be directly modified
- Edit pagination text in the get_the_posts_pagination function
- How does WordPress call functions attached to a certain action hook before calling functions attached to other hooks
- How to get current action?
- How to check if “media_send_to_editor” is audio?
- Changing Order of Filters
- Please help me through this example with a filter to understand how they work
- how to change appearence of the content of default post list columns?
- Use safety filters even if after applied intval?
- How can I filter block registration based on post-type? (Block alignment settings)
- wp_insert_post_data filter not working correctly after upgrade to WordPress 5
- Modify site URL via functions.php of a theme
- Yoast SEO hooks overriding themselves
- Passing variable from child theme to parent theme
- When adding buttons to the tinyMCE editor, how do I make them wrap to the next line and/or display in the “Kitchen Sink” area?
- How to change the order (priority) of registered filters (or actions) (e.g. for the_content)?
- How to take options from form fields and turn them in to links?
- How to change the order of HTML output of a core block?
- How to add ‘total’ value to custom column title on the posts list page
- How add a group by to the query used by the media library?
- Create Page Template by hook programatically in Functions.php in WP 5.8.1
- How to properly modify WP Vary or any existing headers?
- Filter out comments with certain meta key/s in the admin backend
- HTML and custom field variable, inside variable
- WordPress custom admin notice still displays after wp_insert_post_data validation
- how to use force_filtered_html_on_import in add_filter?
- Filter Hook callback error, is it due to using $this inside a filter or something else?
- Run posts_where and posts_join only on the main query
- Disadvantage of using filters & hooks multiple times
- How To Override A WooCommerce AJAX Function
- Can I override the content array using the_posts filter?
- run shortcode in excerpt of single custom post type
- How to use do_shortcode_tag to modify the output of a shortcode?
- Get The Caller (Plugin / Theme / Core) For All actions & Hook in WordPress
- How to trim white space in search terms?
- Changing the argument of a function
- Alter existing page contents based on url
- Stripping URLs & Email from post submissions
- comment_for() Custom fields not visible when user is logged in
- How to include add_filter() in a condition based on $post data
- I’ve set up an extra field for all the available widgets. How do I show it’s value in the front-end?
- Access post ID in “content_save_pre”
- Remove pretty photo style and script if not exist!
- custom gallery filter with image caption as link title?
- Is this hook really deprecated? ( manage_{$taxonomy}_custom_column )
- BuddyPress – A hook available to hide custom born date on public profile view?
- The gettext hook doesnt work on text with links
- the_content getting current page content instead specified ID
- Custom sort orderby question
- “The editor has encountered an unexpected error” After add defer tag to java script
- Override wordpress audio playlist
- Hook to add content after date in post?
- Create different flavours of excerpt
- Search with filters
- Add Index to Item in WordPress Gallery
- How to add_filter only when content is not empty?
- filter out
- Dealing with the clickTrack event in wp-playlist.js in order to display audio download link on the playlist title row
- Filter template text
- How do I isolate the reason a wordpress filter is not running?
- WP Dashboard -> Posts-> Filter > BUG!
- How to make the show as a button?
- Why this remove empty paragraphs from the_content does not works?
- Take filter from multiple functions
- Read More in the actual excerpt
- WP REST API v2. filters doesn’t work
- Is it possible to include the add_filter() function within a shortcode function
- Activate short codes for all post queries?
- filter on the_content stopped working when I updated to WP 3.6.1
- Replace Paid Shipping Method With Free Shipping Method WooCommerce [duplicate]
- Wrapping Featured Image on Add/Edit Page in div?
- Custom excerpt_more filter not working when tag is present
- Clean/filter HTML inserted to post content by XML RPC
- how to localize the number of wordpress post views?
- Taxonomy search filters
- Is it possible to make get variable out of filter in Class?
- NextGEN Gallery: Adding drop-down menu widget to gallery view without modifying plugin code [closed]