Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+1 vote
1.4k views
in Q2A Core by

I have a few (non-Q2A) admin things that I run on my site. I had a basic script set up to hook into Q2A's user-auth functions, so I could simply check my user account (and potentially, other users in the future).

This isn't working in v1.3.3 though. I get an error: qa_register_plugin_module() can only be called from a plugin qa-plugin.php file

My current code (the bit that's causing the problem) is as follows:

define('QA_BASE_DIR', '/siteroot/pokebase/');
require_once QA_BASE_DIR . 'qa-config.php';
require_once QA_BASE_DIR . 'qa-include/qa-base.php';
require_once QA_BASE_DIR . 'qa-include/qa-app-users.php';

 

1 Answer

+1 vote
by
Please try using the code on this page, and let me know if the problem still appears:

http://www.question2answer.org/external.php
by
Ah, skipped over that page. Confused it with the SSO stuff. I'll test it later and let you know :)
by
Just getting back to this now. I tried the code and it still fails with the same error. HOWEVER, this is under CodeIgniter. In a completely independent PHP file it works OK. I am not calling qa_register_plugin_module anywhere in my code though...

Any ideas?
by
qa_register_plugin_module(...) is called by plug-ins as they are registered. This happens in qa-base.php, as part of a loop which sets some global variables. My best guess is that the problem is caused because you're include/require-ing qa-base.php within a function, so even though it assigns some variables in what it thinks is the global scope, it's actually doing so in a local scope. I will aim to fix this issue in the next release. In the meantime, try adding the following line before you require qa-base.php:

global $qa_plugin_directory, $qa_plugin_urltoroot;
by
You're right, I think the "model" include happens in a function, I've noticed problems with scope before. I moved the requires to the controller which also works :)
...