2

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?

2
  • may be your $user object isn't created till where you tried to call in header. Commented Jul 2, 2015 at 3:35
  • sounds like a scope issue. Commented Jul 2, 2015 at 4:42

1 Answer 1

1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.