Hi @Raj Sekharan:
Looks good to me, but is wanting to know the current usage really your question or do you want to understand where current_filter()
gets it’s information from?
If the latter, here’s basically what happens in all the different hook processing functions, e.g. do_action()
, apply_filters()
, do_action_ref_array()
, apply_filters_ref_array()
(greatly simplified, of course):
<?php
function <process_hook>($hook, $value) {
global $wp_filter, $wp_current_filter;
$wp_current_filter[] = $hook; // "Push" the hook onto the stack.
$value = call_user_func($wp_filter[$hook]['function'],$value);
array_pop($wp_current_filter);
return $value;
}
Then all that current_filter()
does is retrieve the last hook “pushed” onto the global wp_current_filter
array, i.e.:
<?php
function current_filter() {
global $wp_current_filter;
return end( $wp_current_filter );
}
Related Posts:
- How to know what functions are hooked to an action/filter?
- Implementing advanced add_* function wrappers
- Change the footer text on the login page
- How can I hook into and edit the text of a wp_nav_menu tag?
- Check if page parent has certain template
- How to remove “out of stock” variation options from size dropdown in woocommerce?
- How to debug removal of rewrite rule flushing?
- Find variables available at a given hook
- hooks & filters and variables
- Getting my head round WordPress filter
- How To Change The Html of Products filtration sidebar in Woocommerce?
- How to set a custom path, for ajax image upload folder in admin?
- Reposition Woocommerce Message
- WooCommerce: Add Payment Gateway Field to Webhooks [closed]
- how to determine how many and what kind of arguments are passed to hooks
- When using the_author hook, how can I determine the PHP file that generates each call to `the_author()`?
- How to call function at the bottom of post using plugin?
- Event Calendar using insert_post_data after save_post and insert_post after post_transition draft_to_schedule
- Handling Body class based on Template
- Strange behaviour with add_{$meta_type}_metadata | add_post_metadata filter
- Edit incorrect password message WordPress
- Contact Fom 7 – how to add custom HTML inside span.wpcf7-form-control-wrap AND IMMEDIATELY AFTER input.wpcf7-form-control?
- Remove a div from RSS feed
- How to add an arrow to menu items has submenus
- WordPress Gravatar filter is removing my custom attributes
- Generating an nonce for Content Security Policy and all scripts – How to make it match/persist for each page load?
- How to have different site identity logos on each page on Astra Theme [closed]
- WordPress: Add custom add_filter for custom functions
- Must filter functions receive all arguments passed to them?
- How to sort WooCommerce products page by latest in-stock items first?
- Use a hook or filter, or overwrite this Gamipress function?
- Filter wordpress posts without searching the keywords in the post content
- Variation prices breakdown only for single product page
- How to edit post meta data before publishing the post it self wordpress?
- Dynamic page for nav items used as filters
- Fatal error: Uncaught Error: Class ‘WP_Block_Styles_Registry’
- using filter and hook inside class
- add_filter() inside another add_filter()
- Add class to all meta boxes for a custom post type
- How to access variables in the function where apply_filters() is called?
- How to add custom checkout field in user details mail template
- For each loop will not append to the_content hook
- Assign new post author IF another user in custom field on post transition
- Is there a hook that I can use when a fatal error occurs?
- Filter specific shortcode output?
- Using register_activation_hook in classes
- trigger save_post event programmatically
- is it possible to get the hook name in add_action?
- How to disable all WordPress emails modularly and programatically?
- WooCommerce: How to display item meta data in email confirmation using woocommerce_order_item_meta_end
- How to properly test a method that is called by an action hook
- Filter all html output
- wp_redirect() not working on form submission with init hook
- Customizing the default logout page of WordPress
- Insert all post IDs in new database table
- WooCommerce – Overwrite action hook [closed]
- Admin Hook at the Login Page
- How to add numeric slug for child page in WordPress 5.9?
- Custom action on login and “remember me”
- Prevent a plugin from being automatically activated
- wp_loaded hook block script enquequing
- Change the site tagline (or similar) based on current page
- Hook when new CPT published AND postmeta inserted
- Query categories that have a description
- Gutenberg – Add align controls to a custom block
- creat filter with wp_query
- Action hook for custom tax edit
- Remove an action by extending class and replacing it
- Insert HTML in post, below nav bar but above content?
- Convert Gravity Form Entry Date on Export
- How to add content to suscriptor dashboard frontend?
- How to append to an array and return the results in a filter?
- Redirect no product url’s to static url
- Add PHP code to header section from plugin
- How to change a WordPress term’s slug before saving
- What hook should I use that will fire whenever I open a post for editing in the WP back-end?
- How to access page variable inside action hook
- Hook in a sidebar widget and add some markup
- Is there a author_update action?
- Catch and display error on save_post action
- ‘manage_users_custom_column’ is a filter, but ‘manage_posts_custom_column’ is an action. Why?
- Scanning for custom embed and prefetching
- How to hide a category or tag everywhere EXCEPT for use with get_posts
- Remove and replace woocommerce add to cart button [closed]
- Hook to change the site URL
- remove_action not working for a function
- What hook should I use to add post meta data with on update?
- WordPress Ajax filter: Create two loops for different output styles?
- Hook into all password resets in WordPress and get password before hashing?
- Converting restricted html in comments to bbcode
- Limit Taxonomy Parents
- WordPress HTML Helper
- Using actions, hooks and filters in a non-WordPress page
- Hook into create_category
- Trouble adding data to options table
- $GLOBALS & global doesn’t work [closed]
- Hooks not working on live server
- How to pass value to add_filter wpcf7_form_tag from another function?
- How can I get the ID before after_setup_theme?
- Hook on opening a media/document