80 * @return array Uploaded file's details on success, error message on failure |
80 * @return array Uploaded file's details on success, error message on failure |
81 */ |
81 */ |
82 function wp_import_handle_upload() { |
82 function wp_import_handle_upload() { |
83 if ( ! isset( $_FILES['import'] ) ) { |
83 if ( ! isset( $_FILES['import'] ) ) { |
84 return array( |
84 return array( |
85 '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.' ), |
85 'error' => sprintf( |
|
86 /* translators: 1: php.ini, 2: post_max_size, 3: upload_max_filesize */ |
|
87 __( 'File is empty. Please upload something more substantial. This error could also be caused by uploads being disabled in your %1$s file or by %2$s being defined as smaller than %3$s in %1$s.' ), |
|
88 'php.ini', |
|
89 'post_max_size', |
|
90 'upload_max_filesize' |
|
91 ), |
86 ); |
92 ); |
87 } |
93 } |
88 |
94 |
89 $overrides = array( |
95 $overrides = array( |
90 'test_form' => false, |
96 'test_form' => false, |
95 |
101 |
96 if ( isset( $upload['error'] ) ) { |
102 if ( isset( $upload['error'] ) ) { |
97 return $upload; |
103 return $upload; |
98 } |
104 } |
99 |
105 |
100 // Construct the object array |
106 // Construct the object array. |
101 $object = array( |
107 $object = array( |
102 'post_title' => wp_basename( $upload['file'] ), |
108 'post_title' => wp_basename( $upload['file'] ), |
103 'post_content' => $upload['url'], |
109 'post_content' => $upload['url'], |
104 'post_mime_type' => $upload['type'], |
110 'post_mime_type' => $upload['type'], |
105 'guid' => $upload['url'], |
111 'guid' => $upload['url'], |
106 'context' => 'import', |
112 'context' => 'import', |
107 'post_status' => 'private', |
113 'post_status' => 'private', |
108 ); |
114 ); |
109 |
115 |
110 // Save the data |
116 // Save the data. |
111 $id = wp_insert_attachment( $object, $upload['file'] ); |
117 $id = wp_insert_attachment( $object, $upload['file'] ); |
112 |
118 |
113 /* |
119 /* |
114 * Schedule a cleanup for one day from now in case of failed |
120 * Schedule a cleanup for one day from now in case of failed |
115 * import or missing wp_import_cleanup() call. |
121 * import or missing wp_import_cleanup() call. |
128 * @since 3.5.0 |
134 * @since 3.5.0 |
129 * |
135 * |
130 * @return array Importers with metadata for each. |
136 * @return array Importers with metadata for each. |
131 */ |
137 */ |
132 function wp_get_popular_importers() { |
138 function wp_get_popular_importers() { |
133 include( ABSPATH . WPINC . '/version.php' ); // include an unmodified $wp_version |
139 // Include an unmodified $wp_version. |
|
140 require ABSPATH . WPINC . '/version.php'; |
134 |
141 |
135 $locale = get_user_locale(); |
142 $locale = get_user_locale(); |
136 $cache_key = 'popular_importers_' . md5( $locale . $wp_version ); |
143 $cache_key = 'popular_importers_' . md5( $locale . $wp_version ); |
137 $popular_importers = get_site_transient( $cache_key ); |
144 $popular_importers = get_site_transient( $cache_key ); |
138 |
145 |
167 } |
174 } |
168 |
175 |
169 foreach ( $popular_importers['importers'] as &$importer ) { |
176 foreach ( $popular_importers['importers'] as &$importer ) { |
170 // phpcs:ignore WordPress.WP.I18n.LowLevelTranslationFunction,WordPress.WP.I18n.NonSingularStringLiteralText |
177 // phpcs:ignore WordPress.WP.I18n.LowLevelTranslationFunction,WordPress.WP.I18n.NonSingularStringLiteralText |
171 $importer['description'] = translate( $importer['description'] ); |
178 $importer['description'] = translate( $importer['description'] ); |
172 if ( $importer['name'] != 'WordPress' ) { |
179 if ( 'WordPress' !== $importer['name'] ) { |
173 // phpcs:ignore WordPress.WP.I18n.LowLevelTranslationFunction,WordPress.WP.I18n.NonSingularStringLiteralText |
180 // phpcs:ignore WordPress.WP.I18n.LowLevelTranslationFunction,WordPress.WP.I18n.NonSingularStringLiteralText |
174 $importer['name'] = translate( $importer['name'] ); |
181 $importer['name'] = translate( $importer['name'] ); |
175 } |
182 } |
176 } |
183 } |
177 return $popular_importers['importers']; |
184 return $popular_importers['importers']; |
178 } |
185 } |
179 |
186 |
180 return array( |
187 return array( |
181 // slug => name, description, plugin slug, and register_importer() slug |
188 // slug => name, description, plugin slug, and register_importer() slug. |
182 'blogger' => array( |
189 'blogger' => array( |
183 'name' => __( 'Blogger' ), |
190 'name' => __( 'Blogger' ), |
184 'description' => __( 'Import posts, comments, and users from a Blogger blog.' ), |
191 'description' => __( 'Import posts, comments, and users from a Blogger blog.' ), |
185 'plugin-slug' => 'blogger-importer', |
192 'plugin-slug' => 'blogger-importer', |
186 'importer-id' => 'blogger', |
193 'importer-id' => 'blogger', |
201 'name' => __( 'Movable Type and TypePad' ), |
208 'name' => __( 'Movable Type and TypePad' ), |
202 'description' => __( 'Import posts and comments from a Movable Type or TypePad blog.' ), |
209 'description' => __( 'Import posts and comments from a Movable Type or TypePad blog.' ), |
203 'plugin-slug' => 'movabletype-importer', |
210 'plugin-slug' => 'movabletype-importer', |
204 'importer-id' => 'mt', |
211 'importer-id' => 'mt', |
205 ), |
212 ), |
206 'opml' => array( |
|
207 'name' => __( 'Blogroll' ), |
|
208 'description' => __( 'Import links in OPML format.' ), |
|
209 'plugin-slug' => 'opml-importer', |
|
210 'importer-id' => 'opml', |
|
211 ), |
|
212 'rss' => array( |
213 'rss' => array( |
213 'name' => __( 'RSS' ), |
214 'name' => __( 'RSS' ), |
214 'description' => __( 'Import posts from an RSS feed.' ), |
215 'description' => __( 'Import posts from an RSS feed.' ), |
215 'plugin-slug' => 'rss-importer', |
216 'plugin-slug' => 'rss-importer', |
216 'importer-id' => 'rss', |
217 'importer-id' => 'rss', |