I'm including a Class file in functions.php file
require_once get_template_directory() . "/core/classes/General.php";
require_once get_template_directory() . "/core/classes/User.php";
When I do $user->getCredits($user_id); in some page, it works fine. But when I tried doing that same line of code in header.php it prompts an error of Call to a member function getCredits() on null.
So what I did is I required the same file in header.php, it still gives the same error, when I removed the included file in functions.php the error was removed and the code in header.php works ($user->getCredits($user_id)) but then in normal pages it does not detect the required file.
Any solution for this stuff?
$userobject isn't created till where you tried to call in header.