Deleting WordPress records based on Nested Selects

Last week I was helping with a task for deleting terms from the WordPress database based on an array of IDs from a select statement. Since I have a thing for database systems (spent a few years playing in various mid-size and large projects with Oracle and PostgreSQL databases before migrating to MySQL) I thought it was a 20sec job to build the query having the select ready and delete the data. However, I got stuck in the process and took me about 15min to actually form the proper statement. The final code looks like that (with a bit different… Continue Reading

WordPress redirection based on URL

We've been working here on a URL shortener as a part of another project. To avoid the server redirect rules and so, we verify against the database whether a slug exists (is already entered in the DB) and if so, we get the URL and redirect to the page. As a fan of the request filter, I'd go with this approach: [php] function dx_redirector_request_filter( $request ) { // check for request['name'], for instance for // somewpsite.com/some-slug $request['name'] // would be some-slug if( ! empty( $request['name'] ) ) { // verify against the database entries // redirect accordingly, this is a… Continue Reading

jQuery UI problems since 3.5.1

WordPress 3.5.1 landed about 3 weeks ago, since then I have had several emails, direct messages and contact requests for fixing different site-related issues, such as: I cannot drag widgets on my Widgets page My TinyMCE is not displaying on the Posts page My theme/plugin dialogs are broken My X functionality (say slider) behaves in a weird way And so on. Usually, using a smart browser (such as Chrome or Firefox) you are able to open the JavaScript console and get a warning related to JavaScript - either a jquery-ui related file, or tinymce.php related one, or js.php and something… Continue Reading

The 3-Hour Theme Experiment

As a former ThemeForest author and a WPTRT member, I'm intrigued by all the fuzz about parent-child theme relations, theme frameworks, premium themes using the same infrastructure, startup themes and so forth. I remember my positive impression towards Genesis and their hooks model (even though pretty hardcore for customization in practice) and WooThemes and their internal framework, distributed flexibly within their themes. Last month I decided to set 3 hours straight and turn the _s theme by Automattic into a regular blog theme. By default _s comes with almost no stylesheets, or rather nothing than a white board with text… Continue Reading

ColorScheme Designer

I've been doing software and web development for many years now, but my design skills are pathetic (and it's an euphemism for them). However, I've tried an amazing tool a few times for color schemes for my WordPress themes that is absolutely amazing - called ColorScheme Designer. A number of color options are left for the user to pick from: Mono - a single nuance color scheme that focuses on a single color and it's derivatives Complement - an opposite color to the one you pick as a secondary color in addition to the main one (from the color palette) Triad -… Continue Reading

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

DX Plugin Base v.1.1 released

I've released a major update of my DX Plugin Base plugin which servers as a skeleton for WordPress plugin creation. Some of the old code has been refactored and simplified and a few new features have been added as well. Currently the list of code snippets working and included in the sample plugin base is: custom post types and taxonomies setup sample admin menu and subpage example of the Settings API in the admin pages - creating 2 options with a validation hooked function for further use registration of activate/deactivate hooks adding 2 metaboxes on pages - on the right… 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

How to: Make a WordPress plugin translatable

WordPress has its own mechanism to support plugin translations, but if you are a plugin developer yourself, you need to take care of that process at first place. Everything important is covered in the i18n for WordPress devs page in the Codex. If you are new to this, a few comments: 1. You need a .pot file for your plugin - describing all static texts to be translated further. 2. Every language translation consists of a .po file and a .mo file 3. The .po file is the human readable key-value (original text - translation) content, whereas .mo file is… Continue Reading