WordPress 2.7 xmlrpc.php Monkey Patches

I’ve been fighting with WordPress 2.7’s xmlrpc.php file for a few days now, and I’ve made 2 modifications that may be useful to you.

If you’re writing new posts via metaWeblog.newPost and the angle brackets from your HTML formatting are being stripped out (as described in this official WordPress bug report) and you’d rather not rebuild PHP on your server (who does?), open up xmlrpc.php and replace:

$post_content = apply_filters( 'content_save_pre', $content_struct['description'] );

with

$post_content = apply_filters( 'content_save_pre', $content_struct['description'] );
$post_content = str_replace('lt;', '< ', $post_content); $post_content = str_replace('gt;', '>', $post_content);

This should replace the stripped angle brackets with actual, functioning angle brackets.

Secondly, if you’re having trouble uploading files via metaWeblog.newMediaObject, try this fix (big thanks to Keith Garner). In xmlrpc.php replace:
$bits = $data['bits'];
with

$bits = $data['bits'];
$bits = base64_decode($bits);

WordPress has given me quite a roller coaster ride these past couple years. While 2.7 is a huge improvement over the last couple releases, if I wasn’t so committed, I’d be looking for something much leaner.

Update 30 Dec 2008
Big thanks to Daniel Jalkut for commenting that the reason I needed $bits = base64_decode($bits); was probably due to my bits not being properly encoded. Correct he was. So, rather than a bug in WordPress, this is a bug in Applescript (what isn’t) and in Ruby’s XMLRPC/client for failing the Principle of Least Surprise (if the spec says the tag is <base64>, the tag should be <base64> not <string>).

To get the <base64> tags in Ruby, you need to encode with XMLRPC::Base64.new(the_file) not simply Base64.encode(the_file)