Overcome the WordPress Autosave Limitations

WordPress includes a handy feature called 'autosave' that periodically persists an autosave version of a post at the moment of writing. Since accidents happen, it's always good to have some recent version of a long text instead of starting from scratch when you don't have the proper backup. Autosave is handy, but since WordPress is no longer 'yet another blogging platform', it lacks important extensions to that feature. When you work with custom post types (or even plain old posts and pages), you might need to alter the standard save behavior. Therefore you take advantage of the save_post hook. Then… Continue Reading

Add a TinyMCE button to WordPress post editor

Most themes and large plugin utilize the WordPress Shortcode API by adding code snippets that could be parsed inside of a page or post. One of the handy ways to present a UI behavior for your customers is by embedding the functionality to the TinyMCE editor as an extra button. You need to create two files and embed them in your theme/plugin or create an extra piece of code (say, via another plugin) to trigger this behavior. The first file should be the JavaScript logic behind the button (as TinyMCE interaction is entirely JS-driven) and the second one is the… Continue Reading

Quick tip: get_terms with all terms

The get_terms WordPress function is listing all your terms for a given taxonomy (or taxonomies). However, the default callback returns only the terms with entries. Therefore your empty terms won't be visible unless you use the hide_empty parameter with a false value, like this: [php] $product_terms = get_terms( 'product', array( 'hide_empty' => false ) ); [/php] Passing the hide_empty parameter would fetch the empty terms from your product category as well. Continue Reading

eval() error check

We all know how dangerous eval() is in terms of security, but still it is the necessary evil sometimes. I've been developing a script last week that required eval() execution. I did pretty granular input validation with regular expressions and known troubleish test cases. Still, some expressions passed to the eval() function were prone to parse errors. Reading a bit I tried to use the exceptions handling mechanism in PHP 5 (try - catch blocks) to provide a solution, or using a error handler with the set_error_handler function. They work for exceptions and some basic errors, but most of the… Continue Reading

How to Start a WordPress Project?

Starting a new WordPress project requires some initial planning to avoid some common mistakes. Failing to adhere to an action plan may easily incur technical debt (with an unpredictable setup, libraries, and plugins). The WordPress Theme Industry There are tons of themes available - free or premium - and lots of theme markets for premium resources. I even mentioned a script for running your own theme market - that's how popular it got recently. Anyway, as a WordPress developer and consultant I try to select the best options for my clients. And I have some difficulties on the choice of… Continue Reading

WordPress custom pagination

When designing a theme pagination is required for listing of posts on the index page. WordPress, by default, presents only the ability of one to use "Previous page" and "Next page" - which might be enough to navigate through the archives but is however incomplete and annoying. The standard navigation has <<, >> and numbers for the current page and the pages before and after (at some range). One of the best solutions I have used is the Kriesi Pagination. Kriesi is one of the top sellers on the ThemeForest market with over 25 thousand sales at the moment of… Continue Reading

Post formats

Post formats have been introduced to WordPress in version 3.1. This is an innovative way for WordPress user to simulate Tumblr behavior and use the oldest "Post" feature in the platform to post quotes, links, images and other formats with different formatting. In order for one to design specific image or quote behavior we used to create categories with custom templates or write custom post types with additional functionality to them. This requires additional coding for styling and separates from the most standard feature of WordPress - blog posting. That's why post format have been added in v 3.1. By… Continue Reading