Skip Navigation

wp-migrationsWe’ve been trying out WPML on WordPress 2.8 (Beta 2) and it works just fine.

Seeing that several other plugins we’re using did have some problems, I thought it would be interesting to write about how to make sure your own plugins and themes are resilient to WordPress updates.

Tips for making plugins and themes migrate flawlessly

The WordPress codex is stuffed with instructions for writing good plugins. This is a short summary of key points to remember:

  • Never use obsolete calls – no matter how tempting it is.
  • Always use the WP actions (hooks) and filters to access the database and don’t query or update it directly.
  • Use the WP classes when creating GUI elements – this way, when WordPress redesigns, so will your plugin’s admin.

Examples (don’t try these at home)

Getting WordPress options



and not:

$wpdb->get_var("SELECT option_VALUE FROM $wpsb->options WHERE option_name='some_option_name'");

Getting a list of posts (including with a filter)


$posts = query_posts('showposts=5'); //plus any other arguments

$posts = query_posts('showposts=5&cat=3,4,5');

and not:

$posts = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_status='publish' AND post_type='post' ORDER BY post_date DESC LIMIT 5");

$posts = $wpdb->get_results("SELECT * FROM $wpdb->posts p JOIN $wpdb->term_relationships r ON p.ID = r.object_id JOIN $wpdb->term_taxonomy x ON r.term_taxonomy_id = t.term_taxonomy_id JOIN $wpdb->terms t ON x.term_id = t.term_id WHERE p.post_status='publish' AND p.post_type='post' AND x.taxonomy='category' AND t.term_id IN (3,4,5) ORDER BY p.post_date DESC");

Getting a list of tags


$tags = get_terms('post_tag');

and not:

$tags = $wpdb->get_results("SELECT * FROM $wpdb->terms t JOIN $wpdb->term_taxonomy x ON t.term_id = x.term_id WHERE x.taxonomy='post_tag'");


Pretty simple, right?

Keep in mind that this list applies the same to theme functions. You might want to go over your functions.php file and make sure that’s the way it works.

BTW – very few people have voted in our poll about where WPML should go. Don’t you care? You still have a chance. Go and vote now!