Skip to content

Instantly share code, notes, and snippets.

@chrisguitarguy
Created March 10, 2012 07:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save chrisguitarguy/2010630 to your computer and use it in GitHub Desktop.
Save chrisguitarguy/2010630 to your computer and use it in GitHub Desktop.
autop your XMLRPC posts
<?php
/*
Plugin Name: Autop XMLRPC Content
Description: A custom XMLRPC method that allows WordPresss to add autop to posts.
Author: Christopher Davis
Author URI: http://christopherdavis.me
License: GPL2
*/
add_filter( 'xmlrpc_methods', 'wpse44849_xmlrpc_methods' );
/**
* Filters the XMLRPC method to include our own custom method
*/
function wpse44849_xmlrpc_methods( $method )
{
$methods['post_autop'] = 'wpse44849_autop_callback';
return $methods;
}
/**
* Callback function for our custom XML RPC method. Stolen from the
*/
function wpse44849_autop_callback( $args )
{
$post_ID = absint( $args[0] );
$username = $args[1];
$password = $args[2];
$user = wp_authenticate( $username, $password );
// not a valid user name/password? bail.
if( ! $user || is_wp_error( $user ) )
{
return false;
}
$post = get_posts( array( 'p' => $post_ID ) );
// no posts? bail.
if( empty( $post ) )
{
return false;
}
$post = $post[0];
// the magic happens here
$post->post_content = wpautop( $post->post_content );
return (array) $post;
}
@EricIsGood
Copy link

This is great, thanks!
Could you tell me how to make this take effect when I get the full site XML from: Tools -> Export -> All Content

Thanks,
-Eric

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment