Created
April 12, 2017 13:59
-
-
Save Gkiokan/3fd6c54cac08d4b8a82725034b01ec8f to your computer and use it in GitHub Desktop.
WP Remote Helper
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 | |
/* | |
Author: Gkiokan | |
Date: 12.04.2017 | |
URI: www.gkiokan.net | |
Comment: Helps to send easy wp_remote_get/_post | |
*/ | |
class WP_Remote_Helper { | |
/* | |
Method GET | |
@param $url Adress to call | |
@return json_decoded Object | |
*/ | |
public function send($url=null){ | |
if(!$url) return "No url given..."; | |
$request = wp_remote_get( $url, ['method' => 'get', 'timeout' => 45, 'body' => '' ]); | |
$body = wp_remote_retrieve_body($request); | |
$body = json_decode($body, true, true); | |
return $body; | |
} | |
/* | |
Method: POST | |
@param $url Adress to call | |
@param $data Post Data as Array | |
@return json_decoded Object | |
*/ | |
public function post($url=null, $data=null){ | |
if(!$url) return "No url given..."; | |
$request = wp_remote_post( $url, ['method' => 'POST', 'timeout' => 45, 'body' => $data ]); | |
$body = wp_remote_retrieve_body($request); | |
$body = json_decode($body, true, true); | |
return $body; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment