Tag Archives: wordpress

Direct plugin auto-update on WordPress 2.8

I get a lot of traffic on the site due to my post on getting direct (non-FTP) updates to work on WordPress 2.5.  This method worked up until 2.7.x.  With 2.8 out this week, I found during my svn switch a conflict was created due to a code change in file.php.  Looking at the changes, it looks like the wordpress developers created an easy way for one to short-circuit the update to use the method you want via a setting in wp-config.php.

So, in brief, the permissions and WP_TEMP_DIR settings from the older article still stand.  However, you no longer need to edit wp-admin/includes/file.php. Now you just need to edit your wp-config.php and add the following towards the bottom:

define('FS_METHOD', 'direct');

WordPress for iPhone

I noticed that the WordPress for iPhone native blogging app appeared in the iTunes store last night. This is me giving it a try.

I don’t think i’ll bang out long posts this way, but you might see lots of smallish stuff since it’ll be so easy to add. Especially some on the fly photo blogging. Heck, it might replace my use of Twitter for some thoughts. Especially those thoughts over 140 characters.

As and added bonus, here’s Vik’s cat, Inky.


[non iPhone Update: Looks like Declan had the same idea on his blog.]

Small fix for WordPress XML-RPC

I had the idea that I might photo blog more if there was an easy way to get photos off my iPhone and into a blog post.  The easiest way would be to e-mail the photo someplace for WordPress to get it.  Unfortunately, most of the e-mail to blog post plugins (and the built-in stuff) just sucks for my need.

I decided to look at the XML-RPC API to see if I could get it done that way, and then write a script to be called out of procmail to create the mail.  There is a function there that will do what I want, wp.uploadFile aka metaWeblog.newMediaObject.  The specification for that call says that the file being uploaded must be Base64 encoded.  No problem, a few line of ruby later and I have everything ready to test an upload.  The file goes up, but its unviewable in a browser.  A quick check of the file on the server and its revealed to be a text file filled with Baes64 looking data.  Somewhere along the line it wasn’t being decoded.

After about an hour of screwing around, I determined it wasn’t anything obvious in my code, so I thought I’d look at the code for WordPress 2.5.1 to see if I missed anything obvious.  In reading their code, I found that the WordPress folks forgot something obvious, their code never Base64 decodes it before it writes it to a file.  A quick one-line change later, and *boom* I’m off.

Here’s the patch in case its useful to anyone else. I’ll have the script up when I’m done with it.

(Also, in a small bit of embarrassment, I must admit fixing this took me 10 minutes longer than it should because I forgot ; is end of statement in PHP.)

Index: xmlrpc.php
--- xmlrpc.php  (revision 7840)
+++ xmlrpc.php  (working copy)
@@ -1880,6 +1880,10 @@
                        $name = "wpid{$old_file->ID}-{$filename}";
+                # The specification says that this is base64 encoded,
+                # we should really decode it.
+                $bits = base64_decode($bits);
                $upload = wp_upload_bits($name, $type, $bits);
                if ( ! empty($upload['error']) ) {
                        $errorString = sprintf(__('Could not write file %1$s (%2$s)'), $name, $upload['error']);

Great syntax highlighting plugin for WordPress

At times, I think I spend more time writing about using wordpress than actually using it sometimes. I’ll need to fix that. Today, thanks to WordPress’s dashboard, I came across the WP-Codebox plugin. THanks to GeSHI, it can color up a lot of languages and fixes some problems I’ve had with other plugins. Honestly, I’ve never been satisfied with any of them. I think this could change that.

Just to show it off, I present to you some random ruby I wrote the other day when I was working on something. I’ll leave it to you to guess what I’m doing and why with this code. (And I also think I could do it better than using a while loop, but I was able to bang it out quickly for what I needed.)

#!/usr/bin/env ruby
require 'fileutils'

offset = 214

files = Dir['*']

count = 1
while !files.empty?
  file = files.delete_at(rand(files.size))
  extention = File.extname(file).downcase
  name = sprintf('%d%s', count + offset, extention)
  puts "#{file} -> #{name}"
  FileUtils.move(file, name)
  count += 1

Fix/Tricks for plugin auto-update on WordPress 2.5

[READ THIS FIRST!!!  Update 6/13/2009: If you’ve come here looking to get plugin updates to work and you’re using WordPress 2.8, you really want to start with this more recent post on the topic and then come back for the permission information.]

One of the neat features of WordPress 2.5 is the click to install plugin upgrades, assuming the plugin is registered in the WordPress Plugin Directory. If certain conditions are correct on the server it can do it in place, otherwise it tries to do it via FTP.

To make it so wordpress could upgrade them on the server without FTP requires doing some permission changes. You should be aware, the changes I made allow the web server (Apache) to be able to write to the plugin directory. This creates some security exposure. Since I do nightly backups, for me this is an acceptable risk. You may make a different call.

The way I’ve done it also assumes you have admin rights on the unix box or you’re friendly with (s)he who does. Without admin rights to do the group ownership changes, you’re stuck having to make files writable by the world, and that’s not something I’d do. Luckily, I hold the power on the box(es) I care about. Continue reading Fix/Tricks for plugin auto-update on WordPress 2.5