<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Nerdaphernalia &#187; paths</title>
	<atom:link href="http://striderweb.com/nerdaphernalia/tag/paths/feed/" rel="self" type="application/rss+xml" />
	<link>http://striderweb.com/nerdaphernalia</link>
	<description>"It's All Geek To Me"</description>
	<lastBuildDate>Wed, 21 Dec 2011 18:51:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Hit a Moving Target in your WordPress Plugin</title>
		<link>http://striderweb.com/nerdaphernalia/2008/09/hit-a-moving-target-in-your-wordpress-plugin/</link>
		<comments>http://striderweb.com/nerdaphernalia/2008/09/hit-a-moving-target-in-your-wordpress-plugin/#comments</comments>
		<pubDate>Wed, 10 Sep 2008 17:54:09 +0000</pubDate>
		<dc:creator>Stephen R</dc:creator>
				<category><![CDATA[Codecraft]]></category>
		<category><![CDATA[Webcraft]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[constants]]></category>
		<category><![CDATA[paths]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://striderweb.com/nerdaphernalia/?p=209</guid>
		<description><![CDATA[In recent changes to WordPress code, users are more than ever able to customize folder and file locations. [Edit: Refers to WordPress 2.6] The wp-config.php file can now be located one directory up from the one containing WordPress. The wp-content folder can be moved arbitrarily, as can (separately) the plugins folder. What&#8217;s a poor plugin [...]]]></description>
			<content:encoded><![CDATA[<p>In recent changes to WordPress code, users are more than ever able to customize folder and file locations.  <span class="update">[Edit: Refers to WordPress 2.6]</span>  The <code>wp-config.php</code> file can now be located one directory up from the one containing WordPress.  The <code>wp-content</code> folder can be moved arbitrarily, as can (separately) the <code>plugins</code> folder.  What&#8217;s a poor plugin author to do in keeping track of these ever-moving targets?</p>
<p>When those last two folders are moved, it is done by defining specific constants: <code>WP_CONTENT_DIR</code> and <code>WP_CONTENT_URL</code> for the <code>wp-content</code> folder, and <code>WP_PLUGIN_DIR</code> and <code>WP_PLUGIN_URL</code> for the <code>plugins</code> folder.  In plugins it&#8217;s best to use these, except that they are not defined in a default setup, and don&#8217;t <em>exist</em> in earlier versions of WordPress.</p>
<p>The solution, fortunately, is simple:  Check if they are already defined.  If they&#8217;re not, then the folders are in the default locations and you can define them accordingly.  Then just use the constants as normal.  Here&#8217;s the code; just drop this somewhere in the beginning of your plugin:</p>
<pre><code>if ( ! defined( 'WP_CONTENT_URL' ) )
	define( 'WP_CONTENT_URL', get_option( 'siteurl' ) . '/wp-content' );
if ( ! defined( 'WP_CONTENT_DIR' ) )
	define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' );
if ( ! defined( 'WP_PLUGIN_URL' ) )
	define( 'WP_PLUGIN_URL', WP_CONTENT_URL. '/plugins' );
if ( ! defined( 'WP_PLUGIN_DIR' ) )
	define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins' );</code></pre>
<p>There are a couple things to note:</p>
<ul>
<li>By defining these, you might actually fix problems in other plugins &#8212; ones that assume these are defined and call them without checking.</li>
<li>I recommend <em>not</em> using the older <code>PLUGINDIR</code> constant at all.  It is both obsolete and problematic.  Use <code>WP_PLUGIN_DIR</code> instead.</li>
<li>You might be tempted to set <code>WP_PLUGIN_DIR</code> as something like <code>dirname(dirname(__FILE__))</code>.  Don&#8217;t.  First, it&#8217;s inefficient, as it unnecessarily calls <code>dirname()</code> twice.  Second, I&#8217;ve seen (albeit unusual) situations where it <a href="#fnote209_1" class="fnotelink">caused problems<sup>*</sup></a>.</li>
</ul>
<p>So.  Not so complicated after all &#8212; it&#8217;s just one of those rote things that&#8217;s helpful to know.  Use those four constants and you shouldn&#8217;t go wrong finding the right paths in WordPress.</p>
<div class="fnote" id="fnote209_1">*: Specifically, a plugin was being shared between two WP installs with a symlink.  Running in the second blog the plugin was calling the directory of the first blog.</div>
<hr />
© <a href="http://striderweb.com/">Stephen Rider</a> 2008
<p>This article was originally published at <a href="http://striderweb.com/nerdaphernalia">Nerdaphernalia</a>.  <a href="http://planetwordpress.planetozh.com/" rel="nofollow">Planet WordPress</a> is authorized to reproduce WordPress-related entries.  <em>If you're reading this at any other web site, the site owner is stealing copyrighted work.  Please visit the original page:</em></p>

<small><a href="http://striderweb.com/nerdaphernalia/2008/09/hit-a-moving-target-in-your-wordpress-plugin/">Permalink to Hit a Moving Target in your WordPress Plugin</a></small>
<p><small>Feed enhanced by <a href='http://planetozh.com/blog/my-projects/wordpress-plugin-better-feed-rss/'>Better Feed</a> from  <a href='http://planetozh.com/blog/'>Ozh</a></small></p>
]]></content:encoded>
			<wfw:commentRss>http://striderweb.com/nerdaphernalia/2008/09/hit-a-moving-target-in-your-wordpress-plugin/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

