Created
March 10, 2012 07:06
-
-
Save chrisguitarguy/2010630 to your computer and use it in GitHub Desktop.
autop your XMLRPC posts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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