WordPress.org

Make WordPress Core

Ticket #14994: 14994.diff

File 14994.diff, 1.6 KB (added by Nacin, 9 years ago)

Adds current_action() as a wrapper for current_filter(). Adds doing_action() and doing_filter(). Ignores the call for a counterpart to did_action() for filters (should be a new ticket).

  • wp-includes/plugin.php

     
    301301        return end( $wp_current_filter );
    302302}
    303303
     304/**
     305 * Retrieve the name of the current action.
     306 *
     307 * @since 3.2.0
     308 *
     309 * @return string Hook name of the current action.
     310 */
     311function current_action() {
     312        return current_filter();
     313}
    304314
    305315/**
     316 * Retrieve the name of a filter currently being processed.
     317 *
     318 * The function current_filter() only returns the most recent filter
     319 * or action being executed. did_action() returns true once the action
     320 * is initially processed. This function allows detection for any filter
     321 * currently being executed (despite not being the most recent filter to
     322 * fire, in the case of hooks called from hook callbacsk) to be verified.
     323 *
     324 * @since 3.2.0
     325 * @see current_filter()
     326 * @see did_action()
     327 *
     328 * @param $filter string Filter to check
     329 * @return bool Whether the filter is currently in the stack
     330 */
     331function doing_filter( $filter ) {
     332   global $wp_current_filter;
     333   return in_array( $filter, $wp_current_filter );
     334}
     335
     336/**
     337 * Retrieve the name of an action currently being processed.
     338 *
     339 * @since 3.2.0
     340 * @uses doing_filter()
     341 *
     342 * @param $action string Action to check
     343 * @return bool Whether the action is currently in the stack
     344 */
     345function doing_action( $action ) {
     346   return doing_filter( $action );
     347}
     348
     349/**
    306350 * Hooks a function on to a specific action.
    307351 *
    308352 * Actions are the hooks that the WordPress core launches at specific points