3 * Feed API: WP_SimplePie_File class
11 * Core class for fetching remote files and reading local files with SimplePie.
17 class WP_SimplePie_File extends SimplePie_File {
23 * @since 3.2.0 Updated to use a PHP5 constructor.
26 * @param string $url Remote file URL.
27 * @param integer $timeout Optional. How long the connection should stay open in seconds.
29 * @param integer $redirects Optional. The number of allowed redirects. Default 5.
30 * @param string|array $headers Optional. Array or string of headers to send with the request.
32 * @param string $useragent Optional. User-agent value sent. Default null.
33 * @param boolean $force_fsockopen Optional. Whether to force opening internet or unix domain socket
34 * connection or not. Default false.
36 public function __construct($url, $timeout = 10, $redirects = 5, $headers = null, $useragent = null, $force_fsockopen = false) {
38 $this->timeout = $timeout;
39 $this->redirects = $redirects;
40 $this->headers = $headers;
41 $this->useragent = $useragent;
43 $this->method = SIMPLEPIE_FILE_SOURCE_REMOTE;
45 if ( preg_match('/^http(s)?:\/\//i', $url) ) {
47 'timeout' => $this->timeout,
48 'redirection' => $this->redirects,
51 if ( !empty($this->headers) )
52 $args['headers'] = $this->headers;
54 if ( SIMPLEPIE_USERAGENT != $this->useragent ) //Use default WP user agent unless custom has been specified
55 $args['user-agent'] = $this->useragent;
57 $res = wp_safe_remote_request($url, $args);
59 if ( is_wp_error($res) ) {
60 $this->error = 'WP HTTP Error: ' . $res->get_error_message();
61 $this->success = false;
63 $this->headers = wp_remote_retrieve_headers( $res );
64 $this->body = wp_remote_retrieve_body( $res );
65 $this->status_code = wp_remote_retrieve_response_code( $res );
69 $this->success = false;