Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am working on a plugin and have a problem with my options page that I can't seem to figure out. The options page works just fine, it is setup in my main plugin file like this:

add_options_page('Jargonaut', 'Jargonaut', 'manage_options', 'jargonaut-settings', array($this,'jargonaut_ShowAdmin'));

And then the jargonaut_ShowAdmin() function includes a file called 'jargonaut_admin.php'. No big deal, works great.

I have been developing some stuff on that options page ('jargonaut_admin.php') but the code has been getting fairly large so I decided to break some of the form processing functionality off into a separate file and include() it. My include looks like:

global $wpdb;
include_once('jargonaut_form_process.php');

When I made this change, my options page quit functioning the way I want it to (when submitting forms it just reloaded the page and did nothing else) so I added some echo() functions into 'jargonaut_form_process.php' to see where it was going wrong. Come to find out, it doesn't recognize the WordPress function get_option(). In fact, no WordPress functions work.

Now, they work beautifully if I copy that file's contents back into 'jargonaut_admin.php' and use them there.

TLDR: Why do PHP files included into admin option pages not have access to WordPress functions? What is the proper way to do this or do I have to just keep all the code in the same file?

[UPDATE] Turning on error_reporting(E_ALL|E_STRICT) and setting display_errors to true, I get this:

Fatal error: Call to undefined function get_option() in /home/cillosis/mysites/wordpress/wp-content/plugins/jargonaut/jargonaut_form_process.php on line 15

That line is my first attempt in the jargonaut_form_process.php file to access a WordPress function. I've tried adding global $wp; and global $wpdb; to the top of my included file but that doesn't help either.

share|improve this question

closed as too localized by toscho Jul 30 '12 at 19:43

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, see the FAQ.

1 Answer

Solved.

I'm an idiot. I was doing a jQuery POST request (from my javascript admin file in a folder) to my options page and was calling:

url : '../jargonaut_form_process.php' 

When I should have been calling:

url : '../wp-admin/options-general.php?page=jargonaut-settings'

That explains why I didn't have access to WordPress functions. It doesn't load anything by my file when I do it the way I was. Thanks for viewing and hopefully this helps somebody else down the road.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.