-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.php
42 lines (37 loc) · 1.04 KB
/
helpers.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
<?php
/**
* Get dash api config data
*
* @return false|array of data
*/
function dash_config() {
static $config = false;
if ( !$config && file_exists( __DIR__ . '/config.json' ) ) {
$config = json_decode( file_get_contents( __DIR__ . '/config.json' ), true );
}
return $config;
}
/**
* Get data from the MainWP API
*
* @param string $path endpoint route
* @param array $args additional arguments for the api
* @return mixed false if error, otherwise retturned data
*/
function retrieve_data( $path = '', $args = [] ) {
if ( $config = dash_config() ) {
$url = $config['site_url'] . '/wp-json/mainwp/v1/' . $path . "?consumer_key={$config['consumer_key']}&consumer_secret={$config['consumer_secret']}";
if ( count( $args ) ) {
$get_string = '';
foreach ( $args as $key => $value ) {
$get_string .= "&$key=$value";
}
$url .= $get_string;
}
$client = curl_init( $url );
curl_setopt( $client, CURLOPT_RETURNTRANSFER, true );
$response = curl_exec( $client );
return json_decode( $response, true );
}
return false;
}