Bad WordPress code, or is that redundant?

I discovered two levels of bad/bizarre/baffling code while working on customizing ghostpool.com’s Delapidated theme for WordPress. The sidebar and slider were not working because they both use the is_home function to determine whether or not to display.

The WordPress Codex documentation for is_home says: “This conditional tag checks if the main page is being displayed. This is a boolean function, meaning it returns either TRUE or FALSE.” This last sentence is displayed on many WP Codex entries, because apparently WP programmers are not familiar with the concept of booleans*. Anyway, since this is the page at /, usually known as “the home page,” I thought is_home would be true. Sadly, no.

Looking further at the documentation, there is a note that something gets funked up with WP 2.1, and mentions looking at is_front_page. The docs for is_front_page says “It returns TRUE when the main blog page is being displayed and the Settings->Reading->Front page displays is set to “Your latest posts”, or when is set to “A static page” and the “Front Page” value is the current Page being displayed.” Clear as mud.

To actually figure it out, I had to go to the code, which states much more clearly what each one does.  I’d paste the code here, but the code numbers and parts of tables show up due to WP’s auto-formatting and I’m tired. Basically, is_home will only return if you are on your front page AND you have set it to the posts page. So is_home should really be called is_posts_page. is_front_page actually does what it sounds like, though.

So ghostpool’s Dilapidated theme uses this function and this causes the slider and sidebar to fail miserably because the front page is not the posts page. In discovering this I had to dig through and debug various theme options, where I discovered ghostpool’s unfamiliarity with booleans. They keep using 0 to mean true and 1 to mean false. I cannot think of why they did this. So then they have all of their if statements set up to test if something == 1, which you think would be true, but again, sadly, no. I mean, it’s fine, it works, it’s just that it’s massively confusing and the code is uncommented.

Bonus programming nonsense: WordPress has a function called _doing_it_wrong. Sooooo true.

* – You have to know booleans if you’re programming. It’s basic. It’s one step beyond thinking of a computer as full of infinite magic 1s and 0s.  Maybe if someone is forcing you to program with a gun to your head and you have no prior experience, I’ll forgive your ignorance. Otherwise, please just go learn.

This entry was posted in PHP, Web Development, Wordpress. Bookmark the permalink.
  • Jack

    Good post. Your background is cool but very distracting…

  • m

    Thanks. I really should change the background. Or offer an option to turn it off. I’m just glad people still read my li’l ol’ site. I’m trying to update it more.