• Okay, I’m writing a plugin (ajax Contact form) and I’m curious why many supporting files report ‘call to undefined function: get_option()’

    What the heck? get_option is a wp global, no? It works in one php file but not in another. I though maybe everything had to be in the root plugin directory else it can’t call globals, but that made no difference either.

    I’ve tried the plugin on my site and locally on my mac using MAMP and they bork at the same php files.

    What gives?

    Sorry if it’s a n00b question, but I’ve googled high and low and have yet to find an answer, and it’s the second project that’s hit the wall because of this error.

    In short: globals work fine except in some files.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Missing an include, perhaps? Using shorthand?

    Thread Starter stimuli

    (@stimuli)

    What sort of include would I need for a plugin script to call global functions?
    Aren’t global functions available across scripts?

    /* Grab our stored default options */
    $acf_subject = get_option('acf_subject');
    $acf_success_msg = get_option('acf_success_msg');
    $yourName = get_option('acf_name');
    $yourEmail = get_option('acf_email');

    What do I need to call get_option(‘blah’) without it breaking? Why does it work in the main script but not sub-scripts?

    Gah! ??

    Thread Starter stimuli

    (@stimuli)

    Okay, as a last ditch effort, I’m posting my ajaxContact plugin code for all of your persual: https://www.stimuli.ca/random/code/ajaxContact_WTF.zip

    If you see any glaring errors, let me know. This isn’t the first time I’ve had this call to undefined function thing happen… it’s hindering my plugins’ development.

    Any help is appreciated. I’m at a total loss. My only strategy now is to put ALL code, js, etc in one, mammoth, confusing php file.

    Thread Starter stimuli

    (@stimuli)

    Alrighty, problem solved. I simply didn’t understand the structure of a plugin.

    I resolved my woes by having all functions in my main plugin file. Other scripts, in the plugin folder, when called independantly, do not share WP’s global functions, nor your main script’s functions. This is why I got errors of function “blah” not found.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘undefined function?!’ is closed to new replies.