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?
- how to append ACF field data using one of the following filter/ hooks
- Is it possible to switch Gutenberg’s editor styles when document settings change?
- How to filter, restrict and return posts based on custom user meta information
- Reload part of checkout on changed shipping method
- Trying to build simple deposit code that hooks into woocommerce
- User update hook
- Removing “wpautop” (auto tags) only on certain pages?
- `rest_user_query` can’t access post author in post edit screen
- customize_controls_enqueue_scripts doesn’t fire from within my plugin
- use wpml_post_language_details function other plugin based on $post->ID [closed]
- Save User Meta Email Address in Lowercase
- Redirect customer to login page (with other signup plugin) if user not logged in when proceeding to checkout
- Woocommerce: hook action/filter I could use to add variation id and price with each attribute opt on WooCommerce Rest api
- Remove metabox from WordPress menu editor page?
- creat filter with wp_query
- Add a product to checkout via form
- How to use the query hook/filter?
- Post Meta Emtpy on Publish Using Transition
- Add nofollow to custom widget posts
- Change Password Confirmed Email Text
- Footer.php being inserted before article closing tag?
- Calculate price and display on woocommerce product single page under price (simple price, variable price) [closed]
- How to check post type when using sanitize_title hook?
- Get all posts with a duplicate name
- Save acf field data via acf/save_post before post is saved
- Add filter when image is uploaded?
- Why ajax doesn’t work on certain wordpress hooks and reload the page instead?
- Why ajax doesn’t work on certain wordpress hooks?
- Remove the first 5 characters of the_title and orderby that
- How to add custom classes to figure element only if image has caption?
- Is it possible to intercept all ajax requests and get the parameters and the returns?
- Print last modified date only on posts
- Trying to run a compile command while saving post
- user_profile_update_errors hook not executing
- Set meta field to publish date + 2 weeks
- Get Time Taken By Each Action Hook in WordPress
- Error in custom php function doesn’t exist
- How do I trigger a post update within a get_posts() foreach loop?
- Don’t insert if permalink is the same?
- register_activation_hook not updating
- Above-the-fold inline styles from SASS generated stylesheet
- Return a numerical function value in Customizer controls
- Filtering WooCommerce Orders by Category
- Adding widgets to my plugin page instead of WordPress dashboard
- Redirect customer to login if not logged in when proceeding to checkout
- What did I do wrong in my functions code, that will not change the “Get New Password” text to “Send It”?
- Better extend a class or use add filter/action hooks?
- Add content as soon starts
- Duplicate Cron Jobs Using wp_next_scheduled / wp_schedule_event
- Unique icons next to each WordPress menu item
- How to filter the image embed code based on link type
- Add default user field to WooCommerce checkout [closed]
- Adding a hook to the default (page.php) template
- When are wp redirect methods safe to hook?
- Make an array filterable per hook
- Hook when editing user