WP_SimplePie_File

Core class for fetching remote files and reading local files with SimplePie.

Defined (1)

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

/wp-includes/class-wp-simplepie-file.php  
  1. class WP_SimplePie_File extends SimplePie_File { 
  2.  
  3. /** 
  4. * Constructor. 
  5. * @since 2.8.0 
  6. * @since 3.2.0 Updated to use a PHP5 constructor. 
  7. * @access public 
  8. * @param string $url Remote file URL. 
  9. * @param integer $timeout Optional. How long the connection should stay open in seconds. 
  10. * Default 10. 
  11. * @param integer $redirects Optional. The number of allowed redirects. Default 5. 
  12. * @param string|array $headers Optional. Array or string of headers to send with the request. 
  13. * Default null. 
  14. * @param string $useragent Optional. User-agent value sent. Default null. 
  15. * @param boolean $force_fsockopen Optional. Whether to force opening internet or unix domain socket 
  16. * connection or not. Default false. 
  17. */ 
  18. public function __construct($url, $timeout = 10, $redirects = 5, $headers = null, $useragent = null, $force_fsockopen = false) { 
  19. $this->url = $url; 
  20. $this->timeout = $timeout; 
  21. $this->redirects = $redirects; 
  22. $this->headers = $headers; 
  23. $this->useragent = $useragent; 
  24.  
  25. $this->method = SIMPLEPIE_FILE_SOURCE_REMOTE; 
  26.  
  27. if ( preg_match('/^http(s)?:\/\//i', $url) ) { 
  28. $args = array( 
  29. 'timeout' => $this->timeout,  
  30. 'redirection' => $this->redirects,  
  31. ); 
  32.  
  33. if ( !empty($this->headers) ) 
  34. $args['headers'] = $this->headers; 
  35.  
  36. if ( SIMPLEPIE_USERAGENT != $this->useragent ) //Use default WP user agent unless custom has been specified 
  37. $args['user-agent'] = $this->useragent; 
  38.  
  39. $res = wp_safe_remote_request($url, $args); 
  40.  
  41. if ( is_wp_error($res) ) { 
  42. $this->error = 'WP HTTP Error: ' . $res->get_error_message(); 
  43. $this->success = false; 
  44. } else { 
  45. $this->headers = wp_remote_retrieve_headers( $res ); 
  46. $this->body = wp_remote_retrieve_body( $res ); 
  47. $this->status_code = wp_remote_retrieve_response_code( $res ); 
  48. } else { 
  49. $this->error = ''; 
  50. $this->success = false;