forked from YTTechiePress/query-apis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquery-apis.php
51 lines (43 loc) · 1.19 KB
/
query-apis.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
42
43
44
45
46
47
48
49
50
51
<?php
/**
* Plugin name: Query APIs
* Plugin URI: https://omukiguy.com
* Description: Get information from external APIs in WordPress
* Author: Laurence Bahiirwa
* Author URI: https://omukiguy.com
* version: 0.1.0
* License: GPL2 or later.
* text-domain: query-apis
*/
// If this file is access directly, abort!!!
defined( 'ABSPATH' ) or die( 'Unauthorized Access' );
function techiepress_get_send_data() {
$url = 'https://jsonplaceholder.typicode.com/users';
$arguments = array(
'method' => 'GET'
);
$response = wp_remote_get( $url, $arguments );
if ( is_wp_error( $response ) ) {
$error_message = $response->get_error_message();
return "Something went wrong: $error_message";
} else {
echo '<pre>';
var_dump( wp_remote_retrieve_body( $response ) );
echo '</pre>';
}
}
/**
* Register a custom menu page to view the information queried.
*/
function techiepress_register_my_custom_menu_page() {
add_menu_page(
__( 'Query API Test Settings', 'query-apis' ),
'Query API Test',
'manage_options',
'api-test.php',
'techiepress_get_send_data',
'dashicons-testimonial',
16
);
}
add_action( 'admin_menu', 'techiepress_register_my_custom_menu_page' );