[wp-hackers] Best practice: access plugins php files

John Blackbourn johnbillion+wp at gmail.com
Wed Aug 11 01:11:54 UTC 2010


On Wed, Aug 11, 2010 at 1:02 AM, Lox <lox.dev at knc.nc> wrote:
> Should I access it like this:
> wp-content/plugins/myplugin/help.php?field=password ?

No you shouldn't use this because it's possible that a user's plugins
are not stored in wp-content/plugins (see
http://codex.wordpress.org/Determining_Plugin_and_Content_Directories).

I personally use the following to get the location of my plugin:

$plugin_dir = WP_PLUGIN_URL . '/' . basename( dirname( __FILE__ ) );

Then your file would be at:

$plugin_dir . '/help.php?field=password';

but there is a function called plugin_dir_url() which should give you
the same thing. You need to pass it __FILE__ as a parameter. I don't
personally use this because I'm stuck in my old ways and but I assume
it correctly does what I've just told you it does. Sure someone will
correct me if not.

John


More information about the wp-hackers mailing list