Skip to content

Instantly share code, notes, and snippets.

@thierrypigot
Created September 17, 2021 07:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thierrypigot/d144826a62a3ac8603184e2d99c29135 to your computer and use it in GitHub Desktop.
Save thierrypigot/d144826a62a3ac8603184e2d99c29135 to your computer and use it in GitHub Desktop.
WordPress Rest API - Ajout endpoint liste de tous les sites d'un multisites
<?php
function wearewp_api_custom_route_get_sites() {
$args = array(
'public' => 1, // I only want the sites marked Public
'archived' => 0,
'mature' => 0,
'spam' => 0,
'deleted' => 0,
);
$sites = get_sites( $args );
return $sites;
}
add_action('rest_api_init', function() {
register_rest_route('wp/v2', 'sites', [
'methods' => 'GET',
'callback' => 'wearewp_api_custom_route_get_sites'
]);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment