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.
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 [...]
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 [...]
WordPress Function do_action – Very Useful
Today, well, really the last few days have been incredibly productive and incredibly hectic. I finished up some complex code for a customer and ever since then I’ve had so many epiphanies that I’ve practically been typing constantly ever since. I will say that I really like when I am inspired like this, but I [...]
JQuery.post Recursion, or not…
Today I spent some time making some data import code work better. At the start of the process I had a PHP function that I would call to import some data. The problem is, that process would take longer than 30 seconds after which it would time out. A while ago, I changed the function to [...]
WordPress Plugins and AJAX
The last couple of days I’ve been doing a ton of AJAX programming on some WordPress plugins. Wordpress actually does have one very handy AJAX feature that makes using AJAX just a little easier. I also use jQuery because it’s really nice for a lot of things including AJAX work. AJAX is a great technology, and [...]