wp-load.php – I Will Find You!

This is probably the most comprehensive (convoluted) way to load wp-config.php and wp-load.php I’ve ever encountered. There is no reason (except in rare cases) a plugin should be loading these files.

Usually plugins (or themes) will load these core files because they’re trying to access WordPress core functions that are unavailable to them, but this usually only happens when the code that is needing these functions is loaded improperly in the first place. This is often done with forms; the action attribute will be set to the URL of a PHP “processing” file, and inside of that file the developer wants access to core WordPress functions and so must load wp-load.php.

If you are processing a form, it is much better to process it via a function that is connected to the “init” (or similar) hook. By doing that, you completely alleviate the need to load these files., and you get rid of some really crappy code.

/*
if(file_exists('../../../wp-config.php')) {
	require_once("../../../wp-config.php");
} else if(file_exists('../../wp-config.php')) {
	require_once("../../wp-config.php");
} else if(file_exists('../wp-config.php')) {
	require_once("../wp-config.php");
} else if(file_exists('wp-config.php')) {
	require_once("wp-config.php");
} else if(file_exists('../../../../wp-config.php')) {
	require_once("../../../../wp-config.php");
} else if(file_exists('../../../../wp-config.php')) {
	require_once("../../../../wp-config.php");
} else {
	echo '<p>Cannnot find wp-config.php. Maybe a config error with "custom download url" setting.</p>';
	exit;
}
*/
	
if(file_exists('../../../wp-load.php')) {
	require_once("../../../wp-load.php");
} else if(file_exists('../../wp-load.php')) {
	require_once("../../wp-load.php");
} else if(file_exists('../wp-load.php')) {
	require_once("../wp-load.php");
} else if(file_exists('wp-load.php')) {
	require_once("wp-load.php");
} else if(file_exists('../../../../wp-load.php')) {
	require_once("../../../../wp-load.php");
} else if(file_exists('../../../../wp-load.php')) {
	require_once("../../../../wp-load.php");
} else {

	if(file_exists('../../../wp-config.php')) {
		require_once("../../../wp-config.php");
	} else if(file_exists('../../wp-config.php')) {
		require_once("../../wp-config.php");
	} else if(file_exists('../wp-config.php')) {
		require_once("../wp-config.php");
	} else if(file_exists('wp-config.php')) {
		require_once("wp-config.php");
	} else if(file_exists('../../../../wp-config.php')) {
		require_once("../../../../wp-config.php");
	} else if(file_exists('../../../../wp-config.php')) {
		require_once("../../../../wp-config.php");
	} else {
		exit;
	}

}

Submitted by Chris McCoy.

About these ads

7 thoughts on “wp-load.php – I Will Find You!

  1. The only place where I used a “terrible” code like this, was in a TinyMCE plugin for a page editor, where I needed to access plugin’s functions as well as some core functions. TinyMCE plugin’s dialog loads an orphan page, that isn’t connected to WP in any way… so, the only way to do that is by loading wp-load.php. I believe, I saw a code example (similar to your above) in the official WP Codex… not 100% sure though.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s