There is three way to use function.php
file variable into plugin file.
Using global. Make sure you globalize it first.
global $my_variable;
echo $my_variable;
I recommend is using WordPress built-in filter mechanism add_filter. You add the filter in your functions.php
file and apply it where needed.
In functions.php
:
add_filter( 'my_variable', 'return_my_variable' );
function return_my_variable( $arg = '' ) {
return '111221122';
}
Now you can use in your plugin files:
echo apply_filters( 'my_variable', '' );
- Use an action hook add_action
In functions.php
:
add_action( 'my_variable', 'echo_my_variable' );
function echo_my_variable() {
echo '888998899';
}
In your plugin files:
do_action( 'my_variable' );
Again, I recommend a filter because it can return a value. This is far more flexible than injecting echo calls in your plugin file. Whether you use an action hook or a filter is entirely up to you.