Created
April 26, 2012 16:33
-
-
Save nacin/2500819 to your computer and use it in GitHub Desktop.
mu-plugins/extending-xmlrpc.php
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: 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