Extending a WordPress Site: Core Hijack

Including WordPress

Every WordPress site runs off of the main index.php file as a front controller. If you open the index.php file you'll see that it includes a single file: wp-blog-header.php. In that file you'll see that it includes another file: wp-load.php (the contents of which used to be in the wp-blog-header.php file in pre 2.6 WP). The code in wp-load.php is the code that we are going to hijack and modify for our own purposes. Luckily for us, the people that coded wordpress made this really easy for us to do :)

Simply copy this code out of wp-load.php to your index.php file that we created in the set up.

PHP:
  1. /** Define ABSPATH as this files directory */
  2. define( 'ABSPATH', dirname(__FILE__) . '/' );
  3.  
  4. error_reporting(E_ALL ^ E_NOTICE ^ E_USER_NOTICE);
  5.  
  6. if ( file_exists( ABSPATH . 'wp-config.php') ) {
  7.  
  8.     /** The config file resides in ABSPATH */
  9.     require_once( ABSPATH . 'wp-config.php' );
  10.  
  11. } elseif ( file_exists( dirname(ABSPATH) . '/wp-config.php' ) ) {
  12.  
  13.     /** The config file resides one level below ABSPATH */
  14.     require_once( dirname(ABSPATH) . '/wp-config.php' );
  15.  
  16. } else {
  17.  
  18.     // A config file doesn't exist
  19.  
  20.     // Set a path for the link to the installer
  21.     if (strpos($_SERVER['PHP_SELF'], 'wp-admin') !== false) $path = '';
  22.     else $path = 'wp-admin/';
  23.  
  24.     // Die with an error message
  25.     require_once( ABSPATH . '/wp-includes/classes.php' );
  26.     require_once( ABSPATH . '/wp-includes/functions.php' );
  27.     require_once( ABSPATH . '/wp-includes/plugin.php' );
  28.     wp_die(sprintf(/*WP_I18N_NO_CONFIG*/"There doesn't seem to be a <code>wp-config.php</code> file. I need this before we can get started. Need more help? <a href='http://codex.wordpress.org/Editing_wp-config.php'>We got it</a>. You can create a <code>wp-config.php</code> file through a web interface, but this doesn't work for all server setups. The safest way is to manually create the file.</p><p><a href='%ssetup-config.php' class='button'>Create a Configuration File</a>"/*/WP_I18N_NO_CONFIG*/, $path), /*WP_I18N_ERROR_TITLE*/"WordPress &rsaquo; Error"/*/WP_I18N_ERROR_TITLE*/);
  29.  
  30. }

The modifications we are going to make are as follows:

  1. Set the ABSPATH constant to the path of our WordPress install.
  2. Remove the code that checks for the config file - WP should already be installed if you are extending it and we know where it is.

Here is the modified code:

PHP:
  1. /** Define ABSPATH as this files directory */
  2. define( 'ABSPATH', '/home/jamese/public_html' . '/' ); //This line used to be: define( 'ABSPATH', dirname(__FILE__) . '/' ); CHANGE [wp_dir] to your directory path that wpconfig.php is in
  3.  
  4. error_reporting(E_ALL ^ E_NOTICE ^ E_USER_NOTICE);
  5.  
  6. /** The config file resides in ABSPATH */
  7. require_once( ABSPATH . 'wp-config.php' );

On the next page you'll learn how add your theme...

Pages: 1 2 3 4

if you liked this post :)

Category: Programming | 1,711 views | Posted: July 30th 2008 08:00 am

Related Posts

7 Comments »

MyAvatars 0.2

Comment by Christopher Clayton
on 30 Jul 2008 at 1:28 pm #

This is GREAT!

Never knew that! i have an idea i could use this for, once its done ill come back and let you know how it went!

i like your password generator!

Cheers,
Chris

 
MyAvatars 0.2

Comment by Link Building Bible
on 01 Aug 2008 at 3:43 am #

Can you do a post about how to create your own custom Wordpress install…. with all of the settings configured how you want, plugins added (i know u still have to manually activate them) and with theme included.

I create niche sites and have a basic setup for all of them, and want it done automatically for me…. not manually doing it for each site.

Thank you very much.

MyAvatars 0.2

Comment by James Ehly
on 01 Aug 2008 at 8:16 am #

Link,

That sounds like a good idea for a post, but to get you started now, I would do it like this. Set up my install how I wanted it, then do a file and database backup. Take your sql file and figure out what records you want in your install and create update statements with those (or leave them as inserts if they are new content). This is usually kind of a lengthy process, but is a huge timesaver and it’s how I install my MODx sites. Then you can install Wordpress as normal, copy your install files over it, and update the database with your sql script.

James

 
 
MyAvatars 0.2

Comment by Stu the Adelaide SEO
on 17 Aug 2008 at 8:11 pm #

@ link building bible - how long does it take you to install and set up a wordpress blog? Ten minutes?

You can try by getting one set up the way you want it then downloading everything in the wp-content folder.

At least then you have your theme, plugins etc all sitting there for the next time you create a site.

 
MyAvatars 0.2

Comment by San Nayak
on 20 Aug 2008 at 2:00 pm #

I created a guide for installing the worpress with standard template and it seems to take at least 25-30 minutes to configure everything.

 
MyAvatars 0.2

Comment by Code Errors
on 01 Oct 2008 at 4:00 pm #

I don’t know if there is a plugin to get a keyword and description tag in the wordpress, if you guys know then let me know about it as well.

MyAvatars 0.2

Comment by James Ehly
on 01 Oct 2008 at 9:48 pm #

Sure there’s the All in One SEO Pack. Is that what you are looking for?

 
 
Name (required)
E-mail (required - never shown publicly)
URI
Subscribe to comments via email
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> in your comment.

« Top Affiliate Challenge is Over | Adding Linux to Your Web Development Arsenal »