/wp-includes/http.php

  1. <?php 
  2. /** 
  3. * Core HTTP Request API 
  4. * 
  5. * Standardizes the HTTP requests for WordPress. Handles cookies, gzip encoding and decoding, chunk 
  6. * decoding, if HTTP 1.1 and various other difficult HTTP protocol implementations. 
  7. * 
  8. * @package WordPress 
  9. * @subpackage HTTP 
  10. */ 
  11.  
  12. /** 
  13. * Returns the initialized WP_Http Object 
  14. * 
  15. * @since 2.7.0 
  16. * @access private 
  17. * 
  18. * @staticvar WP_Http $http 
  19. * 
  20. * @return WP_Http HTTP Transport object. 
  21. */ 
  22. function _wp_http_get_object() { 
  23. static $http = null; 
  24.  
  25. if ( is_null( $http ) ) { 
  26. $http = new WP_Http(); 
  27. return $http; 
  28.  
  29. /** 
  30. * Retrieve the raw response from a safe HTTP request. 
  31. * 
  32. * This function is ideal when the HTTP request is being made to an arbitrary 
  33. * URL. The URL is validated to avoid redirection and request forgery attacks. 
  34. * 
  35. * @since 3.6.0 
  36. * 
  37. * @see wp_remote_request() For more information on the response array format. 
  38. * @see WP_Http::request() For default arguments information. 
  39. * 
  40. * @param string $url Site URL to retrieve. 
  41. * @param array $args Optional. Request arguments. Default empty array. 
  42. * @return WP_Error|array The response or WP_Error on failure. 
  43. */ 
  44. function wp_safe_remote_request( $url, $args = array() ) { 
  45. $args['reject_unsafe_urls'] = true; 
  46. $http = _wp_http_get_object(); 
  47. return $http->request( $url, $args ); 
  48.  
  49. /** 
  50. * Retrieve the raw response from a safe HTTP request using the GET method. 
  51. * 
  52. * This function is ideal when the HTTP request is being made to an arbitrary 
  53. * URL. The URL is validated to avoid redirection and request forgery attacks. 
  54. * 
  55. * @since 3.6.0 
  56. * 
  57. * @see wp_remote_request() For more information on the response array format. 
  58. * @see WP_Http::request() For default arguments information. 
  59. * 
  60. * @param string $url Site URL to retrieve. 
  61. * @param array $args Optional. Request arguments. Default empty array. 
  62. * @return WP_Error|array The response or WP_Error on failure. 
  63. */ 
  64. function wp_safe_remote_get( $url, $args = array() ) { 
  65. $args['reject_unsafe_urls'] = true; 
  66. $http = _wp_http_get_object(); 
  67. return $http->get( $url, $args ); 
  68.  
  69. /** 
  70. * Retrieve the raw response from a safe HTTP request using the POST method. 
  71. * 
  72. * This function is ideal when the HTTP request is being made to an arbitrary 
  73. * URL. The URL is validated to avoid redirection and request forgery attacks. 
  74. * 
  75. * @since 3.6.0 
  76. * 
  77. * @see wp_remote_request() For more information on the response array format. 
  78. * @see WP_Http::request() For default arguments information. 
  79. * 
  80. * @param string $url Site URL to retrieve. 
  81. * @param array $args Optional. Request arguments. Default empty array. 
  82. * @return WP_Error|array The response or WP_Error on failure. 
  83. */ 
  84. function wp_safe_remote_post( $url, $args = array() ) { 
  85. $args['reject_unsafe_urls'] = true; 
  86. $http = _wp_http_get_object(); 
  87. return $http->post( $url, $args ); 
  88.  
  89. /** 
  90. * Retrieve the raw response from a safe HTTP request using the HEAD method. 
  91. * 
  92. * This function is ideal when the HTTP request is being made to an arbitrary 
  93. * URL. The URL is validated to avoid redirection and request forgery attacks. 
  94. * 
  95. * @since 3.6.0 
  96. * 
  97. * @see wp_remote_request() For more information on the response array format. 
  98. * @see WP_Http::request() For default arguments information. 
  99. * 
  100. * @param string $url Site URL to retrieve. 
  101. * @param array $args Optional. Request arguments. Default empty array. 
  102. * @return WP_Error|array The response or WP_Error on failure. 
  103. */ 
  104. function wp_safe_remote_head( $url, $args = array() ) { 
  105. $args['reject_unsafe_urls'] = true; 
  106. $http = _wp_http_get_object(); 
  107. return $http->head( $url, $args ); 
  108.  
  109. /** 
  110. * Retrieve the raw response from the HTTP request. 
  111. * 
  112. * The array structure is a little complex: 
  113. * 
  114. * $res = array( 
  115. * 'headers' => array(),  
  116. * 'response' => array( 
  117. * 'code' => int,  
  118. * 'message' => string 
  119. * ) 
  120. * ); 
  121. * 
  122. * All of the headers in $res['headers'] are with the name as the key and the 
  123. * value as the value. So to get the User-Agent, you would do the following. 
  124. * 
  125. * $user_agent = $res['headers']['user-agent']; 
  126. * 
  127. * The body is the raw response content and can be retrieved from $res['body']. 
  128. * 
  129. * This function is called first to make the request and there are other API 
  130. * functions to abstract out the above convoluted setup. 
  131. * 
  132. * Request method defaults for helper functions: 
  133. * - Default 'GET' for wp_remote_get() 
  134. * - Default 'POST' for wp_remote_post() 
  135. * - Default 'HEAD' for wp_remote_head() 
  136. * 
  137. * @since 2.7.0 
  138. * 
  139. * @see WP_Http::request() For additional information on default arguments. 
  140. * 
  141. * @param string $url Site URL to retrieve. 
  142. * @param array $args Optional. Request arguments. Default empty array. 
  143. * @return WP_Error|array The response or WP_Error on failure. 
  144. */ 
  145. function wp_remote_request($url, $args = array()) { 
  146. $http = _wp_http_get_object(); 
  147. return $http->request( $url, $args ); 
  148.  
  149. /** 
  150. * Retrieve the raw response from the HTTP request using the GET method. 
  151. * 
  152. * @since 2.7.0 
  153. * 
  154. * @see wp_remote_request() For more information on the response array format. 
  155. * @see WP_Http::request() For default arguments information. 
  156. * 
  157. * @param string $url Site URL to retrieve. 
  158. * @param array $args Optional. Request arguments. Default empty array. 
  159. * @return WP_Error|array The response or WP_Error on failure. 
  160. */ 
  161. function wp_remote_get($url, $args = array()) { 
  162. $http = _wp_http_get_object(); 
  163. return $http->get( $url, $args ); 
  164.  
  165. /** 
  166. * Retrieve the raw response from the HTTP request using the POST method. 
  167. * 
  168. * @since 2.7.0 
  169. * 
  170. * @see wp_remote_request() For more information on the response array format. 
  171. * @see WP_Http::request() For default arguments information. 
  172. * 
  173. * @param string $url Site URL to retrieve. 
  174. * @param array $args Optional. Request arguments. Default empty array. 
  175. * @return WP_Error|array The response or WP_Error on failure. 
  176. */ 
  177. function wp_remote_post($url, $args = array()) { 
  178. $http = _wp_http_get_object(); 
  179. return $http->post( $url, $args ); 
  180.  
  181. /** 
  182. * Retrieve the raw response from the HTTP request using the HEAD method. 
  183. * 
  184. * @since 2.7.0 
  185. * 
  186. * @see wp_remote_request() For more information on the response array format. 
  187. * @see WP_Http::request() For default arguments information. 
  188. * 
  189. * @param string $url Site URL to retrieve. 
  190. * @param array $args Optional. Request arguments. Default empty array. 
  191. * @return WP_Error|array The response or WP_Error on failure. 
  192. */ 
  193. function wp_remote_head($url, $args = array()) { 
  194. $http = _wp_http_get_object(); 
  195. return $http->head( $url, $args ); 
  196.  
  197. /** 
  198. * Retrieve only the headers from the raw response. 
  199. * 
  200. * @since 2.7.0 
  201. * 
  202. * @param array $response HTTP response. 
  203. * @return array The headers of the response. Empty array if incorrect parameter given. 
  204. */ 
  205. function wp_remote_retrieve_headers( $response ) { 
  206. if ( is_wp_error( $response ) || ! isset( $response['headers'] ) ) { 
  207. return array(); 
  208.  
  209. return $response['headers']; 
  210.  
  211. /** 
  212. * Retrieve a single header by name from the raw response. 
  213. * 
  214. * @since 2.7.0 
  215. * 
  216. * @param array $response 
  217. * @param string $header Header name to retrieve value from. 
  218. * @return string The header value. Empty string on if incorrect parameter given, or if the header doesn't exist. 
  219. */ 
  220. function wp_remote_retrieve_header( $response, $header ) { 
  221. if ( is_wp_error( $response ) || ! isset( $response['headers'] ) ) { 
  222. return ''; 
  223.  
  224. if ( isset( $response['headers'][ $header ] ) ) { 
  225. return $response['headers'][$header]; 
  226.  
  227. return ''; 
  228.  
  229. /** 
  230. * Retrieve only the response code from the raw response. 
  231. * 
  232. * Will return an empty array if incorrect parameter value is given. 
  233. * 
  234. * @since 2.7.0 
  235. * 
  236. * @param array $response HTTP response. 
  237. * @return int|string The response code as an integer. Empty string on incorrect parameter given. 
  238. */ 
  239. function wp_remote_retrieve_response_code( $response ) { 
  240. if ( is_wp_error($response) || ! isset($response['response']) || ! is_array($response['response'])) 
  241. return ''; 
  242.  
  243. return $response['response']['code']; 
  244.  
  245. /** 
  246. * Retrieve only the response message from the raw response. 
  247. * 
  248. * Will return an empty array if incorrect parameter value is given. 
  249. * 
  250. * @since 2.7.0 
  251. * 
  252. * @param array $response HTTP response. 
  253. * @return string The response message. Empty string on incorrect parameter given. 
  254. */ 
  255. function wp_remote_retrieve_response_message( $response ) { 
  256. if ( is_wp_error($response) || ! isset($response['response']) || ! is_array($response['response'])) 
  257. return ''; 
  258.  
  259. return $response['response']['message']; 
  260.  
  261. /** 
  262. * Retrieve only the body from the raw response. 
  263. * 
  264. * @since 2.7.0 
  265. * 
  266. * @param array $response HTTP response. 
  267. * @return string The body of the response. Empty string if no body or incorrect parameter given. 
  268. */ 
  269. function wp_remote_retrieve_body( $response ) { 
  270. if ( is_wp_error($response) || ! isset($response['body']) ) 
  271. return ''; 
  272.  
  273. return $response['body']; 
  274.  
  275. /** 
  276. * Retrieve only the cookies from the raw response. 
  277. * 
  278. * @since 4.4.0 
  279. * 
  280. * @param array $response HTTP response. 
  281. * @return array An array of `WP_Http_Cookie` objects from the response. Empty array if there are none, or the response is a WP_Error. 
  282. */ 
  283. function wp_remote_retrieve_cookies( $response ) { 
  284. if ( is_wp_error( $response ) || empty( $response['cookies'] ) ) { 
  285. return array(); 
  286.  
  287. return $response['cookies']; 
  288.  
  289. /** 
  290. * Retrieve a single cookie by name from the raw response. 
  291. * 
  292. * @since 4.4.0 
  293. * 
  294. * @param array $response HTTP response. 
  295. * @param string $name The name of the cookie to retrieve. 
  296. * @return WP_Http_Cookie|string The `WP_Http_Cookie` object. Empty string if the cookie isn't present in the response. 
  297. */ 
  298. function wp_remote_retrieve_cookie( $response, $name ) { 
  299. $cookies = wp_remote_retrieve_cookies( $response ); 
  300.  
  301. if ( empty( $cookies ) ) { 
  302. return ''; 
  303.  
  304. foreach ( $cookies as $cookie ) { 
  305. if ( $cookie->name === $name ) { 
  306. return $cookie; 
  307.  
  308. return ''; 
  309.  
  310. /** 
  311. * Retrieve a single cookie's value by name from the raw response. 
  312. * 
  313. * @since 4.4.0 
  314. * 
  315. * @param array $response HTTP response. 
  316. * @param string $name The name of the cookie to retrieve. 
  317. * @return string The value of the cookie. Empty string if the cookie isn't present in the response. 
  318. */ 
  319. function wp_remote_retrieve_cookie_value( $response, $name ) { 
  320. $cookie = wp_remote_retrieve_cookie( $response, $name ); 
  321.  
  322. if ( ! is_a( $cookie, 'WP_Http_Cookie' ) ) { 
  323. return ''; 
  324.  
  325. return $cookie->value; 
  326.  
  327. /** 
  328. * Determines if there is an HTTP Transport that can process this request. 
  329. * 
  330. * @since 3.2.0 
  331. * 
  332. * @param array $capabilities Array of capabilities to test or a wp_remote_request() $args array. 
  333. * @param string $url Optional. If given, will check if the URL requires SSL and adds 
  334. * that requirement to the capabilities array. 
  335. * 
  336. * @return bool 
  337. */ 
  338. function wp_http_supports( $capabilities = array(), $url = null ) { 
  339. $http = _wp_http_get_object(); 
  340.  
  341. $capabilities = wp_parse_args( $capabilities ); 
  342.  
  343. $count = count( $capabilities ); 
  344.  
  345. // If we have a numeric $capabilities array, spoof a wp_remote_request() associative $args array 
  346. if ( $count && count( array_filter( array_keys( $capabilities ), 'is_numeric' ) ) == $count ) { 
  347. $capabilities = array_combine( array_values( $capabilities ), array_fill( 0, $count, true ) ); 
  348.  
  349. if ( $url && !isset( $capabilities['ssl'] ) ) { 
  350. $scheme = parse_url( $url, PHP_URL_SCHEME ); 
  351. if ( 'https' == $scheme || 'ssl' == $scheme ) { 
  352. $capabilities['ssl'] = true; 
  353.  
  354. return (bool) $http->_get_first_available_transport( $capabilities ); 
  355.  
  356. /** 
  357. * Get the HTTP Origin of the current request. 
  358. * 
  359. * @since 3.4.0 
  360. * 
  361. * @return string URL of the origin. Empty string if no origin. 
  362. */ 
  363. function get_http_origin() { 
  364. $origin = ''; 
  365. if ( ! empty ( $_SERVER[ 'HTTP_ORIGIN' ] ) ) 
  366. $origin = $_SERVER[ 'HTTP_ORIGIN' ]; 
  367.  
  368. /** 
  369. * Change the origin of an HTTP request. 
  370. * 
  371. * @since 3.4.0 
  372. * 
  373. * @param string $origin The original origin for the request. 
  374. */ 
  375. return apply_filters( 'http_origin', $origin ); 
  376.  
  377. /** 
  378. * Retrieve list of allowed HTTP origins. 
  379. * 
  380. * @since 3.4.0 
  381. * 
  382. * @return array Array of origin URLs. 
  383. */ 
  384. function get_allowed_http_origins() { 
  385. $admin_origin = parse_url( admin_url() ); 
  386. $home_origin = parse_url( home_url() ); 
  387.  
  388. // @todo preserve port? 
  389. $allowed_origins = array_unique( array( 
  390. 'http://' . $admin_origin[ 'host' ],  
  391. 'https://' . $admin_origin[ 'host' ],  
  392. 'http://' . $home_origin[ 'host' ],  
  393. 'https://' . $home_origin[ 'host' ],  
  394. ) ); 
  395.  
  396. /** 
  397. * Change the origin types allowed for HTTP requests. 
  398. * 
  399. * @since 3.4.0 
  400. * 
  401. * @param array $allowed_origins { 
  402. * Default allowed HTTP origins. 
  403. * @type string Non-secure URL for admin origin. 
  404. * @type string Secure URL for admin origin. 
  405. * @type string Non-secure URL for home origin. 
  406. * @type string Secure URL for home origin. 
  407. * } 
  408. */ 
  409. return apply_filters( 'allowed_http_origins' , $allowed_origins ); 
  410.  
  411. /** 
  412. * Determines if the HTTP origin is an authorized one. 
  413. * 
  414. * @since 3.4.0 
  415. * 
  416. * @param null|string $origin Origin URL. If not provided, the value of get_http_origin() is used. 
  417. * @return string Origin URL if allowed, empty string if not. 
  418. */ 
  419. function is_allowed_http_origin( $origin = null ) { 
  420. $origin_arg = $origin; 
  421.  
  422. if ( null === $origin ) 
  423. $origin = get_http_origin(); 
  424.  
  425. if ( $origin && ! in_array( $origin, get_allowed_http_origins() ) ) 
  426. $origin = ''; 
  427.  
  428. /** 
  429. * Change the allowed HTTP origin result. 
  430. * 
  431. * @since 3.4.0 
  432. * 
  433. * @param string $origin Origin URL if allowed, empty string if not. 
  434. * @param string $origin_arg Original origin string passed into is_allowed_http_origin function. 
  435. */ 
  436. return apply_filters( 'allowed_http_origin', $origin, $origin_arg ); 
  437.  
  438. /** 
  439. * Send Access-Control-Allow-Origin and related headers if the current request 
  440. * is from an allowed origin. 
  441. * 
  442. * If the request is an OPTIONS request, the script exits with either access 
  443. * control headers sent, or a 403 response if the origin is not allowed. For 
  444. * other request methods, you will receive a return value. 
  445. * 
  446. * @since 3.4.0 
  447. * 
  448. * @return string|false Returns the origin URL if headers are sent. Returns false 
  449. * if headers are not sent. 
  450. */ 
  451. function send_origin_headers() { 
  452. $origin = get_http_origin(); 
  453.  
  454. if ( is_allowed_http_origin( $origin ) ) { 
  455. @header( 'Access-Control-Allow-Origin: ' . $origin ); 
  456. @header( 'Access-Control-Allow-Credentials: true' ); 
  457. if ( 'OPTIONS' === $_SERVER['REQUEST_METHOD'] ) 
  458. exit; 
  459. return $origin; 
  460.  
  461. if ( 'OPTIONS' === $_SERVER['REQUEST_METHOD'] ) { 
  462. status_header( 403 ); 
  463. exit; 
  464.  
  465. return false; 
  466.  
  467. /** 
  468. * Validate a URL for safe use in the HTTP API. 
  469. * 
  470. * @since 3.5.2 
  471. * 
  472. * @param string $url 
  473. * @return false|string URL or false on failure. 
  474. */ 
  475. function wp_http_validate_url( $url ) { 
  476. $original_url = $url; 
  477. $url = wp_kses_bad_protocol( $url, array( 'http', 'https' ) ); 
  478. if ( ! $url || strtolower( $url ) !== strtolower( $original_url ) ) 
  479. return false; 
  480.  
  481. $parsed_url = @parse_url( $url ); 
  482. if ( ! $parsed_url || empty( $parsed_url['host'] ) ) 
  483. return false; 
  484.  
  485. if ( isset( $parsed_url['user'] ) || isset( $parsed_url['pass'] ) ) 
  486. return false; 
  487.  
  488. if ( false !== strpbrk( $parsed_url['host'], ':#?[]' ) ) 
  489. return false; 
  490.  
  491. $parsed_home = @parse_url( get_option( 'home' ) ); 
  492.  
  493. if ( isset( $parsed_home['host'] ) ) { 
  494. $same_host = ( strtolower( $parsed_home['host'] ) === strtolower( $parsed_url['host'] ) || 'localhost' === strtolower( $parsed_url['host'] ) ); 
  495. } else { 
  496. $same_host = false; 
  497.  
  498. if ( ! $same_host ) { 
  499. $host = trim( $parsed_url['host'], '.' ); 
  500. if ( preg_match( '#^(([1-9]?\d|1\d\d|25[0-5]|2[0-4]\d)\.) {3}([1-9]?\d|1\d\d|25[0-5]|2[0-4]\d)$#', $host ) ) { 
  501. $ip = $host; 
  502. } else { 
  503. $ip = gethostbyname( $host ); 
  504. if ( $ip === $host ) // Error condition for gethostbyname() 
  505. $ip = false; 
  506. if ( $ip ) { 
  507. $parts = array_map( 'intval', explode( '.', $ip ) ); 
  508. if ( 127 === $parts[0] || 10 === $parts[0] || 0 === $parts[0] 
  509. || ( 172 === $parts[0] && 16 <= $parts[1] && 31 >= $parts[1] ) 
  510. || ( 192 === $parts[0] && 168 === $parts[1] ) 
  511. ) { 
  512. // If host appears local, reject unless specifically allowed. 
  513. /** 
  514. * Check if HTTP request is external or not. 
  515. * 
  516. * Allows to change and allow external requests for the HTTP request. 
  517. * 
  518. * @since 3.6.0 
  519. * 
  520. * @param bool false Whether HTTP request is external or not. 
  521. * @param string $host IP of the requested host. 
  522. * @param string $url URL of the requested host. 
  523. */ 
  524. if ( ! apply_filters( 'http_request_host_is_external', false, $host, $url ) ) 
  525. return false; 
  526.  
  527. if ( empty( $parsed_url['port'] ) ) 
  528. return $url; 
  529.  
  530. $port = $parsed_url['port']; 
  531. if ( 80 === $port || 443 === $port || 8080 === $port ) 
  532. return $url; 
  533.  
  534. if ( $parsed_home && $same_host && isset( $parsed_home['port'] ) && $parsed_home['port'] === $port ) 
  535. return $url; 
  536.  
  537. return false; 
  538.  
  539. /** 
  540. * Whitelists allowed redirect hosts for safe HTTP requests as well. 
  541. * 
  542. * Attached to the {@see 'http_request_host_is_external'} filter. 
  543. * 
  544. * @since 3.6.0 
  545. * 
  546. * @param bool $is_external 
  547. * @param string $host 
  548. * @return bool 
  549. */ 
  550. function allowed_http_request_hosts( $is_external, $host ) { 
  551. if ( ! $is_external && wp_validate_redirect( 'http://' . $host ) ) 
  552. $is_external = true; 
  553. return $is_external; 
  554.  
  555. /** 
  556. * Whitelists any domain in a multisite installation for safe HTTP requests. 
  557. * 
  558. * Attached to the {@see 'http_request_host_is_external'} filter. 
  559. * 
  560. * @since 3.6.0 
  561. * 
  562. * @global wpdb $wpdb WordPress database abstraction object. 
  563. * @staticvar array $queried 
  564. * 
  565. * @param bool $is_external 
  566. * @param string $host 
  567. * @return bool 
  568. */ 
  569. function ms_allowed_http_request_hosts( $is_external, $host ) { 
  570. global $wpdb; 
  571. static $queried = array(); 
  572. if ( $is_external ) 
  573. return $is_external; 
  574. if ( $host === get_current_site()->domain ) 
  575. return true; 
  576. if ( isset( $queried[ $host ] ) ) 
  577. return $queried[ $host ]; 
  578. $queried[ $host ] = (bool) $wpdb->get_var( $wpdb->prepare( "SELECT domain FROM $wpdb->blogs WHERE domain = %s LIMIT 1", $host ) ); 
  579. return $queried[ $host ]; 
  580.  
  581. /** 
  582. * A wrapper for PHP's parse_url() function that handles edgecases in < PHP 5.4.7 
  583. * 
  584. * PHP 5.4.7 expanded parse_url()'s ability to handle non-absolute url's, including 
  585. * schemeless and relative url's with :// in the path, this works around those 
  586. * limitations providing a standard output on PHP 5.2~5.4+. 
  587. * 
  588. * Error suppression is used as prior to PHP 5.3.3, an E_WARNING would be generated 
  589. * when URL parsing failed. 
  590. * 
  591. * @since 4.4.0 
  592. * 
  593. * @param string $url The URL to parse. 
  594. * @return bool|array False on failure; Array of URL components on success; 
  595. * See parse_url()'s return values. 
  596. */ 
  597. function wp_parse_url( $url ) { 
  598. $parts = @parse_url( $url ); 
  599. if ( ! $parts ) { 
  600. // < PHP 5.4.7 compat, trouble with relative paths including a scheme break in the path 
  601. if ( '/' == $url[0] && false !== strpos( $url, '://' ) ) { 
  602. // Since we know it's a relative path, prefix with a scheme/host placeholder and try again 
  603. if ( ! $parts = @parse_url( 'placeholder://placeholder' . $url ) ) { 
  604. return $parts; 
  605. // Remove the placeholder values 
  606. unset( $parts['scheme'], $parts['host'] ); 
  607. } else { 
  608. return $parts; 
  609.  
  610. // < PHP 5.4.7 compat, doesn't detect schemeless URL's host field 
  611. if ( '//' == substr( $url, 0, 2 ) && ! isset( $parts['host'] ) ) { 
  612. $path_parts = explode( '/', substr( $parts['path'], 2 ), 2 ); 
  613. $parts['host'] = $path_parts[0]; 
  614. if ( isset( $path_parts[1] ) ) { 
  615. $parts['path'] = '/' . $path_parts[1]; 
  616. } else { 
  617. unset( $parts['path'] ); 
  618.  
  619. return $parts; 
.