I am trying to filter some data based on whether a variable from within the function that calls apply_filters() is equal to specific value. That variable is not passed to the apply_filters() parameters. This might explain what I mean:
// function in wordpress core
function get_var_b() {
// generating $var_a
$var_a = "a";
// some code ...
$var_b = apply_filters('get_var_b', $var_b);
return $bar_b;
}
// in functions.php
add_filter('get_var_b', 'filter_var_b');
function filter_var_b($var_b) {
if ($var_a == "c") {
$var_b = "d";
}
return $var_b;
}
I tried to use global $var_a; inside of my function but with no success. The only way I could access $var_a was by editing the core file and passing $var_a to the apply_filters() function like:
apply_filters('get_var_b', $var_b, $var_a);
Is there a way to access this variable without editing the core file or trying to regenerate $var_a from scratch? Thanks.
EDIT: The filter that I am trying to hook to is dynamic_sidebar_params which is called from dynamic_sidebar() function in wp-includes/widgets.php file. I am trying to change the $params[0]['before_widget'] from <aside> to <nav> IF the $id was equal to categories-2.