I am adding theme options to Wordpress and I have a Theme_Options
class for this.
Inside the class I have get_field($field)
method to grab the theme option.
I would like to create a function so I can use in the WordPress Theme that I am building to grab the theme option, but I do not want to use global variable.
class Theme_options
{
public function __construct()
{
}
public function get_field($field)
{
// logic to get the theme option
return $field;
}
}
Right now I need to use global $Theme_Options
to create get_field()
function.
$Theme_Options = new Theme_Options();
function get_field($field) {
global $Theme_Options
return $Theme_Options->get_field($field);
}
How can I create get_field()
function without using global variable inside that function?