Make WordPress Core

Ticket #35357: 35357.5.patch

File 35357.5.patch, 2.0 KB (added by andykeith, 5 years ago)

Add did_filter function

  • src/wp-includes/plugin.php

     
    3030/** @var int[] $wp_actions */
    3131global $wp_actions;
    3232
     33/** @var int[] $wp_filters */
     34global $wp_filters;
     35
    3336/** @var string[] $wp_current_filter */
    3437global $wp_current_filter;
    3538
     
    4346        $wp_actions = array();
    4447}
    4548
     49if ( ! isset( $wp_filters ) ) {
     50        $wp_filters = array();
     51}
     52
    4653if ( ! isset( $wp_current_filter ) ) {
    4754        $wp_current_filter = array();
    4855}
     
    161168 * @return mixed The filtered value after all hooked functions are applied to it.
    162169 */
    163170function apply_filters( $hook_name, $value ) {
    164         global $wp_filter, $wp_current_filter;
     171        global $wp_filter, $wp_current_filter, $wp_filters;
    165172
     173        if ( ! isset( $wp_filters[ $tag ] ) ) {
     174                $wp_filters[ $tag ] = 1;
     175        } else {
     176                ++$wp_filters[ $tag ];
     177        }
     178
    166179        $args = func_get_args();
    167180
    168181        // Do 'all' actions first.
     
    209222 * @return mixed The filtered value after all hooked functions are applied to it.
    210223 */
    211224function apply_filters_ref_array( $hook_name, $args ) {
    212         global $wp_filter, $wp_current_filter;
     225        global $wp_filter, $wp_current_filter, $wp_filters;
    213226
     227        if ( ! isset( $wp_filters[ $tag ] ) ) {
     228                $wp_filters[ $tag ] = 1;
     229        } else {
     230                ++$wp_filters[ $tag ];
     231        }
     232
    214233        // Do 'all' actions first.
    215234        if ( isset( $wp_filter['all'] ) ) {
    216235                $wp_current_filter[] = $hook_name;
     
    238257}
    239258
    240259/**
     260 * Retrieve the number of times a filter has been fired.
     261 *
     262 * @param string $tag The name of the filter hook.
     263 * @return int The number of times filter hook $tag is fired.
     264 *
     265 * @global int[] $wp_filters Stores the number of times each filter was triggered.
     266 *
     267 */
     268function did_filter( $tag ) {
     269        global $wp_filters;
     270
     271        if ( ! isset( $wp_filters[ $tag ] ) ) {
     272                return 0;
     273        }
     274
     275        return $wp_filters[ $tag ];
     276}
     277
     278/**
    241279 * Checks if any filter has been registered for a hook.
    242280 *
    243281 * When using the `$callback` argument, this function may return a non-boolean value