Last active
August 29, 2015 14:06
-
-
Save kramapet/9f876ead1241ff0d141d to your computer and use it in GitHub Desktop.
Wordpress - How to extend xmlrpc to retrieve archives
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: 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