[wp-hackers] Access files inside a plugin directory?
dougal at gunters.org
Tue Mar 23 15:47:10 UTC 2010
On Mar 23 2010 10:18 AM, Jeremy Clarke wrote:
> On Mon, Mar 22, 2010 at 7:38 PM, scribu<scribu at gmail.com> wrote:
>> URL: plugins_url('file_name', __FILE__);
>> PATH: dirname(__FILE__) . '/file_name';
> Is using __FILE__ an accepted practice in WP-land? I have many
> installs where I use symlinks ( ln -s ) to share plugin/theme
> directories between multiple installations, and any use of __file__
> completely screws up file includes in that setup. Most plugins manage
> to avoid it but the ones that use it need to be modified by hand.
> Isn't it presumptive or something? Seems dangerous to have as a best practice.
Well, it presumes that you won't be doing something way-out-of-the-norm,
like symlinking stuff between multiple installs ;)
That said, yeah, using __FILE__ is definitely a pretty common practice.
I suppose we really should all be using something more like:
// Get just the parent directory name of the current file. Path is
$my_plugin_dir_slug = '/' . basename( dirname( __FILE__ ) );
$my_plugin_dir = WP_PLUGIN_DIR . $my_plugin_dir_slug;
$my_plugin_url = WP_PLUGIN_URL . $my_plugin_dir_slug;
Dougal Campbell <dougal at gunters.org>
More information about the wp-hackers