13 * |
13 * |
14 * @return array |
14 * @return array |
15 */ |
15 */ |
16 function get_importers() { |
16 function get_importers() { |
17 global $wp_importers; |
17 global $wp_importers; |
18 if ( is_array($wp_importers) ) |
18 if ( is_array( $wp_importers ) ) { |
19 uasort($wp_importers, create_function('$a, $b', 'return strcmp($a[0], $b[0]);')); |
19 uasort( $wp_importers, '_usort_by_first_member' ); |
|
20 } |
20 return $wp_importers; |
21 return $wp_importers; |
|
22 } |
|
23 |
|
24 /** |
|
25 * Sorts a multidimensional array by first member of each top level member |
|
26 * |
|
27 * Used by uasort() as a callback, should not be used directly. |
|
28 * |
|
29 * @since 2.9.0 |
|
30 * @access private |
|
31 * |
|
32 * @param array $a |
|
33 * @param array $b |
|
34 * @return int |
|
35 */ |
|
36 function _usort_by_first_member( $a, $b ) { |
|
37 return strnatcasecmp( $a[0], $b[0] ); |
21 } |
38 } |
22 |
39 |
23 /** |
40 /** |
24 * Register importer for WordPress. |
41 * Register importer for WordPress. |
25 * |
42 * |
57 * @since 2.0.0 |
74 * @since 2.0.0 |
58 * |
75 * |
59 * @return array Uploaded file's details on success, error message on failure |
76 * @return array Uploaded file's details on success, error message on failure |
60 */ |
77 */ |
61 function wp_import_handle_upload() { |
78 function wp_import_handle_upload() { |
62 if ( !isset($_FILES['import']) ) { |
79 if ( ! isset( $_FILES['import'] ) ) { |
63 $file['error'] = __( 'File is empty. Please upload something more substantial. This error could also be caused by uploads being disabled in your php.ini or by post_max_size being defined as smaller than upload_max_filesize in php.ini.' ); |
80 return array( |
64 return $file; |
81 'error' => __( 'File is empty. Please upload something more substantial. This error could also be caused by uploads being disabled in your php.ini or by post_max_size being defined as smaller than upload_max_filesize in php.ini.' ) |
|
82 ); |
65 } |
83 } |
66 |
84 |
67 $overrides = array( 'test_form' => false, 'test_type' => false ); |
85 $overrides = array( 'test_form' => false, 'test_type' => false ); |
68 $_FILES['import']['name'] .= '.txt'; |
86 $_FILES['import']['name'] .= '.txt'; |
69 $file = wp_handle_upload( $_FILES['import'], $overrides ); |
87 $upload = wp_handle_upload( $_FILES['import'], $overrides ); |
70 |
88 |
71 if ( isset( $file['error'] ) ) |
89 if ( isset( $upload['error'] ) ) { |
72 return $file; |
90 return $upload; |
73 |
91 } |
74 $url = $file['url']; |
|
75 $type = $file['type']; |
|
76 $file = $file['file']; |
|
77 $filename = basename( $file ); |
|
78 |
92 |
79 // Construct the object array |
93 // Construct the object array |
80 $object = array( 'post_title' => $filename, |
94 $object = array( |
81 'post_content' => $url, |
95 'post_title' => basename( $upload['file'] ), |
82 'post_mime_type' => $type, |
96 'post_content' => $upload['url'], |
83 'guid' => $url, |
97 'post_mime_type' => $upload['type'], |
|
98 'guid' => $upload['url'], |
84 'context' => 'import', |
99 'context' => 'import', |
85 'post_status' => 'private' |
100 'post_status' => 'private' |
86 ); |
101 ); |
87 |
102 |
88 // Save the data |
103 // Save the data |
89 $id = wp_insert_attachment( $object, $file ); |
104 $id = wp_insert_attachment( $object, $upload['file'] ); |
90 |
105 |
91 // schedule a cleanup for one day from now in case of failed import or missing wp_import_cleanup() call |
106 /* |
|
107 * Schedule a cleanup for one day from now in case of failed |
|
108 * import or missing wp_import_cleanup() call. |
|
109 */ |
92 wp_schedule_single_event( time() + DAY_IN_SECONDS, 'importer_scheduled_cleanup', array( $id ) ); |
110 wp_schedule_single_event( time() + DAY_IN_SECONDS, 'importer_scheduled_cleanup', array( $id ) ); |
93 |
111 |
94 return array( 'file' => $file, 'id' => $id ); |
112 return array( 'file' => $upload['file'], 'id' => $id ); |
95 } |
113 } |
96 |
114 |
97 /** |
115 /** |
98 * Returns a list from WordPress.org of popular importer plugins. |
116 * Returns a list from WordPress.org of popular importer plugins. |
99 * |
117 * |
100 * @since 3.5.0 |
118 * @since 3.5.0 |
101 * |
119 * |
102 * @return array Importers with metadata for each. |
120 * @return array Importers with metadata for each. |
103 */ |
121 */ |
104 function wp_get_popular_importers() { |
122 function wp_get_popular_importers() { |
105 include ABSPATH . WPINC . '/version.php'; // include an unmodified $wp_version |
123 include( ABSPATH . WPINC . '/version.php' ); // include an unmodified $wp_version |
106 |
124 |
107 $locale = get_locale(); |
125 $locale = get_locale(); |
108 $popular_importers = get_site_transient( 'popular_importers_' . $locale ); |
126 $popular_importers = get_site_transient( 'popular_importers_' . $locale ); |
109 |
127 |
110 if ( ! $popular_importers ) { |
128 if ( ! $popular_importers ) { |