Ticket #21007: importer.diff

File importer.diff, 1.5 KB (added by SeMeKh, 11 months ago)

Patch to fix the omitted-backslashes bug

Line 
1Index: wordpress-importer.php
2===================================================================
3--- wordpress-importer.php      (revision 558445)
4+++ wordpress-importer.php      (working copy)
5@@ -596,7 +596,8 @@
6 
7                                        $comment_post_ID = $post_id = $this->process_attachment( $postdata, $remote_url );
8                                } else {
9-                                       $comment_post_ID = $post_id = wp_insert_post( $postdata, true );
10+                                       $comment_post_ID = $post_id = wp_insert_post( $this->addslashes_deep( $postdata ), true );
11+//                                     $comment_post_ID = $post_id = wp_insert_post( $postdata, true );
12                                }
13 
14                                if ( is_wp_error( $post_id ) ) {
15@@ -1081,6 +1082,30 @@
16        function cmpr_strlen( $a, $b ) {
17                return strlen($b) - strlen($a);
18        }
19+
20+       /**
21+        * Navigates through an array and add slashes to escape the values.
22+        *
23+        * If an array is passed, the array_map() function causes a callback to pass the
24+        * value back to the function. This value will be slash-escaped.
25+        *
26+        * @param array|string $value The array or string to be escaped
27+        * @return array|string Escaped array (or string in the callback).
28+        */
29+       function addslashes_deep($value) {
30+               if ( is_array($value) ) {
31+                       $value = array_map(array(&$this, 'addslashes_deep'), $value);
32+               } elseif ( is_object($value) ) {
33+                       $vars = get_object_vars( $value );
34+                       foreach ($vars as $key=>$data) {
35+                               $value->{$key} = addslashes_deep( $data );
36+                       }
37+               } else {
38+                       $value = addslashes($value);
39+               }
40+
41+               return $value;
42+       }
43 }
44 
45 } // class_exists( 'WP_Importer' )