Skip to content

Instantly share code, notes, and snippets.

@danielbachhuber
Created December 11, 2015 16:51
Show Gist options
  • Save danielbachhuber/cdc34b82b4a2815fb718 to your computer and use it in GitHub Desktop.
Save danielbachhuber/cdc34b82b4a2815fb718 to your computer and use it in GitHub Desktop.
<?php
/**
* See which routes support which contexts
*
* Run with `wp eval-file test-contexts.php --skip-wordpress`
*/
$response = WP_CLI\Utils\http_request( 'GET', 'http://wordpress-develop.dev/wp-json' );
$body = json_decode( $response->body, true );
$data = array();
foreach( $body['routes'] as $route => $values ) {
if ( empty( $values['endpoints'][0]['args']['context'] ) ) {
continue;
}
$data[] = array(
'route' => $route,
'default_context' => $values['endpoints'][0]['args']['context']['default'],
'enum' => ! empty( $values['endpoints'][0]['args']['context']['enum'] ) ? implode( ', ', $values['endpoints'][0]['args']['context']['enum'] ) : '',
);
}
WP_CLI\Utils\format_items( 'table', $data, array( 'route', 'default_context', 'enum' ) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment