Thinking » Topics » Open Source
Investigate. Collaborate. Solve. It’s what we do here at Oomph, and every so often we like to share how we do it. This is a short story about finding WordPress shortcodes using regular expressions.
A few weeks ago, I was tasked with converting a good amount of embedded video from one host platform to another for one of our clients. I wrote two Command Line Interface scripts in the process: one to identify and categorize the 1,200 instances of video code, and another to make the conversions. I did it using regular expressions. Here’s the why and how:
While you could use the WordPress function get_shortcode_regex(), this action will return an array of all the regular expressions in your post content. That means you would still need to conditionally check for your target shortcode within that array and, if found, determine the appropriate array index and operate on that match.
A quicker route to extract a specific shortcode in post content would be to directly use a regular expression:
[php toolbar="true"]
$your_shortcodes = preg_match_all( ‘#\[your-shortcode-here\s*.*?\]#s’, $content, $matches );
[/php]
This will find all instances of your self-closing shortcode and return an array of them. Just one line of code will save you time, and you can loop through your posts and make the necessary changes.
As for our shortcode story, the conversion script ran seamlessly—and all the videos lived happily ever after on their new host platform.
The WordPress Zone Manager plugin—alias The Zoninator—helps site admins curate content by allowing them to create content “zones” anywhere on their website. Content is then assigned to designated zones and ordered based on criteria configured on the backend. Oomph’s Vu Huynh has been working to optimize the power of Zone Manager for our clients, and we sat down with him to talk about what’s possible with The Zoninator.
What are some of the key benefits of the Zone Manager plugin?
Zone Manager provides an easy-to-use administrator interface to queue posts in any order without any programming knowledge. This is particularly useful when a certain post order cannot be easily made through a query. Zones can be quickly added, edited and deleted through the admin interface.
How have you been using Zone Manager?
I’ve been using Zone Manager as a means to “feature” posts on a homepage and a homepage-placed sidebar. Administrators can have a specific post remain on the homepage even if the post would normally be archived because of its publish date. Zones are sometimes used as an alternative to stickies when you want to have a featured post remain on the homepage despite its place in the chronological order.
What else is possible with Zone Manager?
Any content type can be placed into zones, not just posts and pages. So anything that queues content into a list can use Zoninator as an interface to do so, such as a custom gallery.
The first annual WordCamp Providence was held on October 27th. The sold out event brought 200 WordPress developers, designers and the WordPress curious out to the University of Rhode Island campus.
Being a developer, my main focus for WordCamp was the Shipbuilding track. Jon Bishop started off the talks with best practices for providing clients with an admin that will fit their needs and not add unnecessary complexity. Aaron Holbrook followed up by showing how using version control — specifically git — will aid in code maintenance and rapid deployment.
The morning session concluded with Automattic’s John James Jacoby discussing how to secure your code from potentially malicious data, methods of testing your code and the advantage of using xdebug to step through not just your code, but WordPress core as well. John’s IDE of choice is Netbeans, which works very well with xdebug. I tried Netbeans a couple years ago, but switched away. After John’s talk, seeing how easy it is to step through code and access the code to core functions, I’ve switched back. The latest version is a vast improvement in performance and functionality; I strongly suggest giving it a try. Unfortunately, John didn’t provide links, if that changes, I’ll post an update.
Oomph’s own Ben Doherty started the mid-day portion of the developer track with a talk on implementing object oriented programming into theme development. Ben explained how using OOP principals in theme development will result in code modules that can be easily reused in other themes, providing consistency in development. He touched on how to set up a development environment for debugging, different implementations of a singleton, and using actions and filters for accessing class methods. You can read through his presentation at http://bendoh.github.com/WordCamp/wcpvd-2012-oop/
Jon Desiosiers broke down the fundamentals of plugin development, including best practices and what to do when you get stuck. Matthew Boynes built upon Aaron Holbrook’s talk by demonstrating how to use git and a WordPress multisite implementation to develop and deploy code between a local development environment and a hosted staging or production server. You can watch his entire presentation at http://boyn.es/2012/10/28/wordcamp-providence-2012-presentation/
In the home stretch of the Shipbuilding track, K. Adam White talked about Backbone.js and Underscore.js, two new libraries that will be available in WordPress 3.5. These libraries can provide structure to jQuery code via a modified implementation of MVC (Model, View, Collection). The track was concluded by Oomph developer turned Automattician Erick Hitter’s reprising of his WordCamp Boston talk on going beyond the codex and learning more about WordPress by looking at the core files. Erick breaks down the structure of core and where to start looking for the function or filter that will best suit your needs.
Providence’s first WordCamp was a great success, with fantastic speakers and a good vibe all around. I congratulate the organizers for a well planned event and I look forward to next year.
July 14th marked the beginning of yet another successful WordCamp in the City on a Hill, making it Boston’s third time to host the event. Approximately 600 speakers, attendees and volunteers arrived at Boston University from all over the world to congregate around a common entity, our beloved WordPress.
Saturday morning kicked off with one of what I found to be one of the most well-presented and informative talks, How We can have Nice Things, by K. Adam White. The session was focused on demonstrating how the modern WordPress developer can spearhead new and upcoming web technologies such as CSS pre-processing, server-side Javascript, client-side templating, and source control. Doing so allows developers to expand and update their creative process outside of the traditional LAMP stack workflows. continue reading
Earlier this month, approximately 600 of my closest friends and I attended WordCamp Boston. This was my first experience at a WordCamp, and it did not disappoint. I attended several great talks, but one caught my attention: Aaron Jorbin’s “Developing an Automated Workflow for Front End Development“. This was a presentation packed with applications and utilites to aid in reducing development bottlenecks.
Mr. Jorbin suggests utilizing the command line, using dotfiles, and using tab completion to speed up the process. Taking advantage of hooks in git will help to automate workflow, or use your computer’s camera to take a photo of you on a commit.
For WordPress deployments, WP Stack and Capistrano can be a great help.
Mr. Jorbin crammed an almost overwhelming amount of information into the short amount of time he had to present. I have only scratched the surface. I strongly suggest reading through the blog post and trying out some of the tools he has listed there. I’m planning on incorporating some of them myself and I would love to hear what tools you have found useful.
Today at WordCamp NYC, I gave a presentation on how you can work with WordPress via a command-line interface (CLI.) This presentation covered how you can can poke and prod WordPress core and API by using WPSH, a custom script built on top of Facebook’s PHPSH.
Also covered were approaches to write command-line scripts for WordPress, using this knowledge to build tools for importing and exporting blog data, as well as some of the higher-level issues involved with processing bulk data.

One question that was offered after the presentation had to do with my familiarity with wp-cli, which I admit, I had none. It appears that the wp-cli utility is useful for atomic operations on the blog, like upgrading core, adding users, &c., whereas wpsh will give you an interactive environment to run any PHP / WordPress API code that your heart desires. I will be sure to give props to wp-cli in my next talk, and discuss how it differs from wpsh, and the advantages of each.
You can obtain the presentation slides at github.

