[wp-hackers] Widget Weirdness - Doesn't like the file name widgets.php

Andrew Nacin wp at andrewnacin.com
Tue Jun 28 07:24:13 UTC 2011


On Mon, Jun 27, 2011 at 1:10 PM, John Blackbourn
<johnbillion+wp at gmail.com>wrote:

> On 27 June 2011 17:47, Mike Schinkel <mikeschinkel at newclarity.net> wrote:
> > On Jun 27, 2011, at 10:46 AM, John Blackbourn wrote:
> >>> Your include() line is trying to include the widgets.php file inside
> >>> wp-admin/includes. You should either use a full path in your
> >>> include(), or rename the file.
> >> Sorry, I meant your require_once() line, not include().
> >
> > I've run into that same problem with an export.php file but, for the life
> of me, can't figure out what in PHP is causing "wp-admin/includes" to have
> priority over the current directory?  I'd really like to learn how this
> works so I'll be able to anticipate such problems in the future.  If you or
> anyone else knows, I'd be thankful for an explanation.
>
> From PHP's include() page:
>
> "If the file isn't found in the include_path, include() will finally
> check in the calling script's own directory and the current working
> directory before failing."
>
> This means if you're in WordPress' admin area, wp-admin is the current
> script's directory and will be looked in before the directory the
> plugin file lives in. At least, that's how I've always interpreted it.


Correct. Never rely on include_path. It's slow and obviously not always
going to pull the file you want. All paths should be absolute, ideally. That
means using one of these, as appropriate:

For core, there's ABSPATH, WPINC, WP_CONTENT_DIR, etc. For themes, there's
TEMPLATEPATH and STYLESHEETPATH and various helper functions. For plugins,
there's plugin_dir_path(), which is just an alias for dirname(__FILE__), my
personal preference in general.

... and probably a few others I'm not recalling, depending on your
situation.

Nacin


More information about the wp-hackers mailing list