1

I making a plugin, and I registered several options in the plugin PHP file. So let's consider :

my-plugin/
   - my-plugin.php (options are registered here)
   - admin.php (the admin page of the plugin)
   - parts/
     conf.php (here I try to get options I registered and used in my plugin)

I tried to perform a get_option() in the conf.php file, but it doesn't seem to work : it returns empty. The option is registered and set in the DB (I checked).

I guess I can't access to WP registered options from that file ? How can I achieve that ?

EDIT : I can have a log of the error :

<b>Fatal error</b>:  Call to undefined function get_option() in <b>conf.php</b> on line <b>6</b>
7
  • How do you access conf.php? Direct request? Is the file required or included? Commented Nov 28, 2014 at 17:01
  • I use require_once on a file on the same level. Then this file is loaded in an Ajax way. Commented Nov 28, 2014 at 17:03
  • But you are in WordPress context, right? Otherwise you'd need to boostrap WordPress. Do you have Debugging turned on? What does var_dump( get_option( 'option_name' ) ) tell you? Commented Nov 28, 2014 at 17:05
  • See my last edit, I guess I'm not in Wordpress context. Commented Nov 28, 2014 at 17:06
  • 2
    Use the AJAX API in WordPress. Commented Nov 28, 2014 at 17:07

1 Answer 1

1

I finally included the external PHP file in a Wordpress function in my plugin PHP file.

function get_conf_function(){

  require_once(dirname(__FILE__) ."/parts/conf.php"); 

}

Now, I can access to wp functions when I call that function (with Ajax or not).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.