Skip to content

Instantly share code, notes, and snippets.

@nacin
Created April 26, 2012 16:33
Show Gist options
  • Save nacin/2500819 to your computer and use it in GitHub Desktop.
Save nacin/2500819 to your computer and use it in GitHub Desktop.
mu-plugins/extending-xmlrpc.php
<?php
/**
* Plugin Name: jQuery extends WordPress XML-RPC
* Description: Enables XML-RPC and adds custom methods.
*/
add_action( 'enable_xmlrpc', '__return_true' );
function jquery_get_post_paths( $args ) {
$post_type = sanitize_key( $args[0] );
$results = array();
$query = new WP_Query( array(
'post_type' => $post_type,
'post_status' => 'publish',
'posts_per_page' => -1,
'update_post_term_cache' => false,
'update_post_meta_cache' => false,
) );
foreach ( $query->posts as $post )
$results[ $post->post_type . '/' . get_page_uri( $post->ID ) ] = $post->ID;
return $results;
}
function jquery_register_xmlrpc_methods( $methods ) {
$methods['jquery.get_post_paths'] = 'jquery_get_post_paths';
return $methods;
}
add_filter( 'xmlrpc_methods', 'jquery_register_xmlrpc_methods' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment