-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-wp-api-endpoints.php
41 lines (38 loc) · 1.54 KB
/
test-wp-api-endpoints.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
/*
Plugin Name: Test WP API Endpoints
Description: Test authenticated registered endpoint routes without having to worry about nonce and all that.
Version: 1.0
*/
add_action( 'admin_menu', 'test_wp_api_endpoints_register_admin_page', 1 );
function test_wp_api_endpoints_register_admin_page() {
add_menu_page( 'Test WP API', 'Test WP API Endpoints', 'manage_options', 'test-wp-api-endpoints', 'test_wp_api_endpoints_render_main_page' );
}
function test_wp_api_endpoints_render_main_page() {
wp_enqueue_script( 'test-wp-api-endpoint', plugin_dir_url( __FILE__ ) . 'admin.js', array(), true );
wp_localize_script( 'test-wp-api-endpoint', 'testStuff', array(
'root' => esc_url_raw( rest_url() ),
'nonce' => wp_create_nonce( 'wp_rest' ),
) );
// Get all registered endpoints
$registered_endpoints = json_decode( file_get_contents( get_home_url() . '/wp-json' ) );
?>
<h2>Copy/paste one of these registered endpoints to test.</h2>
<strong>Currently registered:</strong><br>
<?php
foreach ( $registered_endpoints->routes as $route => $route_details ) {
// Only show jetpack ones
if ( ! strpos( $route, 'jetpack' ) ) {
continue;
}
echo '<strong>' . $route_details->methods[0] . '</strong> -- ' . substr( $route, 1 ) . '<br>';
}
?>
<select name="wp-api-endpoint-type" id="wp-api-endpoint-type">
<option value="GET">GET</option>
<option value="POST">POST</option>
</select>
<input type="text" id="wp-api-endpoint">
<button id="wp-api-endpoint-do-it">Do it!</button>
<div id="display-wp-api-endpoint-response"></div>
<?php }