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 … Read more

Conditional Ajax inclusion

I have a custom interface that uses 30+ ajax files while running… some files are only used in category.php while othere’s are only used in page.php… i include the ajax loader php files in my functions.php file example: include TEMPLATEPATH . ‘/ajaxLoops/ajax-open_client_editform.php’; include TEMPLATEPATH . ‘/ajaxLoops/ajax-submit_client_editform.php’; It all works great but when i tried to … Read more

How to pass variables with get_template_part?

I am developing a custom theme and i like to pass some variables to selected files. I am calling the view files from functions.php. $var1 = ; $var2 = ; etc include_once(‘form-views/view-profile.php’);//works //get_template_part(‘includes/form-views/view’,’profile’);//doesn’t work Now with include it works 3 Answers 3 This is essentially scope visibility issue. include brings code into a current scope, … Read more

Why does get_template_part() break variables?

In PHP, when you include a file, the variables you’re using in your current scope are available for use in the included file. When using WordPress’s get_template_part(), variables are no longer available in the “included” file. get_template_part() calls locate_template() which then calls load_template(), which then performs the require or require_once. If WordPress eventually calls PHP’s … Read more

External system integration with wordpress

I’m writing a web/db application. My clients would like authentication based on whether the user is logged into WordPress. Assuming this application is hosted from within /wordpress I would like to be able to: Determine who, if anyone, is logged into WordPress Seems as if it should be possible via wp_get_current_user() but I can’t find … Read more