# Include Class File in Wordpress

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?

• may be your $user object isn't created till where you tried to call in header. – Karun Jul 2 '15 at 3:35 • sounds like a scope issue. – Milo Jul 2 '15 at 4:42 ## 1 Answer Please clarify where you initiate the object$user in both ways (function.php and header.php).

This is another thread on stack with similar kind of issue, have a look:

Organizing Code in your WordPress Theme's functions.php File?

Thanks, Vee