Created
September 17, 2021 07:02
-
-
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
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 | |
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