I've searched almost everywhere, but proposed answers didn't help me.
Problem: I've got a Wordpress installation, last version (3.6.1). I've done a clean install multiple times, looked into the wp-includes/option.php
and other files and I'm pretty sure it all works and all has the correct content.
I'm developing a plugin, and I'm making use of the Wordpress-defined function get_option
. Whenever my code calls that function, I get a 500: internal server error
response. Weird, cause the code of a plugin should be called from within the Wordpress framework...
Make it even more weird: other functions defined in those included files, like add_options_page
, work perfectly and behave like they should.
So, for example, this works:
$pageTitle = "Title for my Options Page";
$menuLink = "Title for my Menu Link";
$userAccessLevel = 8; //that's admin
$pageSlug = "slug-to-my-plugin-options-page";
$callbackFunction = array($this, 'optionsPage');
add_options_page($pageTitle, $menuLink, $userAccessLevel,
$pageSlug, $callbackFunction);
But this doesn't:
get_option("ntp_myoption");
Both add_options_page
and get_option
are defined in source files in the same folder (wp-includes\option.php
and wp-includes\plugin.php
), both functions are effectively in those files, both blocks of code above are in the same file in my plugin, I didn't include or require any file.
Anyone has a clue?
As asked, the full block of code from where I call get_option
- it is from the constructor of my class that wraps the plugin.
function __construct() {
global $wpdb;
$this->table_iso = $wpdb->prefix . "ntp_iso";
$this->pluginUrl = get_option('siteurl') . '/wp-content/plugins/my-plugin';
}
Also maybe worth to mention: I've got a class that wraps the actual plugin, and in the bottom of that .php file, I've got (outside the class definition), this code:
global $tp;
$tp = new MyPlugin();
$plugin = plugin_basename(__FILE__);
register_activation_hook( __FILE__, array($tp, 'install'));
register_deactivation_hook( __FILE__, array($tp, 'deactivate'));
add_action('add_meta_boxes', array($tp, 'init'));
if (is_admin()) {
add_action('admin_menu', array($tp, 'addOptionsPage'));
add_filter("plugin_action_links_$plugin", array($tp, 'addSettingsLink'));
}
These all work like a charm.