All posts in WordPress

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 .

Directory Permissions for WordPress under Plesk/Linux

Jason Diehl describes the right way to setup directory permissions on a Linux box running Plesk so that WordPress can automatically create the directories it uses to store uploads. Basically, you need to make sure that PHP’s safe mode is turned off and that wp-content is owned by apache, in the apache group, and chmod’d to 777.

Overwrite Uploads Plugin

I just checked a new plugin called Overwrite Uploads into the WordPress.org repository. It gives users the option to overwrite existing files when uploading rather than WordPress’ default behavior, which is to add a 1 to the end of the filename, e.g., filename1.jpg.

WordPress Plugin and Theme Security

Mark Jaquith recently gave a good presentation on writing secure WordPress themes and plugins at Wordcamp Phoenix 2011. The notes are also available. The main points are: Protect against SQL Injection by using the API whenever possible (because it automatically handles data sanitization). If the API can’t do what you need, use $wpdb->prepare(). Protect against Cross-site Scripting by sanitizing any output with esc_html(), esc_url(),… [more]

Comprehensive WordPress Multisite Migrations

Migrating multiple standalone installations of WordPress into Multisite can be relatively easy if you don’t need it to be perfect. The Codex has a basic guide and Stephanie Leary gave some more detailed tips at Wordcamp Phoenix 2011. But I’ve been working on a project for a client who had half a dozen blogs with hundreds of users and thousands of posts, and… [more]

Theme Metadata not Parsed Correctly

If you create a style.css file for a WordPress theme on a Mac OSX server it will use Mac line breaks (\r) instead of Unix (\n) or Windows (\r\n) ones. get_theme_data() won’t parse the metadata correctly , and it will be look messed up in the admin panel, or break the theme entirely. If your text editor supports converting between the… [more]

404 After Saving Custom Post Type

There’s an active bug related to custom post types and permalinks in WordPress 3.0.3. Here are the conditions that it exists under: Permalinks include %postname% A custom post type exists with an empty value for the slug key on the rewrite array A post/page/etc has been saved after the custom post type was installed You’ll start getting 404… [more]

Force HTTP requests in WordPress

I was working with a hosting client who wanted all of his pages to load via HTTP, except for a shopping cart. mod_rewrite rules are probably the most efficient way to do that, but we were having trouble getting that working, so I wrote a quick WordPress plugin to redirect HTTPS requests to HTTP , but allow specific pages to be exempted. I threw it… [more]

Accessing cforms Data Directly

I’m using the cforms plugin on one site at the client’s request, and I needed to access some of the form’s data. Their API didn’t have what I needed, so I thought I’d just query the database directly. But when I looked at the database I didn’t see any tables for it. I thought that was… [more]

Home page posts missing when using Pretty Permalinks for WordPress on IIS

I’ve been working on a problem recently with the Pretty Permalinks solution for WordPress on IIS. I was migrating a working WordPress blog from one server to another and once it was on the new server the front page would come up w/ the theme, but instead of the default posts it would say “Sorry, no posts… [more]

Protecting Contact Forms From Spam

I’ve had several clients complain about getting spam through their contact forms. Initially, I tried checking the referrers to make sure the comments were being submitted from a browser rather than just a bot, but that didn’t help enough. Luckily, many people have created libraries for Akismet , the anti-spam service that WordPress uses. I setup… [more]

Blank Page when using IIS Permalink hack

I use Pretty WordPress Permalinks on IIS when I need to install WP on a windows server, but on one host I ran into a problem where I would get a blank page if the post didn’t exist instead of the theme’s 404 template. But for some reason it works fine if I just echo something in wp-404-handler.php. I echoed… [more]

 
re-abolish slavery