The WordPress Horror Show

Bashing of popular technologies like PHP, Java, WordPress and Magento are nothing new. I had fallen for such comparisons before, and spent my share of time reading other people’s experiences. Invariably, one of the two sentiments emerges from such excursions:

  • The platform in question was devised by the Devil himself to torture human souls.
  • Those who hate the platform are idiots that know nothing about it.

I always tended to side with the second camp. I mean, I’ve been a core PHP developer. And I’ve worked with Java and Python and Elixir and dipped into Go and what not. So I know that while PHP has the most number of problems, they don’t matter so much in the long run. It has all the paradigms and tools necessary to deliver a first-class developer experience.

So when I finally started learning WordPress, I was expecting something similar. I thought people didn’t like it because it wasn’t Object Oriented and didn’t use Composer (I’m also not aware of unit testing in the WordPress domain). But having spent a few minutes with it, I’m beginning to side with the haters.

It all started with a simple code snippet I came across in a beginner tutorial:

<?php
 if ( have_posts() ) : while ( have_posts() ) : the_post();
 get_template_part( 'content', get_post_format() );
 endwhile; endif;
 ?>

I had looked at it cursorily several times before, but this time I felt an unease. What was get_template_part() doing? Okay, it loads a PHP template file with the given name. Inside content.php is a line that says the_content() and I guess that is the one that outputs the actual post content. But then what is the_post() doing? I thought it too was rendering the post, but I was wrong. It turns out that it sort of sets some internal index to the correct state and sets the stage for rendering the post correctly.

As a developer, I’m confused about several things:

  • Why does the_post() need to be called explicitly? If setting the post pointers in the right place is so important, why not let the core call it directly?
  • Who thought of this horribly confusing naming? the_content() is supposed to publish the content while the_post() is supposed to . . . publish the post??
  • Why isn’t the_post() called setup_post_pointer() or something more helpful?
  • In fact, why are these fundamental functions named without a verb in their name? What am I supposed to understand from the_content()? The content of what? And what is this function supposed to be doing?

Even the official documentation is full of horrible oversights. Look at the very first line of WP_Query Class Reference:

WP_Query is a class defined in wp-includes/query.php [. . .]

Except that when you open the file in question, there’s no such class defined! I had to do a grep to figure out the correct location: it’s wp-uncludes/class-wp-query.php. This much is enough to make me proclaim WordPress as one of the horrors of software development.

Am I going to give up WordPress because of these shortcomings? Not at all, because WordPress makes a lot of business sense. It’s a radically popular platform, and allows you to get to work quickly (both as a developer and a user). And there’s a huge, paying market. So as far as websites, blogs, small e-commerce stores are concerned, WordPress will be my first choice. It’s just that every time I’ll have to work with its code, a small part of the developer inside me will die.

Leave a Reply

Your email address will not be published. Required fields are marked *