I have this class I created on a theme within a WordPress environment.
class Theme {
function __construct()
{
add_action('after_setup_theme', array(&$this, 'do_this'));
}
function do_this()
{
require_once('helper_functions.php');
}
}
$theme = new Theme();
And within the helper_functions.php I have:
function get_image()
{
return 'working';
}
But now I am puzzled because when I execute this
echo $theme->get_image();
It doesn’t work….But if I called it directly it works like this:
echo get_image();
But I thought since I am using a class method, I need to use the class object to get to a class method…Why am I able to call it directly?
The function
get_image()is not a function set in the classTheme, it is set in a separate file, which is included in the class.If you want it to be a function of the class then you need to write it in the class file, move the code into the class.
Alternative you could make use of class extends
And change the Theme class file to
Alternative
Since you said it was several functions in several files you can do this, either in the Theme class file or in an extended class file.