WordPress Themes: Object Oriented PHP Code is Very Important
I’m doing a heavy rewrite of my main WordPress theme that all of my other themes are based on. As someone who has spent a lot of time writing code, one of the things that has been bugging me about WordPress themes is all the duplication of HTML. For instance, if all your pages have a [...]
Tip: Always Comment overflow: hidden; CSS Rules
CSS comments aren’t always helpful, they tend to muddle the code and once you get good at naming classes and ids your CSS should tell a pretty clear story. But one thing that should always be clearly commented is the use of overflow: hidden; This rule is used mostly for a couple of reasons, and almost [...]
Using the WordPress apply_filters Function for Dynamic Content
In a WordPress plugin you can filter many values including the title and content of a post using: add_filter('the_content', 'MyPluginClass::FilterTheContent'); This is pretty handy, but sometimes when you’re writing a WordPress theme you want to allow plugins to add content, not just filter the usual content. Using apply_filters makes this pretty easy because you can call apply [...]
WordPress and PHP have Poor Support for Dates and Time Zones
Today I spent way too much time figuring out how to convert dates and times to different time zones. PHP can barely do it, and WordPress really doesn’t do anything to make it easier. I would love it if someone would just create a simple function like this: $string = format_gmt_time_for_time_zone( 'l, F [...]
Swift Mailer: Awesome PHP Mailer
Tonight was the first time that I needed to write some code for a business that would send email to customers, or at least email that needed to be reliable and feature rich. I looked at the documentation for the PHP mail function and after a lot of reading realized it was not going to [...]
HTAccess RewriteRule, When it Changes the URL in the Address Bar
I have been trying to figure this out for ages. When will RewriteRule change the URL in the browser address bar? Today I read thought the whole Apache mod_rewrite documentation page and I still didn’t know the answer. But after a ton of searching I finally figured it out, and hope to explain it to [...]
Making the body Element Take Up At Least 100 Percent of the html Height
Here was my problem, I had some divs absolutely positioned at the top and bottom of the body element and I needed the div at the bottom to be at the bottom of the window even if the body wasn’t tall enough to reach the bottom of the window. Here’s the solution: * { [...]
Using PHP Class Methods as WordPress Action Hook Callbacks
Using object oriented code is a must for me. Object oriented code is more than just organization of the code, it’s organization of one’s thinking. I wanted to talk about using static class methods as handlers for WordPress actions. This is important to me because often my plugins are implemented as a class. add_action('init', 'MyPlugin::Init'); class MyPlugin { [...]
PHP, Classes, Camel Case, and Underlines
When I first started PHP programming, I wrote code like the PHP inventors wrote code, using lowercase characters and underlines, like: $my_favorite_variable = 5; function add_numbers($first_number, $second_number) { return $first_number + $second_number; } $answer = add_numbers($my_favorite_variable, 1); But this became tiresome. The thing is, the underscore character is harder to type and using all lowercase really makes the [...]