Ticket #2551: enclosure-redirects-patch.txt

File enclosure-redirects-patch.txt, 839 bytes (added by aegrumet, 6 years ago)

Same code, should be easier to read

Line 
1Index: wp-includes/functions.php
2===================================================================
3--- wp-includes/functions.php   (revision 3636)
4+++ wp-includes/functions.php   (working copy)
5@@ -1216,15 +1216,13 @@
6                $headers["$key"] = $matches[2][$i];
7        }
8 
9-    $code = preg_replace('/.*?(\d{3}).*/i', '$1', $response);
10-   
11-    $headers['status_code'] = $code;
12-   
13-    if ( '302' == $code || '301' == $code )
14-        return wp_get_http_headers( $url, ++$red );
15-
16        preg_match('/.*([0-9]{3}).*/', $response, $return);
17        $headers['response'] = $return[1]; // HTTP response code eg 204, 200, 404
18+
19+    $code = $headers['response'];
20+    if ( ('302' == $code || '301' == $code) && isset($headers['location']) )
21+        return wp_get_http_headers( $headers['location'], ++$red );
22+
23        return $headers;
24 }
25