Skip to content

Instantly share code, notes, and snippets.

@kramapet
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kramapet/9f876ead1241ff0d141d to your computer and use it in GitHub Desktop.
Save kramapet/9f876ead1241ff0d141d to your computer and use it in GitHub Desktop.
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