How to process shortcodes in XML-RPC

Explanation of the behavior

A shortcode is meant to be processed during runtime (when rendering & displaying a post on the public facing view). It is absolutely not meant to be a pre-processor during saving the post. The receiver simply doesn’t have your parser (which is the function processing the shortcode) and therefore will get the raw result.

How to “fix” it

Just a note upfront: When you’re doing this, it won’t be reversible. The shortcode will get transformed to whatever it is replaced with and the result will then be saved as post content.

You will want to use the

to pre-process the post and replace the shortcode tag with it’s actual content. Another option you might want to consider is the

or

To grab the shortcode you’ll want to use get_shortcode_regex().

Hooks and XML RPC?

I’m not sure if the following works. It is well known that one can extend the XML RPC interface, but it seems that there’re options/hooks to alter the returned values (at least it also does query for posts).

AS Matthew Murow explains, you could check (in a plugin) if you have an XML RPC request and then intercept during the hook:

if ( 
    defined ( 'XMLRPC_REQUEST' )
    AND XMLRPC_REQUEST
)
    add_action( 'xmlrpc_call', 'example_xmlrpc_posts_callback' );

Inside your callback, hook into the pre_get_posts (…) filter

This would look similar to this:

function example_xmlrpc_posts_callback( $task )
{
    if ( 'wp.getPosts' !== $task )
        return;

    add_filter( 'pre_get_posts', 'xmlrpc_pre_get_posts' );
}
function xmlrpc_pre_get_posts( $data )
{
    // Only run once - do not intercept later queries
    remove_filter( current_filter(), __FUNCTION__, 10 );

    // Alter output:
    // pre-process shortcodes

    return $data;
}