120 * @return array Importers with metadata for each. |
123 * @return array Importers with metadata for each. |
121 */ |
124 */ |
122 function wp_get_popular_importers() { |
125 function wp_get_popular_importers() { |
123 include( ABSPATH . WPINC . '/version.php' ); // include an unmodified $wp_version |
126 include( ABSPATH . WPINC . '/version.php' ); // include an unmodified $wp_version |
124 |
127 |
125 $locale = get_locale(); |
128 $locale = get_user_locale(); |
126 $popular_importers = get_site_transient( 'popular_importers_' . $locale ); |
129 $cache_key = 'popular_importers_' . md5( $locale . $wp_version ); |
|
130 $popular_importers = get_site_transient( $cache_key ); |
127 |
131 |
128 if ( ! $popular_importers ) { |
132 if ( ! $popular_importers ) { |
129 $url = add_query_arg( 'locale', get_locale(), 'http://api.wordpress.org/core/importers/1.1/' ); |
133 $url = add_query_arg( array( |
130 $options = array( 'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url() ); |
134 'locale' => $locale, |
|
135 'version' => $wp_version, |
|
136 ), 'http://api.wordpress.org/core/importers/1.1/' ); |
|
137 $options = array( 'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ) ); |
|
138 |
|
139 if ( wp_http_supports( array( 'ssl' ) ) ) { |
|
140 $url = set_url_scheme( $url, 'https' ); |
|
141 } |
|
142 |
131 $response = wp_remote_get( $url, $options ); |
143 $response = wp_remote_get( $url, $options ); |
132 $popular_importers = json_decode( wp_remote_retrieve_body( $response ), true ); |
144 $popular_importers = json_decode( wp_remote_retrieve_body( $response ), true ); |
133 |
145 |
134 if ( is_array( $popular_importers ) ) |
146 if ( is_array( $popular_importers ) ) { |
135 set_site_transient( 'popular_importers_' . $locale, $popular_importers, 2 * DAY_IN_SECONDS ); |
147 set_site_transient( $cache_key, $popular_importers, 2 * DAY_IN_SECONDS ); |
136 else |
148 } else { |
137 $popular_importers = false; |
149 $popular_importers = false; |
|
150 } |
138 } |
151 } |
139 |
152 |
140 if ( is_array( $popular_importers ) ) { |
153 if ( is_array( $popular_importers ) ) { |
141 // If the data was received as translated, return it as-is. |
154 // If the data was received as translated, return it as-is. |
142 if ( $popular_importers['translated'] ) |
155 if ( $popular_importers['translated'] ) |
152 |
165 |
153 return array( |
166 return array( |
154 // slug => name, description, plugin slug, and register_importer() slug |
167 // slug => name, description, plugin slug, and register_importer() slug |
155 'blogger' => array( |
168 'blogger' => array( |
156 'name' => __( 'Blogger' ), |
169 'name' => __( 'Blogger' ), |
157 'description' => __( 'Install the Blogger importer to import posts, comments, and users from a Blogger blog.' ), |
170 'description' => __( 'Import posts, comments, and users from a Blogger blog.' ), |
158 'plugin-slug' => 'blogger-importer', |
171 'plugin-slug' => 'blogger-importer', |
159 'importer-id' => 'blogger', |
172 'importer-id' => 'blogger', |
160 ), |
173 ), |
161 'wpcat2tag' => array( |
174 'wpcat2tag' => array( |
162 'name' => __( 'Categories and Tags Converter' ), |
175 'name' => __( 'Categories and Tags Converter' ), |
163 'description' => __( 'Install the category/tag converter to convert existing categories to tags or tags to categories, selectively.' ), |
176 'description' => __( 'Convert existing categories to tags or tags to categories, selectively.' ), |
164 'plugin-slug' => 'wpcat2tag-importer', |
177 'plugin-slug' => 'wpcat2tag-importer', |
165 'importer-id' => 'wp-cat2tag', |
178 'importer-id' => 'wp-cat2tag', |
166 ), |
179 ), |
167 'livejournal' => array( |
180 'livejournal' => array( |
168 'name' => __( 'LiveJournal' ), |
181 'name' => __( 'LiveJournal' ), |
169 'description' => __( 'Install the LiveJournal importer to import posts from LiveJournal using their API.' ), |
182 'description' => __( 'Import posts from LiveJournal using their API.' ), |
170 'plugin-slug' => 'livejournal-importer', |
183 'plugin-slug' => 'livejournal-importer', |
171 'importer-id' => 'livejournal', |
184 'importer-id' => 'livejournal', |
172 ), |
185 ), |
173 'movabletype' => array( |
186 'movabletype' => array( |
174 'name' => __( 'Movable Type and TypePad' ), |
187 'name' => __( 'Movable Type and TypePad' ), |
175 'description' => __( 'Install the Movable Type importer to import posts and comments from a Movable Type or TypePad blog.' ), |
188 'description' => __( 'Import posts and comments from a Movable Type or TypePad blog.' ), |
176 'plugin-slug' => 'movabletype-importer', |
189 'plugin-slug' => 'movabletype-importer', |
177 'importer-id' => 'mt', |
190 'importer-id' => 'mt', |
178 ), |
191 ), |
179 'opml' => array( |
192 'opml' => array( |
180 'name' => __( 'Blogroll' ), |
193 'name' => __( 'Blogroll' ), |
181 'description' => __( 'Install the blogroll importer to import links in OPML format.' ), |
194 'description' => __( 'Import links in OPML format.' ), |
182 'plugin-slug' => 'opml-importer', |
195 'plugin-slug' => 'opml-importer', |
183 'importer-id' => 'opml', |
196 'importer-id' => 'opml', |
184 ), |
197 ), |
185 'rss' => array( |
198 'rss' => array( |
186 'name' => __( 'RSS' ), |
199 'name' => __( 'RSS' ), |
187 'description' => __( 'Install the RSS importer to import posts from an RSS feed.' ), |
200 'description' => __( 'Import posts from an RSS feed.' ), |
188 'plugin-slug' => 'rss-importer', |
201 'plugin-slug' => 'rss-importer', |
189 'importer-id' => 'rss', |
202 'importer-id' => 'rss', |
190 ), |
203 ), |
191 'tumblr' => array( |
204 'tumblr' => array( |
192 'name' => __( 'Tumblr' ), |
205 'name' => __( 'Tumblr' ), |
193 'description' => __( 'Install the Tumblr importer to import posts & media from Tumblr using their API.' ), |
206 'description' => __( 'Import posts & media from Tumblr using their API.' ), |
194 'plugin-slug' => 'tumblr-importer', |
207 'plugin-slug' => 'tumblr-importer', |
195 'importer-id' => 'tumblr', |
208 'importer-id' => 'tumblr', |
196 ), |
209 ), |
197 'wordpress' => array( |
210 'wordpress' => array( |
198 'name' => 'WordPress', |
211 'name' => 'WordPress', |
199 'description' => __( 'Install the WordPress importer to import posts, pages, comments, custom fields, categories, and tags from a WordPress export file.' ), |
212 'description' => __( 'Import posts, pages, comments, custom fields, categories, and tags from a WordPress export file.' ), |
200 'plugin-slug' => 'wordpress-importer', |
213 'plugin-slug' => 'wordpress-importer', |
201 'importer-id' => 'wordpress', |
214 'importer-id' => 'wordpress', |
202 ), |
215 ), |
203 ); |
216 ); |
204 } |
217 } |