Skip to content

Instantly share code, notes, and snippets.

@Gkiokan
Created April 12, 2017 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gkiokan/3fd6c54cac08d4b8a82725034b01ec8f to your computer and use it in GitHub Desktop.
Save Gkiokan/3fd6c54cac08d4b8a82725034b01ec8f to your computer and use it in GitHub Desktop.
WP Remote Helper
<?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