Attaching Uploads to Custom Post Types

I’m working on a plugin that implements a custom post type, and it doesn’t need the editor, but I do want to upload files. I setup the everything like you normally would, but I noticed that the files weren’t being attached to the post when they were uploaded. I couldn’t find anything online, so I dug through […]

Continue reading...

Reusing P2’s ajaxUrl Short-Circuits Other AJAX Requests

I just spent awhile tracking down some odd AJAX behavior that was puzzling me, so I thought I’d share the solution. I was working on a plugin to extend P2 and my AJAX requests were always responding with -1. After a lot of digging and some trial-and-error, I figured out that it was happening because I was […]

Continue reading...

Preventing a Plugin from Automatically Updating

In an ideal world you’d never have to fork a plugin, because developers would always make their plugins extensible with hooks, just like WordPress itself does. But unfortunately that’s not usually the case, and it’s sometimes necessary to directly modify a plugin to make it do what you need. In those cases, you want to […]

Continue reading...

Creating Admin Notices From a WordPress Plugin

I just threw a couple small PHP classes up on GitHub that I use in almost every WordPress plugin I write. The first is IDAdminNotices, which is a clean and easy way for plugins and themes to send messages/errors to the user within the Administration Panels. The second is IDDescribeVar, which will outputs the type, length and contents of […]

Continue reading...

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 […]

Continue reading...

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 […]

Continue reading...

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 […]

Continue reading...

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 […]

Continue reading...

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 […]

Continue reading...