WordPress: PHP Fatal error: Call to undefined function get_option()



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:


Both add_options_page and get_option are defined in source files in the same folder (wp-includesoption.php and wp-includesplugin.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.





I suspect wp-includesoption.php is not being loaded.

Just for grins, right before the call to get_options() add


Or try calling something else in option.php like: update_option(null);

option.php is included from inside wp-includes/functions.php while plugin.php gets included in one of several different places.

You can see all the files that are currently included/required by inserting this into your code:

 $includedStuff = get_included_files();

Good Luck!


Facebook Comments

Website Comments

  1. http://networkadvertising.org

    Wօrking as a contract paralegal has factors in its favor, and components that are detrimental to
    some people. If а sense of adventure and pleasure
    in yoսr work lifе is wһat wwould suit you
    the perfect, freelancing mmay very ᴡell bbe an ɑmazing choice for you!

Post a comment