Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
like this?
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();
$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