Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Wordpress - How to extend xmlrpc to retrieve archives
<?php
/**
* Plugin Name: XMLRPC archive
* Plugin Uri: http://localhost/
* Description: Extend Wordpress API to get archives
* Version 1.0
* Author: John Doe
*/
// tested on wordpress 3.5.2
if (!function_exists('add_filter')) {
die('Do not call me directly.');
}
function xmlrpc_archive_get_archives()
{
$links = array();
$archives = wp_get_archives(array('echo' => 0, 'format' => 'custom'));
foreach (simplexml_load_string('<root>' . $archives . '</root>')->children() as $a) {
$links[] = array('href' => (string) $a['href'], 'title' => (string) $a['title']);
}
return $links;
}
function __xmlrpc_archive_methods($methods)
{
if (!isset($methods['wp.getArchives'])) { // XMLRPC method name
return $methods['wp.getArchives'] = 'xmlrpc_archive_get_archives'; // callback
}
}
add_filter('xmlrpc_methods', '__xmlrpc_archive_methods');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment