Tag Archives: upgrade

The hassle with WP_CONTENT_URL and WP_PLUGIN_DIR

Since WordPress 2.6 it’s possible to move wp-content and the plugins path to a different location. Basically not a bad idea , except the situation that my plugins wordTube / NextGEN Gallery loads some XML/AJAX based “standalone” php files not via the admin page. This means I need to know the location of wp-load.php. In the past I can be sure that my plugin is located always below wp-content/plugins/<plugin name>. So it was easy to get the correct path to wp-load.php

Now this has changed and Ozh show up the new way in his article. In his discussion with GamerZ he added the note to the article :

However, as pointed out by GamerZ in the comments, this still may not work. Why? Because not only the config file may not be there anymore, but the relative path to it may have changed since wp-content might have been moved too.

At this point though, there is no way I can think of to guess the locations of both wp-config and wp-content. To be 100% foolproof, such a “standalone” file needing to include wp-config should be editable so that advanced users moving their wp-content directory could manually edit a location path (the $root variable in the previous example)

I’m currently thinking what would be the best solution. For a intermediate solution I will now add a “config” file where you can add “server path” to wp-load.php in the case you moved the plugin folders. The disadvantage of this solution is the automatic upgrade procedure, because every upgrade wipe out your changes (Mhh, would be not a good idea to have a way to exclude files from the upgrade procedure ??).

Anyway here is the code :

/** Define the server path to the file wp-config here,
if you placed WP-CONTENT outside the classic file structure */

$path  = ''; // It should be end with a trailing slash   

/** That's all, stop editing from here **/

if ( !defined('WP_LOAD_PATH') ) {

 // classic root path
 $classic_root = dirname(dirname(dirname(dirname(__FILE__)))).'/';
 if (file_exists( $classic_root . 'wp-load.php') )
  define( 'WP_LOAD_PATH', $classic_root);
  if (file_exists( $path . 'wp-load.php') )
   define( 'WP_LOAD_PATH', $path);
   exit("Could not find wp-load.php");

// let's load WordPress
require_once( WP_LOAD_PATH . 'wp-load.php');

I’m happy for any comments / ideas for a better solution….

Tagged , ,