All posts in WordPress

WordPress Backup Options

Nathan Ingram put together a thorough post on backing up WordPress and a chart comparing various plugins and services .

Placing Snippets in a Functionality Plugin Instead of Theme

Dave Clements has a great suggestion for adding snippets to a WordPress site in a way that will preserve them between theme changes: create a simple functionality plugin .

Scaling WordPress Installations

TJ Stein gave a really good presentation at WordCamp Chicago 2011 about scaling and performance issues with WordPress installations. He focuses a lot on using ngnix instead of Apache, but also covers PHP object caching, Varnish, CDNs, benchmarking, etc. It’s a good overview of current practices, but there’s also a lot of specific tips throughout.

Different Approaches to Building a Theme-based Site

Mark Root-Wiley wrote a great article on the pros and cons of using premium themes, writing child themes and writing themes from scratch . It’s discussed in the context of WordPress themes, but most of it is applicable to other CMSs as well. I think it’s a good introduction to give clients when discussing which method is best for their project.

Differences between query_posts(), get_posts() and WP_Query

This WordPress Answers page explains the differences between the query_post() and get_posts() functions, and their relation to the WP_Query class. They both use WP_Query internally, but should be used in different contexts. Using them in the wrong context could lead to bugs that are hard to track down.

Re-Abolish Slavery Ribbon

I just released a new WordPress plugin into the repository that raises awareness about modern-day slavery by adding a “Re-Abolish Slavery” ribbon to WordPress sites. It’s running on this site, so  you can see a live example by looking in the upper-right hand corner. The ribbon links to the Not For Sale campaign , which is one of the leading organizations involved in fighting human… [more]

Unit Testing WordPress Plugins

Nikolay Bachiyski gave a good talk at this year’s WordCamp San Francisco about unit testing WordPress plugins . His method uses PHPUnit , which is an additional PEAR package you have to install on the server. You can then use MockPress to simulate WordPress in the tests. Another option is the SimpleTest for WordPress plugin , which uses SimpleTest instead of PHPUnit, doesn’t require installing a PEAR… [more]

Performance Improvements for Dedicated WordPress Servers

Mark Maunder benchmarked several performance tuning measures with a WordPress installation on a VPS server to show which are most effective. The biggest improvements were from installing PHP-APC , setting up Nginx to proxy concurrent connections for Apache, and using MySQL’s query cache.  

Passing Multi-Dimensional Arrays from WordPress to JavaScript

On its own wp_localize_script() can’t handle multi-dimensional arrays, but you can get around that by encoding the child arrays in JSON . That doesn’t handle HTML content very well, though, so another way to do it is to use the l10n_print_after parameter . That’s kind of ugly, but it seems like the best way available right now. It looks like WordPress 3.3 might have a wp_add_js_data() function , which would be much… [more]

Conditionally Loading JavaScript and CSS in WordPress Plugins

When writing a WordPress plugin it’s considered a best practice to only include JavaScript/CSS/etc files on the specific pages that need them, rather than on every page load. This speeds up page load by reducing the number of HTTP transactions and also minimizes the risk of unnecessary conflicts between other files. There are two popular… [more]

Basic Google Maps Placemarks Plugin

I wrote a new WordPress plugin for a side project and just released it into the repository . It creates a custom post type for markers and then inserts them into an embedded Google Map, using the post’s featured image as the map icon. Note: all support requests should be posted to the support forums .

Custom Post Type Fields Overwritten

The past few days I’ve run up against a weird bug in a plugin I’m writing, where the custom post type fields would be overwritten with empty values randomly. Creating or editing a post would save the values fine, but I’d come back 5 minutes later and they’d be empty. I finally got it sorted,… [more]

Parse Error When Installing WordPress 3.2 on a PHP4 Server

This is the error you’ll get if you try to install WordPress 3.2 on a PHP4 server: Parse error: parse error, unexpected T_VARIABLE in /path/to/your/directory/wp-includes/load.php on line 566 It’s because the clone keyword doesn’t exist in PHP4 .

admin-ajax.php Response Fails When Called from Domain Alias

I’m writing a WordPress plugin that uses AJAX and I had everything setup and working fine for awhile. I came back to the code a few hours later and all of the sudden I was getting a failed response, even though the code hadn’t changed. I got the correct JSON response when I loaded the… [more]

Uploading Files with Custom Post Types

If you’re building a custom post type and want to let the user upload files, you’ll need to add enctype=”multipart/form-data” to the form tag, using the  post_edit_form_tag filter. Otherwise the $_FILES array will be empty.

Creating Custom Post Types With Extra Fields

Richard Shepherd’s post on creating custom post types in WordPress is the first good example I’ve found that covers adding extra data fields.

Determining WordPress Paths and URLs

I often need to include a directory or URL path when writing a theme or plugin, but I can never find all of the different options in one place, so I’m pulling it together from various Codex pages and xref . Constants ABSPATH – /var/www/vhosts/example.com/httpdocs/ WP_CONTENT_DIR - /var/www/vhosts/example.com/httpdocs/wp-content WP_CONTENT_URL - http://www.example.com/wp-content WP_PLUGIN_DIR - /var/www/vhosts/example.com/httpdocs/wp-content/plugins WP_PLUGIN_URL - http://www.example.com/wp-content/plugins TEMPLATEPATH - /var/www/vhosts/example.com/httpdocs/wp-content/themes/parent-theme STYLESHEETPATH - /var/www/vhosts/example.com/httpdocs/wp-content/themes/child-theme BLOGUPLOADDIR… [more]

Using Chained Properties Inside $wpdb->prepare()

If you’re using $wpdb->prepare() to query a custom table, you can’t pass the table name in as an argument because it will be single-quoted, which would be a MySQL syntax error. Instead, you need to insert the variable directly into the double-quoted query string and let PHP parse it out. That creates a new problem,… [more]

Capturing WordPress Plugin Activation Errors

If you’re developing a plugin and there are any PHP errors/warnings you’ll get a message like this when you activate it: The plugin generated [x] characters of unexpected output during activation. If you notice “headers already sent” messages, problems with syndication feeds or other issues, try deactivating or removing this plugin. You don’t actually see… [more]

Reserved WordPress URL Parameters

Using a reserved WordPress URL parameter (like “year” or “m”) on the front end will cause a 404 error .

 
re-abolish slavery