Advertisement
shelob9

Untitled

Jul 31st, 2016
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. function slug_make_request( $api ){
  2. $r = wp_remote_request( $api );
  3. if( is_wp_error( $r ) ){
  4. throw new Exception( $r->get_error_message() );
  5. }
  6.  
  7. return wp_remote_retrieve_body( $r );
  8. }
  9.  
  10. try {
  11. $url = 'http://somurl.com/wp-json';
  12. $response = slug_make_request( $url );
  13. } catch (Exception $e) {
  14.  
  15. if( class_exists( 'WP_Papertrail_API' ) ){
  16. WP_Papertrail_API::log( [
  17. 'error' => $e->getMessage(),
  18. 'url' => $url
  19. ], 'api_request_failed' );
  20. }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement