Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?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