Created
September 18, 2015 10:36
-
-
Save RubyRonin/6cd82ec79e774940f492 to your computer and use it in GitHub Desktop.
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: WP REST API Multisite | |
* Plugin URI: https://github.com/epfl-lts2/json-rest-api-multisites/ | |
* Description: Very simple site endpoint for WP REST API | |
* Version: 0.1 | |
* Author: Maximilien Cuony | |
* Author URI: https://github.com/the-glu | |
* License: MIT | |
* */ | |
function json_rest_api_multisites_api_init() { | |
global $json_rest_api_multisites_api_site; | |
$json_rest_api_multisites_api_site = new JsonRESTAPIMultiSites_API_Site(); | |
add_filter('json_endpoints', array($json_rest_api_multisites_api_site, 'register_routes')); | |
} | |
add_action( 'wp_json_server_before_serve', 'json_rest_api_multisites_api_init'); | |
class JsonRESTAPIMultiSites_API_Site { | |
public function register_routes($routes) { | |
$routes['/sites'] = array( | |
array(array($this, 'get_site_details'), WP_JSON_Server::READABLE), | |
); | |
return $routes; | |
} | |
public function get_sites() { | |
return wp_get_sites(); | |
} | |
public function get_site_details(){ | |
$sites = wp_get_sites(); | |
$sites_with_names = array(); | |
} | |
foreach( $sites as $key, $value) { | |
$sites_with_names[] = get_blog_details($value['blog_id']); | |
} | |
return $sites_with_names; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment