Debug WordPress To See How It is Works

It’s no doubt that WordPress is one of the most powerful CMS for blogging. Beside it is free and open source, it also user friendly. But do you know how exactly WordPress executing it’s code? Well, this idea come up in my mind, so i would like to trace how WordPress executing it’s code.

When visitors visit your WordPress blog, it only serve through index.php, even your visitors click any links in your blog (post, category, page, blogroll, archive, feed links), it will serve only from index.php. So when i try to open index.php, it only have 2 line of code to execute.

See the code below:

define('WP_USE_THEMES', true);
require('./wp-blog-header.php');

It’s surprising, isn’t it?

So to trace the code, i’m using XDebug, and place the XDebug code in the index.php:

define('WP_USE_THEMES', true);
xdebug_start_trace('c:/trace/wordpress.txt');
require('./wp-blog-header.php');
xdebug_stop_trace();

And i got so many lines of debug executed code. Then i follow it, and open wp-blog-header.php, i got this code and also place the XDebug code as well in wp():

if ( !isset($wp_did_header) ) {
	$wp_did_header = true;
	require_once( dirname(__FILE__) . '/wp-load.php' );
        xdebug_start_trace('c:/trace/wordpress.txt');
	wp();
        xdebug_stop_trace();
	require_once( ABSPATH . WPINC . '/template-loader.php' );
}

And still i got bunch of debug executed code, but now it is easily to understand.

So what i learn so far by tracing this code is, it is useless that i put the post-id at the end of my url (example: https://www.ivankristianto.com/see-how-php-web-application-work-with-xdebug/). WordPress will parsing the url with this sequence: get the category, post title, and then post id for the last. I should have been make post id at the beginning, so it will increase WordPress performance since it will get the post-id in first sequence of url parsing.

I will test it in the next run by using timer to see the difference between put the id at the beginning and at the end of url rewriting.

Related reading:
See How PHP Web Application Work With XDebug
Debug Your PHP Application With XDebug

Comments

  1. Great post. Just what I was looking for. Just wish PHP/WordPress had more info right in the browser. A blank page isn’t that helpful.

  2. Really Good One, It should have been make post id at the beginning, so it will increase WordPress performance since it will get the post..Thanks

Give me your feedback

This site uses Akismet to reduce spam. Learn how your comment data is processed.