WPSEO_OnPage_Request

This class will fetch a new status from OnPage.org and if it's necessary it will notify the site admin by email and remove the current meta value for hidding the notice for all admin users.

Defined (1)

The class is defined in the following location(s).

/admin/onpage/class-onpage-request.php  
  1. class WPSEO_OnPage_Request { 
  2.  
  3. /** 
  4. * @var string The endpoint where the request will be send to. 
  5. */ 
  6. private $onpage_endpoint = 'https://indexability.yoast.onpage.org/'; 
  7.  
  8. /** 
  9. * Doing the remote get and returns the body 
  10. * @param string $target_url The home url. 
  11. * @param array $parameters Array of extra parameters to send to OnPage. 
  12. * @return array 
  13. * @throws Exception The error message that can be used to show to the user. 
  14. */ 
  15. protected function get_remote( $target_url, $parameters = array() ) { 
  16. $parameters = array_merge( array( 
  17. 'url' => $target_url,  
  18. 'wp_version' => $GLOBALS['wp_version'],  
  19. 'yseo_version' => WPSEO_VERSION,  
  20. ), $parameters ); 
  21.  
  22. $url = add_query_arg( $parameters, $this->onpage_endpoint ); 
  23.  
  24. $response = wp_remote_get( $url ); 
  25. $response_code = wp_remote_retrieve_response_code( $response ); 
  26.  
  27. // When the request is successful, the response code will be 200. 
  28. if ( $response_code === 200 ) { 
  29. $response_body = wp_remote_retrieve_body( $response ); 
  30.  
  31. return json_decode( $response_body, true ); 
  32.  
  33. /** 
  34. * Sending a request to OnPage to check if the $home_url is indexable 
  35. * @param string $target_url The URL that will be send to the API. 
  36. * @param array $parameters Array of extra parameters to send to OnPage. 
  37. * @return array 
  38. */ 
  39. public function do_request( $target_url, $parameters = array() ) { 
  40. $json_body = $this->get_remote( $target_url, $parameters ); 
  41.  
  42. // OnPage.org recognized a redirect, fetch the data of that URL by calling this method with the value from OnPage.org. 
  43. if ( ! empty( $json_body['passes_juice_to'] ) ) { 
  44. return $this->do_request( $json_body['passes_juice_to'], $parameters ); 
  45.  
  46. return $json_body; 
  47.  
  48. /** 
  49. * Returns the fetched response 
  50. * @deprecated 3.1.2 
  51. * @codeCoverageIgnore 
  52. * @return array 
  53. */ 
  54. public function get_response() { 
  55. _deprecated_function( __METHOD__, 'WPSEO 3.1.2', 'WPSEO_OnPage_Request::do_request' ); 
  56.  
  57. return array();