Created
September 18, 2015 11:37
-
-
Save RubyRonin/22e688a6861ab681a89f to your computer and use it in GitHub Desktop.
it works
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
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_sites'), WP_JSON_Server::READABLE), | |
); | |
return $routes; | |
} | |
public function 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