0

Is there a way to pass a custom variable value from outside like from functions.php to a plugin's variable?

Lets say that I have the following function defined in a plugin.

function plugin_funct(){

 $var1 = 0;
 if(var1 == 0)
 {
    return false;

 }
 else
 {
      echo "Variable passed";

 }

}

Now, is there a way to pass some value to "var1" from functions.php etc? By adding any filter or action? Something like

function passValue()
{
    $var1 = 1;

}
add_filter("plugin_funct", "passValue");

So that we get the "else" condition in the plugin's function "plugin_funct". Possible?

1
  • Why do you need it with such an early timing? There shouldn't be much logic running during functions.php load.
    – Rarst
    Nov 24 '14 at 21:59
0

You can with filter.

On your plugin :

 $value = 0;
 $value = apply_filter('get_value_from_function', $value);

Then on functions.php

add_filter('get_value_from_function', 'my_special_value_treatment', 10, 1);
function my_special_value_treatment ($value){
    return 1;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.