apply_filters_ref_array

The timeline below displays how wordpress function apply_filters_ref_array has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.1

/**
 * Calls the callback functions that have been added to a filter hook, specifying arguments in an array.
 *
 * @since 3.0.0
 *
 * @see apply_filters() This function is identical, but the arguments passed to the
 *                      functions hooked to `$hook_name` are supplied using an array.
 *
 * @global WP_Hook[] $wp_filter         Stores all of the filters and actions.
 * @global int[]     $wp_filters        Stores the number of times each filter was triggered.
 * @global string[]  $wp_current_filter Stores the list of current filters with the current one last.
 *
 * @param string $hook_name The name of the filter hook.
 * @param array  $args      The arguments supplied to the functions hooked to `$hook_name`.
 * @return mixed The filtered value after all hooked functions are applied to it.
 */
function apply_filters_ref_array($hook_name, $args)
{
    global $wp_filter, $wp_filters, $wp_current_filter;
    if (!isset($wp_filters[$hook_name])) {
        $wp_filters[$hook_name] = 1;
    } else {
        ++$wp_filters[$hook_name];
    }
    // Do 'all' actions first.
    if (isset($wp_filter['all'])) {
        $wp_current_filter[] = $hook_name;
        $all_args = func_get_args();
        // phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.NeedsInspection
        _wp_call_all_hook($all_args);
    }
    if (!isset($wp_filter[$hook_name])) {
        if (isset($wp_filter['all'])) {
            array_pop($wp_current_filter);
        }
        return $args[0];
    }
    if (!isset($wp_filter['all'])) {
        $wp_current_filter[] = $hook_name;
    }
    $filtered = $wp_filter[$hook_name]->apply_filters($args[0], $args);
    array_pop($wp_current_filter);
    return $filtered;
}

WordPress Version: 5.8

/**
 * Calls the callback functions that have been added to a filter hook, specifying arguments in an array.
 *
 * @since 3.0.0
 *
 * @see apply_filters() This function is identical, but the arguments passed to the
 *                      functions hooked to `$hook_name` are supplied using an array.
 *
 * @global WP_Hook[] $wp_filter         Stores all of the filters and actions.
 * @global string[]  $wp_current_filter Stores the list of current filters with the current one last.
 *
 * @param string $hook_name The name of the filter hook.
 * @param array  $args      The arguments supplied to the functions hooked to `$hook_name`.
 * @return mixed The filtered value after all hooked functions are applied to it.
 */
function apply_filters_ref_array($hook_name, $args)
{
    global $wp_filter, $wp_current_filter;
    // Do 'all' actions first.
    if (isset($wp_filter['all'])) {
        $wp_current_filter[] = $hook_name;
        $all_args = func_get_args();
        // phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.NeedsInspection
        _wp_call_all_hook($all_args);
    }
    if (!isset($wp_filter[$hook_name])) {
        if (isset($wp_filter['all'])) {
            array_pop($wp_current_filter);
        }
        return $args[0];
    }
    if (!isset($wp_filter['all'])) {
        $wp_current_filter[] = $hook_name;
    }
    $filtered = $wp_filter[$hook_name]->apply_filters($args[0], $args);
    array_pop($wp_current_filter);
    return $filtered;
}

WordPress Version: 5.6

/**
 * Calls the callback functions that have been added to a filter hook, specifying arguments in an array.
 *
 * @since 3.0.0
 *
 * @see apply_filters() This function is identical, but the arguments passed to the
 * functions hooked to `$tag` are supplied using an array.
 *
 * @global WP_Hook[] $wp_filter         Stores all of the filters and actions.
 * @global string[]  $wp_current_filter Stores the list of current filters with the current one last.
 *
 * @param string $tag  The name of the filter hook.
 * @param array  $args The arguments supplied to the functions hooked to $tag.
 * @return mixed The filtered value after all hooked functions are applied to it.
 */
function apply_filters_ref_array($tag, $args)
{
    global $wp_filter, $wp_current_filter;
    // Do 'all' actions first.
    if (isset($wp_filter['all'])) {
        $wp_current_filter[] = $tag;
        $all_args = func_get_args();
        // phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.NeedsInspection
        _wp_call_all_hook($all_args);
    }
    if (!isset($wp_filter[$tag])) {
        if (isset($wp_filter['all'])) {
            array_pop($wp_current_filter);
        }
        return $args[0];
    }
    if (!isset($wp_filter['all'])) {
        $wp_current_filter[] = $tag;
    }
    $filtered = $wp_filter[$tag]->apply_filters($args[0], $args);
    array_pop($wp_current_filter);
    return $filtered;
}

WordPress Version: 5.5

/**
 * Calls the callback functions that have been added to a filter hook, specifying arguments in an array.
 *
 * @since 3.0.0
 *
 * @see apply_filters() This function is identical, but the arguments passed to the
 * functions hooked to `$tag` are supplied using an array.
 *
 * @global array $wp_filter         Stores all of the filters and actions.
 * @global array $wp_current_filter Stores the list of current filters with the current one last.
 *
 * @param string $tag  The name of the filter hook.
 * @param array  $args The arguments supplied to the functions hooked to $tag.
 * @return mixed The filtered value after all hooked functions are applied to it.
 */
function apply_filters_ref_array($tag, $args)
{
    global $wp_filter, $wp_current_filter;
    // Do 'all' actions first.
    if (isset($wp_filter['all'])) {
        $wp_current_filter[] = $tag;
        $all_args = func_get_args();
        // phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.NeedsInspection
        _wp_call_all_hook($all_args);
    }
    if (!isset($wp_filter[$tag])) {
        if (isset($wp_filter['all'])) {
            array_pop($wp_current_filter);
        }
        return $args[0];
    }
    if (!isset($wp_filter['all'])) {
        $wp_current_filter[] = $tag;
    }
    $filtered = $wp_filter[$tag]->apply_filters($args[0], $args);
    array_pop($wp_current_filter);
    return $filtered;
}

WordPress Version: 5.4

/**
 * Calls the callback functions that have been added to a filter hook, specifying arguments in an array.
 *
 * @since 3.0.0
 *
 * @see apply_filters() This function is identical, but the arguments passed to the
 * functions hooked to `$tag` are supplied using an array.
 *
 * @global array $wp_filter         Stores all of the filters and actions.
 * @global array $wp_current_filter Stores the list of current filters with the current one last.
 *
 * @param string $tag  The name of the filter hook.
 * @param array  $args The arguments supplied to the functions hooked to $tag.
 * @return mixed The filtered value after all hooked functions are applied to it.
 */
function apply_filters_ref_array($tag, $args)
{
    global $wp_filter, $wp_current_filter;
    // Do 'all' actions first.
    if (isset($wp_filter['all'])) {
        $wp_current_filter[] = $tag;
        $all_args = func_get_args();
        _wp_call_all_hook($all_args);
    }
    if (!isset($wp_filter[$tag])) {
        if (isset($wp_filter['all'])) {
            array_pop($wp_current_filter);
        }
        return $args[0];
    }
    if (!isset($wp_filter['all'])) {
        $wp_current_filter[] = $tag;
    }
    $filtered = $wp_filter[$tag]->apply_filters($args[0], $args);
    array_pop($wp_current_filter);
    return $filtered;
}

WordPress Version: 5.3

/**
 * Calls the callback functions that have been added to a filter hook, specifying arguments in an array.
 *
 * @since 3.0.0
 *
 * @see apply_filters() This function is identical, but the arguments passed to the
 * functions hooked to `$tag` are supplied using an array.
 *
 * @global array $wp_filter         Stores all of the filters
 * @global array $wp_current_filter Stores the list of current filters with the current one last
 *
 * @param string $tag  The name of the filter hook.
 * @param array  $args The arguments supplied to the functions hooked to $tag.
 * @return mixed The filtered value after all hooked functions are applied to it.
 */
function apply_filters_ref_array($tag, $args)
{
    global $wp_filter, $wp_current_filter;
    // Do 'all' actions first
    if (isset($wp_filter['all'])) {
        $wp_current_filter[] = $tag;
        $all_args = func_get_args();
        _wp_call_all_hook($all_args);
    }
    if (!isset($wp_filter[$tag])) {
        if (isset($wp_filter['all'])) {
            array_pop($wp_current_filter);
        }
        return $args[0];
    }
    if (!isset($wp_filter['all'])) {
        $wp_current_filter[] = $tag;
    }
    $filtered = $wp_filter[$tag]->apply_filters($args[0], $args);
    array_pop($wp_current_filter);
    return $filtered;
}

WordPress Version: 4.7

/**
 * Execute functions hooked on a specific filter hook, specifying arguments in an array.
 *
 * @since 3.0.0
 *
 * @see apply_filters() This function is identical, but the arguments passed to the
 * functions hooked to `$tag` are supplied using an array.
 *
 * @global array $wp_filter         Stores all of the filters
 * @global array $wp_current_filter Stores the list of current filters with the current one last
 *
 * @param string $tag  The name of the filter hook.
 * @param array  $args The arguments supplied to the functions hooked to $tag.
 * @return mixed The filtered value after all hooked functions are applied to it.
 */
function apply_filters_ref_array($tag, $args)
{
    global $wp_filter, $wp_current_filter;
    // Do 'all' actions first
    if (isset($wp_filter['all'])) {
        $wp_current_filter[] = $tag;
        $all_args = func_get_args();
        _wp_call_all_hook($all_args);
    }
    if (!isset($wp_filter[$tag])) {
        if (isset($wp_filter['all'])) {
            array_pop($wp_current_filter);
        }
        return $args[0];
    }
    if (!isset($wp_filter['all'])) {
        $wp_current_filter[] = $tag;
    }
    $filtered = $wp_filter[$tag]->apply_filters($args[0], $args);
    array_pop($wp_current_filter);
    return $filtered;
}

WordPress Version: 4.5

/**
 * Execute functions hooked on a specific filter hook, specifying arguments in an array.
 *
 * @since 3.0.0
 *
 * @see apply_filters() This function is identical, but the arguments passed to the
 * functions hooked to `$tag` are supplied using an array.
 *
 * @global array $wp_filter         Stores all of the filters
 * @global array $merged_filters    Merges the filter hooks using this function.
 * @global array $wp_current_filter Stores the list of current filters with the current one last
 *
 * @param string $tag  The name of the filter hook.
 * @param array  $args The arguments supplied to the functions hooked to $tag.
 * @return mixed The filtered value after all hooked functions are applied to it.
 */
function apply_filters_ref_array($tag, $args)
{
    global $wp_filter, $merged_filters, $wp_current_filter;
    // Do 'all' actions first
    if (isset($wp_filter['all'])) {
        $wp_current_filter[] = $tag;
        $all_args = func_get_args();
        _wp_call_all_hook($all_args);
    }
    if (!isset($wp_filter[$tag])) {
        if (isset($wp_filter['all'])) {
            array_pop($wp_current_filter);
        }
        return $args[0];
    }
    if (!isset($wp_filter['all'])) {
        $wp_current_filter[] = $tag;
    }
    // Sort
    if (!isset($merged_filters[$tag])) {
        ksort($wp_filter[$tag]);
        $merged_filters[$tag] = true;
    }
    reset($wp_filter[$tag]);
    do {
        foreach ((array) current($wp_filter[$tag]) as $the_) {
            if (!is_null($the_['function'])) {
                $args[0] = call_user_func_array($the_['function'], array_slice($args, 0, (int) $the_['accepted_args']));
            }
        }
    } while (next($wp_filter[$tag]) !== false);
    array_pop($wp_current_filter);
    return $args[0];
}

WordPress Version: 4.1

/**
 * Execute functions hooked on a specific filter hook, specifying arguments in an array.
 *
 * @see 3.0.0
 *
 * @see apply_filters() This function is identical, but the arguments passed to the
 * functions hooked to `$tag` are supplied using an array.
 *
 * @global array $wp_filter         Stores all of the filters
 * @global array $merged_filters    Merges the filter hooks using this function.
 * @global array $wp_current_filter Stores the list of current filters with the current one last
 *
 * @param string $tag  The name of the filter hook.
 * @param array  $args The arguments supplied to the functions hooked to $tag.
 * @return mixed The filtered value after all hooked functions are applied to it.
 */
function apply_filters_ref_array($tag, $args)
{
    global $wp_filter, $merged_filters, $wp_current_filter;
    // Do 'all' actions first
    if (isset($wp_filter['all'])) {
        $wp_current_filter[] = $tag;
        $all_args = func_get_args();
        _wp_call_all_hook($all_args);
    }
    if (!isset($wp_filter[$tag])) {
        if (isset($wp_filter['all'])) {
            array_pop($wp_current_filter);
        }
        return $args[0];
    }
    if (!isset($wp_filter['all'])) {
        $wp_current_filter[] = $tag;
    }
    // Sort
    if (!isset($merged_filters[$tag])) {
        ksort($wp_filter[$tag]);
        $merged_filters[$tag] = true;
    }
    reset($wp_filter[$tag]);
    do {
        foreach ((array) current($wp_filter[$tag]) as $the_) {
            if (!is_null($the_['function'])) {
                $args[0] = call_user_func_array($the_['function'], array_slice($args, 0, (int) $the_['accepted_args']));
            }
        }
    } while (next($wp_filter[$tag]) !== false);
    array_pop($wp_current_filter);
    return $args[0];
}

WordPress Version: 4.0

/**
 * Execute functions hooked on a specific filter hook, specifying arguments in an array.
 *
 * @see apply_filters() This function is identical, but the arguments passed to the
 * functions hooked to <tt>$tag</tt> are supplied using an array.
 *
 * @since 3.0.0
 *
 * @global array $wp_filter         Stores all of the filters
 * @global array $merged_filters    Merges the filter hooks using this function.
 * @global array $wp_current_filter Stores the list of current filters with the current one last
 *
 * @param string $tag  The name of the filter hook.
 * @param array  $args The arguments supplied to the functions hooked to $tag.
 * @return mixed The filtered value after all hooked functions are applied to it.
 */
function apply_filters_ref_array($tag, $args)
{
    global $wp_filter, $merged_filters, $wp_current_filter;
    // Do 'all' actions first
    if (isset($wp_filter['all'])) {
        $wp_current_filter[] = $tag;
        $all_args = func_get_args();
        _wp_call_all_hook($all_args);
    }
    if (!isset($wp_filter[$tag])) {
        if (isset($wp_filter['all'])) {
            array_pop($wp_current_filter);
        }
        return $args[0];
    }
    if (!isset($wp_filter['all'])) {
        $wp_current_filter[] = $tag;
    }
    // Sort
    if (!isset($merged_filters[$tag])) {
        ksort($wp_filter[$tag]);
        $merged_filters[$tag] = true;
    }
    reset($wp_filter[$tag]);
    do {
        foreach ((array) current($wp_filter[$tag]) as $the_) {
            if (!is_null($the_['function'])) {
                $args[0] = call_user_func_array($the_['function'], array_slice($args, 0, (int) $the_['accepted_args']));
            }
        }
    } while (next($wp_filter[$tag]) !== false);
    array_pop($wp_current_filter);
    return $args[0];
}

WordPress Version: 3.9

/**
 * Execute functions hooked on a specific filter hook, specifying arguments in an array.
 *
 * @see apply_filters() This function is identical, but the arguments passed to the
 * functions hooked to <tt>$tag</tt> are supplied using an array.
 *
 * @since 3.0.0
 * @global array $wp_filter Stores all of the filters
 * @global array $merged_filters Merges the filter hooks using this function.
 * @global array $wp_current_filter stores the list of current filters with the current one last
 *
 * @param string $tag The name of the filter hook.
 * @param array $args The arguments supplied to the functions hooked to <tt>$tag</tt>
 * @return mixed The filtered value after all hooked functions are applied to it.
 */
function apply_filters_ref_array($tag, $args)
{
    global $wp_filter, $merged_filters, $wp_current_filter;
    // Do 'all' actions first
    if (isset($wp_filter['all'])) {
        $wp_current_filter[] = $tag;
        $all_args = func_get_args();
        _wp_call_all_hook($all_args);
    }
    if (!isset($wp_filter[$tag])) {
        if (isset($wp_filter['all'])) {
            array_pop($wp_current_filter);
        }
        return $args[0];
    }
    if (!isset($wp_filter['all'])) {
        $wp_current_filter[] = $tag;
    }
    // Sort
    if (!isset($merged_filters[$tag])) {
        ksort($wp_filter[$tag]);
        $merged_filters[$tag] = true;
    }
    reset($wp_filter[$tag]);
    do {
        foreach ((array) current($wp_filter[$tag]) as $the_) {
            if (!is_null($the_['function'])) {
                $args[0] = call_user_func_array($the_['function'], array_slice($args, 0, (int) $the_['accepted_args']));
            }
        }
    } while (next($wp_filter[$tag]) !== false);
    array_pop($wp_current_filter);
    return $args[0];
}

WordPress Version: 3.7

/**
 * Execute functions hooked on a specific filter hook, specifying arguments in an array.
 *
 * @see apply_filters() This function is identical, but the arguments passed to the
 * functions hooked to <tt>$tag</tt> are supplied using an array.
 *
 * @package WordPress
 * @subpackage Plugin
 * @since 3.0.0
 * @global array $wp_filter Stores all of the filters
 * @global array $merged_filters Merges the filter hooks using this function.
 * @global array $wp_current_filter stores the list of current filters with the current one last
 *
 * @param string $tag The name of the filter hook.
 * @param array $args The arguments supplied to the functions hooked to <tt>$tag</tt>
 * @return mixed The filtered value after all hooked functions are applied to it.
 */
function apply_filters_ref_array($tag, $args)
{
    global $wp_filter, $merged_filters, $wp_current_filter;
    // Do 'all' actions first
    if (isset($wp_filter['all'])) {
        $wp_current_filter[] = $tag;
        $all_args = func_get_args();
        _wp_call_all_hook($all_args);
    }
    if (!isset($wp_filter[$tag])) {
        if (isset($wp_filter['all'])) {
            array_pop($wp_current_filter);
        }
        return $args[0];
    }
    if (!isset($wp_filter['all'])) {
        $wp_current_filter[] = $tag;
    }
    // Sort
    if (!isset($merged_filters[$tag])) {
        ksort($wp_filter[$tag]);
        $merged_filters[$tag] = true;
    }
    reset($wp_filter[$tag]);
    do {
        foreach ((array) current($wp_filter[$tag]) as $the_) {
            if (!is_null($the_['function'])) {
                $args[0] = call_user_func_array($the_['function'], array_slice($args, 0, (int) $the_['accepted_args']));
            }
        }
    } while (next($wp_filter[$tag]) !== false);
    array_pop($wp_current_filter);
    return $args[0];
}