One Click Demo Import - Version 1.1.0

Version Description

Release Date - 14 May 2016

  • Content import now imports in multiple AJAX calls, so there should be no more server timeout errors,
  • The setting for generation of multiple image sizes in the content import is again enabled by default,
  • Plugin textdomain was loaded, so that translations can be made.
Download this release

Release Info

Developer capuderg
Plugin Icon 128x128 One Click Demo Import
Version 1.1.0
Comparing to
See all releases

Code changes from version 1.0.3 to 1.1.0

assets/css/main.css CHANGED
@@ -5,14 +5,15 @@
5
 
6
  /* AJAX loader */
7
  .ocdi__ajax-loader {
8
- font-width: bold;
9
  font-size: 1.5em;
 
10
  }
11
 
12
  .ocdi__ajax-loader .spinner {
13
  display: inline-block;
14
  float: none;
15
  visibility: visible;
 
16
  }
17
 
18
  /* Plugin intro text */
5
 
6
  /* AJAX loader */
7
  .ocdi__ajax-loader {
 
8
  font-size: 1.5em;
9
+ display: none;
10
  }
11
 
12
  .ocdi__ajax-loader .spinner {
13
  display: inline-block;
14
  float: none;
15
  visibility: visible;
16
+ margin-bottom: 6px;
17
  }
18
 
19
  /* Plugin intro text */
assets/js/main.js CHANGED
@@ -18,7 +18,12 @@ jQuery( function ( $ ) {
18
  data.append( 'widget_file', $('#ocdi__widget-file-upload')[0].files[0] );
19
  }
20
 
21
- // AJAX call.
 
 
 
 
 
22
  $.ajax({
23
  method: 'POST',
24
  url: ocdi.ajax_url,
@@ -26,24 +31,27 @@ jQuery( function ( $ ) {
26
  contentType: false,
27
  processData: false,
28
  beforeSend: function() {
29
- $( '.js-ocdi-import-data' ).after( '<p class="js-ocdi-ajax-loader ocdi__ajax-loader"><span class="spinner"></span>' + ocdi.loader_text + '</p>' );
30
- },
31
- complete: function() {
32
- $( '.js-ocdi-ajax-loader' ).hide( 500, function(){ $( '.js-ocdi-ajax-loader' ).remove(); } );
33
  }
34
  })
35
  .done( function( response ) {
36
- if ( 'undefined' !== typeof response.message ) {
 
 
 
 
37
  $( '.js-ocdi-ajax-response' ).append( '<p>' + response.message + '</p>' );
 
38
  }
39
  else {
40
  $( '.js-ocdi-ajax-response' ).append( '<div class="error below-h2"><p>' + response + '</p></div>' );
 
41
  }
42
  })
43
  .fail( function( error ) {
44
  $( '.js-ocdi-ajax-response' ).append( '<div class="error below-h2"> Error: ' + error.statusText + ' (' + error.status + ')' + '</div>' );
 
45
  });
46
-
47
- });
48
 
49
  });
18
  data.append( 'widget_file', $('#ocdi__widget-file-upload')[0].files[0] );
19
  }
20
 
21
+ // AJAX call to import everything (content, widgets, before/after setup)
22
+ ajaxCall( data );
23
+
24
+ });
25
+
26
+ function ajaxCall( data ) {
27
  $.ajax({
28
  method: 'POST',
29
  url: ocdi.ajax_url,
31
  contentType: false,
32
  processData: false,
33
  beforeSend: function() {
34
+ $( '.js-ocdi-ajax-loader' ).show();
 
 
 
35
  }
36
  })
37
  .done( function( response ) {
38
+
39
+ if ( 'undefined' !== typeof response.status && 'newAJAX' === response.status ) {
40
+ ajaxCall( data );
41
+ }
42
+ else if ( 'undefined' !== typeof response.message ) {
43
  $( '.js-ocdi-ajax-response' ).append( '<p>' + response.message + '</p>' );
44
+ $( '.js-ocdi-ajax-loader' ).hide();
45
  }
46
  else {
47
  $( '.js-ocdi-ajax-response' ).append( '<div class="error below-h2"><p>' + response + '</p></div>' );
48
+ $( '.js-ocdi-ajax-loader' ).hide();
49
  }
50
  })
51
  .fail( function( error ) {
52
  $( '.js-ocdi-ajax-response' ).append( '<div class="error below-h2"> Error: ' + error.statusText + ' (' + error.status + ')' + '</div>' );
53
+ $( '.js-ocdi-ajax-loader' ).hide();
54
  });
55
+ }
 
56
 
57
  });
inc/class-ocdi-importer.php CHANGED
@@ -16,7 +16,7 @@ class OCDI_Importer {
16
 
17
  // Set the WordPress Importer v2 as the importer used in this plugin.
18
  // More: https://github.com/humanmade/WordPress-Importer.
19
- $this->importer = new WXR_Importer( $importer_options );
20
 
21
  // Set logger to the importer.
22
  if ( ! empty( $logger ) ) {
@@ -32,7 +32,7 @@ class OCDI_Importer {
32
  defined( 'WP_LOAD_IMPORTERS' ) || define( 'WP_LOAD_IMPORTERS', true );
33
  require ABSPATH . '/wp-admin/includes/class-wp-importer.php';
34
  }
35
- require PT_OCDI_PATH . 'vendor/humanmade/WordPress-Importer/class-wxr-importer.php';
36
  }
37
 
38
  /**
@@ -52,4 +52,20 @@ class OCDI_Importer {
52
  public function set_logger( $logger ) {
53
  $this->importer->set_logger( $logger );
54
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  }
16
 
17
  // Set the WordPress Importer v2 as the importer used in this plugin.
18
  // More: https://github.com/humanmade/WordPress-Importer.
19
+ $this->importer = new OCDI_WXR_Importer( $importer_options );
20
 
21
  // Set logger to the importer.
22
  if ( ! empty( $logger ) ) {
32
  defined( 'WP_LOAD_IMPORTERS' ) || define( 'WP_LOAD_IMPORTERS', true );
33
  require ABSPATH . '/wp-admin/includes/class-wp-importer.php';
34
  }
35
+ require PT_OCDI_PATH . 'inc/class-ocdi-wxr-importer.php';
36
  }
37
 
38
  /**
52
  public function set_logger( $logger ) {
53
  $this->importer->set_logger( $logger );
54
  }
55
+
56
+ /**
57
+ * Get all protected variables from the WXR_Importer needed for continuing the import.
58
+ */
59
+ public function get_importer_data() {
60
+ return $this->importer->get_importer_data();
61
+ }
62
+
63
+ /**
64
+ * Sets all protected variables from the WXR_Importer needed for continuing the import.
65
+ *
66
+ * @param array $data with set variables.
67
+ */
68
+ public function set_importer_data( $data ) {
69
+ $this->importer->set_importer_data( $data );
70
+ }
71
  }
inc/class-ocdi-wxr-importer.php ADDED
@@ -0,0 +1,276 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * WXR importer class used in the One Click Demo Import plugin.
4
+ * Needed to extend the WXR_Importer class to get/set the importer protected variables,
5
+ * for use in the multiple AJAX calls.
6
+ *
7
+ * Overwritten process_post method to fix the menu items/tags import issue. This
8
+ * should be removed when it is fixed in the original importer.
9
+ *
10
+ * @package ocdi
11
+ */
12
+
13
+ // Include required files.
14
+ require PT_OCDI_PATH . 'vendor/humanmade/WordPress-Importer/class-wxr-importer.php';
15
+
16
+ class OCDI_WXR_Importer extends WXR_Importer {
17
+
18
+ /**
19
+ * Get all protected variables from the WXR_Importer needed for continuing the import.
20
+ */
21
+ public function get_importer_data() {
22
+ return array(
23
+ 'mapping' => $this->mapping,
24
+ 'requires_remapping' => $this->requires_remapping,
25
+ 'exists' => $this->exists,
26
+ 'user_slug_override' => $this->user_slug_override,
27
+ 'url_remap' => $this->url_remap,
28
+ 'featured_images' => $this->featured_images,
29
+ );
30
+ }
31
+
32
+ /**
33
+ * Sets all protected variables from the WXR_Importer needed for continuing the import.
34
+ *
35
+ * @param array $data with set variables.
36
+ */
37
+ public function set_importer_data( $data ) {
38
+ $this->mapping = empty( $data['mapping'] ) ? array() : $data['mapping'];
39
+ $this->requires_remapping = empty( $data['requires_remapping'] ) ? array() : $data['requires_remapping'];
40
+ $this->exists = empty( $data['exists'] ) ? array() : $data['exists'];
41
+ $this->user_slug_override = empty( $data['user_slug_override'] ) ? array() : $data['user_slug_override'];
42
+ $this->url_remap = empty( $data['url_remap'] ) ? array() : $data['url_remap'];
43
+ $this->featured_images = empty( $data['featured_images'] ) ? array() : $data['featured_images'];
44
+ }
45
+
46
+
47
+
48
+ /**
49
+ * Create new posts based on import information
50
+ *
51
+ * Posts marked as having a parent which doesn't exist will become top level items.
52
+ * Doesn't create a new post if: the post type doesn't exist, the given post ID
53
+ * is already noted as imported or a post with the same title and date already exists.
54
+ * Note that new/updated terms, comments and meta are imported for the last of the above.
55
+ *
56
+ *
57
+ * The only thing that is changed in this function is a typecesting to int!!!
58
+ * It is marked with a couple of lines of comments -> !!!OCDI:
59
+ *
60
+ */
61
+ protected function process_post( $data, $meta, $comments, $terms ) {
62
+ /**
63
+ * Pre-process post data.
64
+ *
65
+ * @param array $data Post data. (Return empty to skip.)
66
+ * @param array $meta Meta data.
67
+ * @param array $comments Comments on the post.
68
+ * @param array $terms Terms on the post.
69
+ */
70
+ $data = apply_filters( 'wxr_importer.pre_process.post', $data, $meta, $comments, $terms );
71
+ if ( empty( $data ) ) {
72
+ return false;
73
+ }
74
+
75
+ $original_id = isset( $data['post_id'] ) ? (int) $data['post_id'] : 0;
76
+ $parent_id = isset( $data['post_parent'] ) ? (int) $data['post_parent'] : 0;
77
+ $author_id = isset( $data['post_author'] ) ? (int) $data['post_author'] : 0;
78
+
79
+ // Have we already processed this?
80
+ if ( isset( $this->mapping['post'][ $original_id ] ) ) {
81
+ return;
82
+ }
83
+
84
+ $post_type_object = get_post_type_object( $data['post_type'] );
85
+
86
+ // Is this type even valid?
87
+ if ( ! $post_type_object ) {
88
+ $this->logger->warning( sprintf(
89
+ __( 'Failed to import "%s": Invalid post type %s', 'pt-ocdi' ),
90
+ $data['post_title'],
91
+ $data['post_type']
92
+ ) );
93
+ return false;
94
+ }
95
+
96
+ $post_exists = $this->post_exists( $data );
97
+ if ( $post_exists ) {
98
+ $this->logger->info( sprintf(
99
+ __('%s "%s" already exists.', 'pt-ocdi'),
100
+ $post_type_object->labels->singular_name,
101
+ $data['post_title']
102
+ ) );
103
+
104
+ return false;
105
+ }
106
+
107
+ // Map the parent post, or mark it as one we need to fix
108
+ $requires_remapping = false;
109
+ if ( $parent_id ) {
110
+ if ( isset( $this->mapping['post'][ $parent_id ] ) ) {
111
+ $data['post_parent'] = $this->mapping['post'][ $parent_id ];
112
+ } else {
113
+ $meta[] = array( 'key' => '_wxr_import_parent', 'value' => $parent_id );
114
+ $requires_remapping = true;
115
+
116
+ $data['post_parent'] = 0;
117
+ }
118
+ }
119
+
120
+ // Map the author, or mark it as one we need to fix
121
+ $author = sanitize_user( $data['post_author'], true );
122
+ if ( empty( $author ) ) {
123
+ // Missing or invalid author, use default if available.
124
+ $data['post_author'] = $this->options['default_author'];
125
+ } elseif ( isset( $this->mapping['user_slug'][ $author ] ) ) {
126
+ $data['post_author'] = $this->mapping['user_slug'][ $author ];
127
+ }
128
+ else {
129
+ $meta[] = array( 'key' => '_wxr_import_user_slug', 'value' => $author );
130
+ $requires_remapping = true;
131
+
132
+ $data['post_author'] = (int) get_current_user_id();
133
+ }
134
+
135
+ // Does the post look like it contains attachment images?
136
+ if ( preg_match( self::REGEX_HAS_ATTACHMENT_REFS, $data['post_content'] ) ) {
137
+ $meta[] = array( 'key' => '_wxr_import_has_attachment_refs', 'value' => true );
138
+ $requires_remapping = true;
139
+ }
140
+
141
+ // Whitelist to just the keys we allow
142
+ $postdata = array(
143
+ 'import_id' => $data['post_id'],
144
+ );
145
+ $allowed = array(
146
+ 'post_author' => true,
147
+ 'post_date' => true,
148
+ 'post_date_gmt' => true,
149
+ 'post_content' => true,
150
+ 'post_excerpt' => true,
151
+ 'post_title' => true,
152
+ 'post_status' => true,
153
+ 'post_name' => true,
154
+ 'comment_status' => true,
155
+ 'ping_status' => true,
156
+ 'guid' => true,
157
+ 'post_parent' => true,
158
+ 'menu_order' => true,
159
+ 'post_type' => true,
160
+ 'post_password' => true,
161
+ );
162
+ foreach ( $data as $key => $value ) {
163
+ if ( ! isset( $allowed[ $key ] ) ) {
164
+ continue;
165
+ }
166
+
167
+ $postdata[ $key ] = $data[ $key ];
168
+ }
169
+
170
+ $postdata = apply_filters( 'wp_import_post_data_processed', $postdata, $data );
171
+
172
+ if ( 'attachment' === $postdata['post_type'] ) {
173
+ if ( ! $this->options['fetch_attachments'] ) {
174
+ $this->logger->notice( sprintf(
175
+ __( 'Skipping attachment "%s", fetching attachments disabled', 'pt-ocdi' ),
176
+ $data['post_title']
177
+ ) );
178
+ return false;
179
+ }
180
+ $remote_url = ! empty($data['attachment_url']) ? $data['attachment_url'] : $data['guid'];
181
+ $post_id = $this->process_attachment( $postdata, $meta, $remote_url );
182
+ } else {
183
+ $post_id = wp_insert_post( $postdata, true );
184
+ do_action( 'wp_import_insert_post', $post_id, $original_id, $postdata, $data );
185
+ }
186
+
187
+ if ( is_wp_error( $post_id ) ) {
188
+ $this->logger->error( sprintf(
189
+ __( 'Failed to import "%s" (%s)', 'pt-ocdi' ),
190
+ $data['post_title'],
191
+ $post_type_object->labels->singular_name
192
+ ) );
193
+ $this->logger->debug( $post_id->get_error_message() );
194
+
195
+ /**
196
+ * Post processing failed.
197
+ *
198
+ * @param WP_Error $post_id Error object.
199
+ * @param array $data Raw data imported for the post.
200
+ * @param array $meta Raw meta data, already processed by {@see process_post_meta}.
201
+ * @param array $comments Raw comment data, already processed by {@see process_comments}.
202
+ * @param array $terms Raw term data, already processed.
203
+ */
204
+ do_action( 'wxr_importer.process_failed.post', $post_id, $data, $meta, $comments, $terms );
205
+ return false;
206
+ }
207
+
208
+ // Ensure stickiness is handled correctly too
209
+ if ( $data['is_sticky'] == 1 ) {
210
+ stick_post( $post_id );
211
+ }
212
+
213
+ // map pre-import ID to local ID
214
+ $this->mapping['post'][ $original_id ] = (int) $post_id;
215
+ if ( $requires_remapping ) {
216
+ $this->requires_remapping['post'][ $post_id ] = true;
217
+ }
218
+ $this->mark_post_exists( $data, $post_id );
219
+
220
+ $this->logger->info( sprintf(
221
+ __( 'Imported "%s" (%s)', 'pt-ocdi' ),
222
+ $data['post_title'],
223
+ $post_type_object->labels->singular_name
224
+ ) );
225
+ $this->logger->debug( sprintf(
226
+ __( 'Post %d remapped to %d', 'pt-ocdi' ),
227
+ $original_id,
228
+ $post_id
229
+ ) );
230
+
231
+ // Handle the terms too
232
+ $terms = apply_filters( 'wp_import_post_terms', $terms, $post_id, $data );
233
+
234
+ if ( ! empty( $terms ) ) {
235
+ $term_ids = array();
236
+ foreach ( $terms as $term ) {
237
+ $taxonomy = $term['taxonomy'];
238
+ $key = sha1( $taxonomy . ':' . $term['slug'] );
239
+
240
+ if ( isset( $this->mapping['term'][ $key ] ) ) {
241
+ // !!!OCDI: The only change from the original importer code is this typecasting (int) bellow.
242
+ // !!!OCDI: The only change from the original importer code is this typecasting (int) bellow.
243
+ // !!!OCDI: The only change from the original importer code is this typecasting (int) bellow.
244
+ $term_ids[ $taxonomy ][] = (int) $this->mapping['term'][ $key ];
245
+ }
246
+ else {
247
+ $meta[] = array( 'key' => '_wxr_import_term', 'value' => $term );
248
+ $requires_remapping = true;
249
+ }
250
+ }
251
+
252
+ foreach ( $term_ids as $tax => $ids ) {
253
+ $tt_ids = wp_set_post_terms( $post_id, $ids, $tax );
254
+ do_action( 'wp_import_set_post_terms', $tt_ids, $ids, $tax, $post_id, $data );
255
+ }
256
+ }
257
+
258
+ $this->process_comments( $comments, $post_id, $data );
259
+ $this->process_post_meta( $meta, $post_id, $data );
260
+
261
+ if ( 'nav_menu_item' === $data['post_type'] ) {
262
+ $this->process_menu_item_meta( $post_id, $data, $meta );
263
+ }
264
+
265
+ /**
266
+ * Post processing completed.
267
+ *
268
+ * @param int $post_id New post ID.
269
+ * @param array $data Raw data imported for the post.
270
+ * @param array $meta Raw meta data, already processed by {@see process_post_meta}.
271
+ * @param array $comments Raw comment data, already processed by {@see process_comments}.
272
+ * @param array $terms Raw term data, already processed.
273
+ */
274
+ do_action( 'wxr_importer.processed.post', $post_id, $data, $meta, $comments, $terms );
275
+ }
276
+ }
languages/{one-click-demo-import.pot → pt-ocdi.pot} RENAMED
@@ -2,9 +2,9 @@
2
  # This file is distributed under the GPL 2.0.
3
  msgid ""
4
  msgstr ""
5
- "Project-Id-Version: One Click Demo Import 1.0.2\n"
6
  "Report-Msgid-Bugs-To: http://support.proteusthemes.com/\n"
7
- "POT-Creation-Date: 2016-03-14 13:27:22+00:00\n"
8
  "MIME-Version: 1.0\n"
9
  "Content-Type: text/plain; charset=utf-8\n"
10
  "Content-Transfer-Encoding: 8bit\n"
@@ -136,17 +136,41 @@ msgstr ""
136
  msgid "No results for widget import!"
137
  msgstr ""
138
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139
  #. Plugin Name of the plugin/theme
140
  msgid "One Click Demo Import"
141
  msgstr ""
142
 
143
- #: one-click-demo-import.php:114
144
  msgid ""
145
  "%sWarning: your server is using %sPHP safe mode%s. This means that you "
146
  "might experience server timeout errors.%s"
147
  msgstr ""
148
 
149
- #: one-click-demo-import.php:128
150
  msgid ""
151
  "Importing demo data (post, pages, images, theme settings, ...) is the "
152
  "easiest way to setup your theme. It will allow you to quickly edit "
@@ -154,69 +178,69 @@ msgid ""
154
  "data, the following things might happen:"
155
  msgstr ""
156
 
157
- #: one-click-demo-import.php:132
158
  msgid ""
159
  "No existing posts, pages, categories, images, custom post types or any "
160
  "other data will be deleted or modified."
161
  msgstr ""
162
 
163
- #: one-click-demo-import.php:133
164
  msgid "Posts, pages, images, widgets and menus will get imported."
165
  msgstr ""
166
 
167
- #: one-click-demo-import.php:134
168
  msgid ""
169
  "Please click \"Import Demo Data\" button only once and wait, it can take a "
170
  "couple of minutes."
171
  msgstr ""
172
 
173
- #: one-click-demo-import.php:139
174
  msgid "Before you begin, make sure all the required plugins are activated."
175
  msgstr ""
176
 
177
- #: one-click-demo-import.php:153
178
  msgid ""
179
  "There are no predefined import files available in this theme. Please upload "
180
  "the import files manually!"
181
  msgstr ""
182
 
183
- #: one-click-demo-import.php:157
184
  msgid "Choose a XML file for content import:"
185
  msgstr ""
186
 
187
- #: one-click-demo-import.php:160
188
  msgid "optional"
189
  msgstr ""
190
 
191
- #: one-click-demo-import.php:160
192
  msgid "Choose a WIE or JSON file for widget import:"
193
  msgstr ""
194
 
195
- #: one-click-demo-import.php:176
196
  msgid "Import Demo Data"
197
  msgstr ""
198
 
199
- #: one-click-demo-import.php:201
200
- msgid "Importing now, please wait!"
201
  msgstr ""
202
 
203
- #: one-click-demo-import.php:248
204
  msgid "Manually uploaded files"
205
  msgstr ""
206
 
207
- #: one-click-demo-import.php:265 one-click-demo-import.php:276
208
  msgid "Downloaded files"
209
  msgstr ""
210
 
211
- #: one-click-demo-import.php:272
212
  msgid "The import files for: %s were successfully downloaded!"
213
  msgstr ""
214
 
215
- #: one-click-demo-import.php:282
216
  msgid "No import files specified!"
217
  msgstr ""
218
 
219
- #: one-click-demo-import.php:321
220
  msgid ""
221
  "%1$s%3$sThat's it, all done!%4$s%2$sThe demo import has finished. Please "
222
  "check your page and make sure that everything has imported correctly. If it "
@@ -224,23 +248,27 @@ msgid ""
224
  "it has done its job.%5$s"
225
  msgstr ""
226
 
227
- #: one-click-demo-import.php:332
228
  msgid ""
229
  "%1$sThe demo import has finished, but there were some import "
230
  "errors.%2$sMore details about the errors can be found in this %3$s%5$slog "
231
  "file%6$s%4$s%7$s"
232
  msgstr ""
233
 
234
- #: one-click-demo-import.php:383
235
  msgid "Importing content"
236
  msgstr ""
237
 
238
- #: one-click-demo-import.php:419 one-click-demo-import.php:431
239
  msgid "Importing widgets"
240
  msgstr ""
241
 
242
- #. Author URI of the plugin/theme
243
- msgid "http://www.proteusthemes.com"
 
 
 
 
244
  msgstr ""
245
 
246
  #. Description of the plugin/theme
@@ -251,4 +279,8 @@ msgstr ""
251
 
252
  #. Author of the plugin/theme
253
  msgid "ProteusThemes"
 
 
 
 
254
  msgstr ""
2
  # This file is distributed under the GPL 2.0.
3
  msgid ""
4
  msgstr ""
5
+ "Project-Id-Version: One Click Demo Import 1.1.0\n"
6
  "Report-Msgid-Bugs-To: http://support.proteusthemes.com/\n"
7
+ "POT-Creation-Date: 2016-05-14 09:53:17+00:00\n"
8
  "MIME-Version: 1.0\n"
9
  "Content-Type: text/plain; charset=utf-8\n"
10
  "Content-Transfer-Encoding: 8bit\n"
136
  msgid "No results for widget import!"
137
  msgstr ""
138
 
139
+ #: inc/class-ocdi-wxr-importer.php:89
140
+ msgid "Failed to import \"%s\": Invalid post type %s"
141
+ msgstr ""
142
+
143
+ #: inc/class-ocdi-wxr-importer.php:99
144
+ msgid "%s \"%s\" already exists."
145
+ msgstr ""
146
+
147
+ #: inc/class-ocdi-wxr-importer.php:175
148
+ msgid "Skipping attachment \"%s\", fetching attachments disabled"
149
+ msgstr ""
150
+
151
+ #: inc/class-ocdi-wxr-importer.php:189
152
+ msgid "Failed to import \"%s\" (%s)"
153
+ msgstr ""
154
+
155
+ #: inc/class-ocdi-wxr-importer.php:221
156
+ msgid "Imported \"%s\" (%s)"
157
+ msgstr ""
158
+
159
+ #: inc/class-ocdi-wxr-importer.php:226
160
+ msgid "Post %d remapped to %d"
161
+ msgstr ""
162
+
163
  #. Plugin Name of the plugin/theme
164
  msgid "One Click Demo Import"
165
  msgstr ""
166
 
167
+ #: one-click-demo-import.php:115
168
  msgid ""
169
  "%sWarning: your server is using %sPHP safe mode%s. This means that you "
170
  "might experience server timeout errors.%s"
171
  msgstr ""
172
 
173
+ #: one-click-demo-import.php:129
174
  msgid ""
175
  "Importing demo data (post, pages, images, theme settings, ...) is the "
176
  "easiest way to setup your theme. It will allow you to quickly edit "
178
  "data, the following things might happen:"
179
  msgstr ""
180
 
181
+ #: one-click-demo-import.php:133
182
  msgid ""
183
  "No existing posts, pages, categories, images, custom post types or any "
184
  "other data will be deleted or modified."
185
  msgstr ""
186
 
187
+ #: one-click-demo-import.php:134
188
  msgid "Posts, pages, images, widgets and menus will get imported."
189
  msgstr ""
190
 
191
+ #: one-click-demo-import.php:135
192
  msgid ""
193
  "Please click \"Import Demo Data\" button only once and wait, it can take a "
194
  "couple of minutes."
195
  msgstr ""
196
 
197
+ #: one-click-demo-import.php:140
198
  msgid "Before you begin, make sure all the required plugins are activated."
199
  msgstr ""
200
 
201
+ #: one-click-demo-import.php:154
202
  msgid ""
203
  "There are no predefined import files available in this theme. Please upload "
204
  "the import files manually!"
205
  msgstr ""
206
 
207
+ #: one-click-demo-import.php:158
208
  msgid "Choose a XML file for content import:"
209
  msgstr ""
210
 
211
+ #: one-click-demo-import.php:161
212
  msgid "optional"
213
  msgstr ""
214
 
215
+ #: one-click-demo-import.php:161
216
  msgid "Choose a WIE or JSON file for widget import:"
217
  msgstr ""
218
 
219
+ #: one-click-demo-import.php:177
220
  msgid "Import Demo Data"
221
  msgstr ""
222
 
223
+ #: one-click-demo-import.php:181
224
+ msgid "Importing, please wait!"
225
  msgstr ""
226
 
227
+ #: one-click-demo-import.php:260
228
  msgid "Manually uploaded files"
229
  msgstr ""
230
 
231
+ #: one-click-demo-import.php:277 one-click-demo-import.php:288
232
  msgid "Downloaded files"
233
  msgstr ""
234
 
235
+ #: one-click-demo-import.php:284
236
  msgid "The import files for: %s were successfully downloaded!"
237
  msgstr ""
238
 
239
+ #: one-click-demo-import.php:294
240
  msgid "No import files specified!"
241
  msgstr ""
242
 
243
+ #: one-click-demo-import.php:334
244
  msgid ""
245
  "%1$s%3$sThat's it, all done!%4$s%2$sThe demo import has finished. Please "
246
  "check your page and make sure that everything has imported correctly. If it "
248
  "it has done its job.%5$s"
249
  msgstr ""
250
 
251
+ #: one-click-demo-import.php:345
252
  msgid ""
253
  "%1$sThe demo import has finished, but there were some import "
254
  "errors.%2$sMore details about the errors can be found in this %3$s%5$slog "
255
  "file%6$s%4$s%7$s"
256
  msgstr ""
257
 
258
+ #: one-click-demo-import.php:401
259
  msgid "Importing content"
260
  msgstr ""
261
 
262
+ #: one-click-demo-import.php:440 one-click-demo-import.php:452
263
  msgid "Importing widgets"
264
  msgstr ""
265
 
266
+ #: one-click-demo-import.php:502
267
+ msgid "Completed AJAX call number: "
268
+ msgstr ""
269
+
270
+ #. Plugin URI of the plugin/theme
271
+ msgid "https://wordpress.org/plugins/one-click-demo-import/"
272
  msgstr ""
273
 
274
  #. Description of the plugin/theme
279
 
280
  #. Author of the plugin/theme
281
  msgid "ProteusThemes"
282
+ msgstr ""
283
+
284
+ #. Author URI of the plugin/theme
285
+ msgid "http://www.proteusthemes.com"
286
  msgstr ""
one-click-demo-import.php CHANGED
@@ -2,9 +2,9 @@
2
 
3
  /*
4
  Plugin Name: One Click Demo Import
5
- Plugin URI: http://www.proteusthemes.com
6
  Description: Import your content, widgets and theme settings with one click. Theme authors! Enable simple demo import for your theme demo data.
7
- Version: 1.0.3
8
  Author: ProteusThemes
9
  Author URI: http://www.proteusthemes.com
10
  License: GPL3
@@ -20,7 +20,7 @@ define( 'PT_OCDI_PATH', plugin_dir_path( __FILE__ ) );
20
  define( 'PT_OCDI_URL', plugin_dir_url( __FILE__ ) );
21
 
22
  // Current version of the plugin.
23
- define( 'PT_OCDI_VERSION', '1.0.3' );
24
 
25
  // Include files.
26
  require PT_OCDI_PATH . 'inc/class-ocdi-helpers.php';
@@ -41,7 +41,7 @@ class PT_One_Click_Demo_Import {
41
  /**
42
  * Private variables used throughout the plugin.
43
  */
44
- private $importer, $plugin_page, $import_files, $logger, $log_file_path;
45
 
46
 
47
  /**
@@ -70,6 +70,7 @@ class PT_One_Click_Demo_Import {
70
  add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
71
  add_action( 'wp_ajax_ocdi_import_demo_data', array( $this, 'import_demo_data_ajax_callback' ) );
72
  add_action( 'after_setup_theme', array( $this, 'setup_plugin_with_filter_data' ) );
 
73
  }
74
 
75
 
@@ -176,6 +177,10 @@ class PT_One_Click_Demo_Import {
176
  <button class="ocdi__button button-primary js-ocdi-import-data"><?php esc_html_e( 'Import Demo Data', 'pt-ocdi' ); ?></button>
177
  </p>
178
 
 
 
 
 
179
  <div class="ocdi__response js-ocdi-ajax-response"></div>
180
  </div>
181
 
@@ -198,7 +203,6 @@ class PT_One_Click_Demo_Import {
198
  array(
199
  'ajax_url' => admin_url( 'admin-ajax.php' ),
200
  'ajax_nonce' => wp_create_nonce( 'ocdi-ajax-verification' ),
201
- 'loader_text' => esc_html__( 'Importing now, please wait!', 'pt-ocdi' ),
202
  )
203
  );
204
 
@@ -223,100 +227,109 @@ class PT_One_Click_Demo_Import {
223
  // Verify if the AJAX call is valid (checks nonce and current_user_can).
224
  OCDI_Helpers::verify_ajax_call();
225
 
226
- // Error messages displayed on front page.
227
- $frontend_error_messages = '';
228
 
229
- // Create a date and time string to use for demo and log file names.
230
- $demo_import_start_time = date( apply_filters( 'pt-ocdi/date_format_for_file_names', 'Y-m-d__H-i-s' ) );
231
 
232
- // Define log file path.
233
- $this->log_file_path = OCDI_Helpers::get_log_path( $demo_import_start_time );
234
 
235
- // Get selected file index or set it to 0.
236
- $selected_index = empty( $_POST['selected'] ) ? 0 : absint( $_POST['selected'] );
237
 
238
- /**
239
- * 1. Prepare import files.
240
- * Manually uploaded import files or predefined import files via filter: pt-ocdi/import_files
241
- */
242
- if ( ! empty( $_FILES ) ) { // Using manual file uploads?
243
 
244
- // Get paths for the uploaded files.
245
- $selected_import_files = OCDI_Helpers::process_uploaded_files( $_FILES, $this->log_file_path );
246
 
247
- // Set the name of the import files, because we used the uploaded files.
248
- $this->import_files[ $selected_index ]['import_file_name'] = esc_html__( 'Manually uploaded files', 'pt-ocdi' );
249
- }
250
- elseif ( ! empty( $this->import_files[ $selected_index ] ) ) { // Use predefined import files from wp filter: pt-ocdi/import_files.
251
 
252
- // Download the import files (content and widgets files) and save it to variable for later use.
253
- $selected_import_files = OCDI_Helpers::download_import_files(
254
- $this->import_files[ $selected_index ],
255
- $demo_import_start_time
256
- );
257
 
258
- // Check Errors.
259
- if ( is_wp_error( $selected_import_files ) ) {
 
 
 
 
 
260
 
261
- // Write error to log file and send an AJAX response with the error.
262
- OCDI_Helpers::log_error_and_send_ajax_response(
263
- $selected_import_files->get_error_message(),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
264
  $this->log_file_path,
265
- esc_html__( 'Downloaded files', 'pt-ocdi' )
266
  );
267
  }
 
268
 
269
- // Add this message to log file.
270
- $log_added = OCDI_Helpers::append_to_file(
271
- sprintf(
272
- __( 'The import files for: %s were successfully downloaded!', 'pt-ocdi' ),
273
- $this->import_files[ $selected_index ]['import_file_name']
274
- ) . OCDI_Helpers::import_file_info( $selected_import_files ),
275
- $this->log_file_path,
276
- esc_html__( 'Downloaded files' , 'pt-ocdi' )
277
- );
278
- }
279
- else {
280
-
281
- // Send JSON Error response to the AJAX call.
282
- wp_send_json( esc_html__( 'No import files specified!', 'pt-ocdi' ) );
283
  }
284
 
285
  /**
286
  * 2. Import content.
287
  * Returns any errors greater then the "error" logger level, that will be displayed on front page.
288
  */
289
- $frontend_error_messages .= $this->import_content( $selected_import_files['content'] );
290
 
291
  /**
292
  * 3. Before widgets import setup.
293
  */
294
  $action = 'pt-ocdi/before_widgets_import';
295
- if ( ( false !== has_action( $action ) ) && empty( $frontend_error_messages ) ) {
296
 
297
  // Run the before_widgets_import action to setup other settings.
298
- $this->do_import_action( $action, $this->import_files[ $selected_index ] );
299
  }
300
 
301
  /**
302
  * 4. Import widgets.
303
  */
304
- if ( ! empty( $selected_import_files['widgets'] ) && empty( $frontend_error_messages ) ) {
305
- $this->import_widgets( $selected_import_files['widgets'] );
306
  }
307
 
308
  /**
309
  * 5. After import setup.
310
  */
311
  $action = 'pt-ocdi/after_import';
312
- if ( ( false !== has_action( $action ) ) && empty( $frontend_error_messages ) ) {
313
 
314
  // Run the after_import action to setup other settings.
315
- $this->do_import_action( $action, $this->import_files[ $selected_index ] );
316
  }
317
 
318
  // Display final messages (success or error messages).
319
- if ( empty( $frontend_error_messages ) ) {
320
  $response['message'] = sprintf(
321
  __( '%1$s%3$sThat\'s it, all done!%4$s%2$sThe demo import has finished. Please check your page and make sure that everything has imported correctly. If it did, you can deactivate the %3$sOne Click Demo Import%4$s plugin, because it has done its job.%5$s', 'pt-ocdi' ),
322
  '<div class="notice notice-success"><p>',
@@ -327,7 +340,7 @@ class PT_One_Click_Demo_Import {
327
  );
328
  }
329
  else {
330
- $response['message'] = $frontend_error_messages . '<br>';
331
  $response['message'] .= sprintf(
332
  __( '%1$sThe demo import has finished, but there were some import errors.%2$sMore details about the errors can be found in this %3$s%5$slog file%6$s%4$s%7$s', 'pt-ocdi' ),
333
  '<div class="notice notice-error"><p>',
@@ -351,6 +364,8 @@ class PT_One_Click_Demo_Import {
351
  */
352
  private function import_content( $import_file_path ) {
353
 
 
 
354
  // This should be replaced with multiple AJAX calls (import in smaller chunks)
355
  // so that it would not come to the Internal Error, because of the PHP script timeout.
356
  // Also this function has no effect when PHP is running in safe mode
@@ -361,8 +376,11 @@ class PT_One_Click_Demo_Import {
361
  // Disable import of authors.
362
  add_filter( 'wxr_importer.pre_process.user', '__return_false' );
363
 
 
 
 
364
  // Disables generation of multiple image sizes (thumbnails) in the content import step.
365
- if ( ! apply_filters( 'pt-ocdi/regenerate_thumbnails_in_content_import', false ) ) {
366
  add_filter( 'intermediate_image_sizes_advanced',
367
  function() {
368
  return null;
@@ -384,6 +402,9 @@ class PT_One_Click_Demo_Import {
384
  );
385
  }
386
 
 
 
 
387
  // Return any error messages for the front page output (errors, critical, alert and emergency level messages only).
388
  return $this->logger->error_output;
389
  }
@@ -454,6 +475,83 @@ class PT_One_Click_Demo_Import {
454
  }
455
 
456
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
457
  /**
458
  * Get data from filters, after the theme has loaded and instantiate the importer.
459
  */
@@ -481,4 +579,4 @@ class PT_One_Click_Demo_Import {
481
  }
482
  }
483
 
484
- $PT_One_Click_Demo_Import = PT_One_Click_Demo_Import::getInstance();
2
 
3
  /*
4
  Plugin Name: One Click Demo Import
5
+ Plugin URI: https://wordpress.org/plugins/one-click-demo-import/
6
  Description: Import your content, widgets and theme settings with one click. Theme authors! Enable simple demo import for your theme demo data.
7
+ Version: 1.1.0
8
  Author: ProteusThemes
9
  Author URI: http://www.proteusthemes.com
10
  License: GPL3
20
  define( 'PT_OCDI_URL', plugin_dir_url( __FILE__ ) );
21
 
22
  // Current version of the plugin.
23
+ define( 'PT_OCDI_VERSION', '1.1.0' );
24
 
25
  // Include files.
26
  require PT_OCDI_PATH . 'inc/class-ocdi-helpers.php';
41
  /**
42
  * Private variables used throughout the plugin.
43
  */
44
+ private $importer, $plugin_page, $import_files, $logger, $log_file_path, $selected_index, $selected_import_files, $microtime, $frontend_error_messages, $ajax_call_number;
45
 
46
 
47
  /**
70
  add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
71
  add_action( 'wp_ajax_ocdi_import_demo_data', array( $this, 'import_demo_data_ajax_callback' ) );
72
  add_action( 'after_setup_theme', array( $this, 'setup_plugin_with_filter_data' ) );
73
+ add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) );
74
  }
75
 
76
 
177
  <button class="ocdi__button button-primary js-ocdi-import-data"><?php esc_html_e( 'Import Demo Data', 'pt-ocdi' ); ?></button>
178
  </p>
179
 
180
+ <p class="ocdi__ajax-loader js-ocdi-ajax-loader">
181
+ <span class="spinner"></span> <?php esc_html_e( 'Importing, please wait!', 'pt-ocdi' ); ?>
182
+ </p>
183
+
184
  <div class="ocdi__response js-ocdi-ajax-response"></div>
185
  </div>
186
 
203
  array(
204
  'ajax_url' => admin_url( 'admin-ajax.php' ),
205
  'ajax_nonce' => wp_create_nonce( 'ocdi-ajax-verification' ),
 
206
  )
207
  );
208
 
227
  // Verify if the AJAX call is valid (checks nonce and current_user_can).
228
  OCDI_Helpers::verify_ajax_call();
229
 
230
+ // Is this a new AJAX call to continue the previous import?
231
+ $use_existing_importer_data = $this->get_importer_data();
232
 
233
+ if ( ! $use_existing_importer_data ) {
 
234
 
235
+ // Set the AJAX call number.
236
+ $this->ajax_call_number = empty( $this->ajax_call_number ) ? 0 : $this->ajax_call_number;
237
 
238
+ // Error messages displayed on front page.
239
+ $this->frontend_error_messages = '';
240
 
241
+ // Create a date and time string to use for demo and log file names.
242
+ $demo_import_start_time = date( apply_filters( 'pt-ocdi/date_format_for_file_names', 'Y-m-d__H-i-s' ) );
 
 
 
243
 
244
+ // Define log file path.
245
+ $this->log_file_path = OCDI_Helpers::get_log_path( $demo_import_start_time );
246
 
247
+ // Get selected file index or set it to 0.
248
+ $this->selected_index = empty( $_POST['selected'] ) ? 0 : absint( $_POST['selected'] );
 
 
249
 
250
+ /**
251
+ * 1. Prepare import files.
252
+ * Manually uploaded import files or predefined import files via filter: pt-ocdi/import_files
253
+ */
254
+ if ( ! empty( $_FILES ) ) { // Using manual file uploads?
255
 
256
+ // Get paths for the uploaded files.
257
+ $this->selected_import_files = OCDI_Helpers::process_uploaded_files( $_FILES, $this->log_file_path );
258
+
259
+ // Set the name of the import files, because we used the uploaded files.
260
+ $this->import_files[ $this->selected_index ]['import_file_name'] = esc_html__( 'Manually uploaded files', 'pt-ocdi' );
261
+ }
262
+ elseif ( ! empty( $this->import_files[ $this->selected_index ] ) ) { // Use predefined import files from wp filter: pt-ocdi/import_files.
263
 
264
+ // Download the import files (content and widgets files) and save it to variable for later use.
265
+ $this->selected_import_files = OCDI_Helpers::download_import_files(
266
+ $this->import_files[ $this->selected_index ],
267
+ $demo_import_start_time
268
+ );
269
+
270
+ // Check Errors.
271
+ if ( is_wp_error( $this->selected_import_files ) ) {
272
+
273
+ // Write error to log file and send an AJAX response with the error.
274
+ OCDI_Helpers::log_error_and_send_ajax_response(
275
+ $this->selected_import_files->get_error_message(),
276
+ $this->log_file_path,
277
+ esc_html__( 'Downloaded files', 'pt-ocdi' )
278
+ );
279
+ }
280
+
281
+ // Add this message to log file.
282
+ $log_added = OCDI_Helpers::append_to_file(
283
+ sprintf(
284
+ __( 'The import files for: %s were successfully downloaded!', 'pt-ocdi' ),
285
+ $this->import_files[ $this->selected_index ]['import_file_name']
286
+ ) . OCDI_Helpers::import_file_info( $this->selected_import_files ),
287
  $this->log_file_path,
288
+ esc_html__( 'Downloaded files' , 'pt-ocdi' )
289
  );
290
  }
291
+ else {
292
 
293
+ // Send JSON Error response to the AJAX call.
294
+ wp_send_json( esc_html__( 'No import files specified!', 'pt-ocdi' ) );
295
+ }
 
 
 
 
 
 
 
 
 
 
 
296
  }
297
 
298
  /**
299
  * 2. Import content.
300
  * Returns any errors greater then the "error" logger level, that will be displayed on front page.
301
  */
302
+ $this->frontend_error_messages .= $this->import_content( $this->selected_import_files['content'] );
303
 
304
  /**
305
  * 3. Before widgets import setup.
306
  */
307
  $action = 'pt-ocdi/before_widgets_import';
308
+ if ( ( false !== has_action( $action ) ) && empty( $this->frontend_error_messages ) ) {
309
 
310
  // Run the before_widgets_import action to setup other settings.
311
+ $this->do_import_action( $action, $this->import_files[ $this->selected_index ] );
312
  }
313
 
314
  /**
315
  * 4. Import widgets.
316
  */
317
+ if ( ! empty( $this->selected_import_files['widgets'] ) && empty( $this->frontend_error_messages ) ) {
318
+ $this->import_widgets( $this->selected_import_files['widgets'] );
319
  }
320
 
321
  /**
322
  * 5. After import setup.
323
  */
324
  $action = 'pt-ocdi/after_import';
325
+ if ( ( false !== has_action( $action ) ) && empty( $this->frontend_error_messages ) ) {
326
 
327
  // Run the after_import action to setup other settings.
328
+ $this->do_import_action( $action, $this->import_files[ $this->selected_index ] );
329
  }
330
 
331
  // Display final messages (success or error messages).
332
+ if ( empty( $this->frontend_error_messages ) ) {
333
  $response['message'] = sprintf(
334
  __( '%1$s%3$sThat\'s it, all done!%4$s%2$sThe demo import has finished. Please check your page and make sure that everything has imported correctly. If it did, you can deactivate the %3$sOne Click Demo Import%4$s plugin, because it has done its job.%5$s', 'pt-ocdi' ),
335
  '<div class="notice notice-success"><p>',
340
  );
341
  }
342
  else {
343
+ $response['message'] = $this->frontend_error_messages . '<br>';
344
  $response['message'] .= sprintf(
345
  __( '%1$sThe demo import has finished, but there were some import errors.%2$sMore details about the errors can be found in this %3$s%5$slog file%6$s%4$s%7$s', 'pt-ocdi' ),
346
  '<div class="notice notice-error"><p>',
364
  */
365
  private function import_content( $import_file_path ) {
366
 
367
+ $this->microtime = microtime( true );
368
+
369
  // This should be replaced with multiple AJAX calls (import in smaller chunks)
370
  // so that it would not come to the Internal Error, because of the PHP script timeout.
371
  // Also this function has no effect when PHP is running in safe mode
376
  // Disable import of authors.
377
  add_filter( 'wxr_importer.pre_process.user', '__return_false' );
378
 
379
+ // Check, if we need to send another AJAX request.
380
+ add_filter( 'wxr_importer.pre_process.post', array( $this, 'new_ajax_request_maybe' ) );
381
+
382
  // Disables generation of multiple image sizes (thumbnails) in the content import step.
383
+ if ( ! apply_filters( 'pt-ocdi/regenerate_thumbnails_in_content_import', true ) ) {
384
  add_filter( 'intermediate_image_sizes_advanced',
385
  function() {
386
  return null;
402
  );
403
  }
404
 
405
+ // Delete content importer data for current import from DB.
406
+ delete_transient( 'ocdi_importer_data' );
407
+
408
  // Return any error messages for the front page output (errors, critical, alert and emergency level messages only).
409
  return $this->logger->error_output;
410
  }
475
  }
476
 
477
 
478
+ /**
479
+ * Check if we need to create a new AJAX request, so that server does not timeout.
480
+ *
481
+ * @param array $data current post data.
482
+ * @return array
483
+ */
484
+ public function new_ajax_request_maybe( $data ) {
485
+ $time = microtime( true ) - $this->microtime;
486
+
487
+ // We should make a new ajax call, if the time is right.
488
+ if ( $time > apply_filters( 'pt-ocdi/time_for_one_ajax_call', 25 ) ) {
489
+ $this->ajax_call_number++;
490
+ $this->set_importer_data();
491
+
492
+ $response = array(
493
+ 'status' => 'newAJAX',
494
+ 'message' => 'Time for new AJAX request!: ' . $time,
495
+ );
496
+
497
+ // Add any output to the log file and clear the buffers.
498
+ $message = ob_get_clean();
499
+
500
+ // Add message to log file.
501
+ $log_added = OCDI_Helpers::append_to_file(
502
+ __( 'Completed AJAX call number: ' , 'pt-ocdi' ) . $this->ajax_call_number . PHP_EOL . $message,
503
+ $this->log_file_path,
504
+ ''
505
+ );
506
+
507
+ wp_send_json( $response );
508
+ }
509
+
510
+ return $data;
511
+ }
512
+
513
+ /**
514
+ * Set current state of the content importer, so we can continue the import with new AJAX request.
515
+ */
516
+ private function set_importer_data() {
517
+ $data = array(
518
+ 'frontend_error_messages' => $this->frontend_error_messages,
519
+ 'ajax_call_number' => $this->ajax_call_number,
520
+ 'log_file_path' => $this->log_file_path,
521
+ 'selected_index' => $this->selected_index,
522
+ 'selected_import_files' => $this->selected_import_files,
523
+ );
524
+
525
+ $data = array_merge( $data, $this->importer->get_importer_data() );
526
+
527
+ set_transient( 'ocdi_importer_data', $data, 0.5 * HOUR_IN_SECONDS );
528
+ }
529
+
530
+ /**
531
+ * Get content importer data, so we can continue the import with this new AJAX request.
532
+ */
533
+ private function get_importer_data() {
534
+ if ( $data = get_transient( 'ocdi_importer_data' ) ) {
535
+ $this->frontend_error_messages = empty( $data['frontend_error_messages'] ) ? '' : $data['frontend_error_messages'];
536
+ $this->ajax_call_number = empty( $data['ajax_call_number'] ) ? 1 : $data['ajax_call_number'];
537
+ $this->log_file_path = empty( $data['log_file_path'] ) ? '' : $data['log_file_path'];
538
+ $this->selected_index = empty( $data['selected_index'] ) ? 0 : $data['selected_index'];
539
+ $this->selected_import_files = empty( $data['selected_import_files'] ) ? array() : $data['selected_import_files'];
540
+ $this->importer->set_importer_data( $data );
541
+
542
+ return true;
543
+ }
544
+ return false;
545
+ }
546
+
547
+ /**
548
+ * Load the plugin textdomain, so that translations can be made.
549
+ */
550
+ public function load_textdomain() {
551
+ load_plugin_textdomain( 'pt-ocdi', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' );
552
+ }
553
+
554
+
555
  /**
556
  * Get data from filters, after the theme has loaded and instantiate the importer.
557
  */
579
  }
580
  }
581
 
582
+ $pt_one_click_demo_import = PT_One_Click_Demo_Import::getInstance();
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: capuderg, cyman
3
  Tags: import, content, demo, data, widgets, settings
4
  Requires at least: 4.0.0
5
  Tested up to: 4.5
6
- Stable tag: 1.0.3
7
  License: GPLv3 or later
8
 
9
  Import your demo content, widgets and theme settings with one click. Theme authors! Enable simple demo import for your theme demo data.
@@ -90,7 +90,7 @@ add_action( 'pt-ocdi/after_import', 'ocdi_after_import' );
90
 
91
  = Can I add some code before the widgets get imported? =
92
 
93
- Of course you can, use the `pt-ocdi/before_widgets_import` filter. You can also target different predefined demo imports like in the example above. Here is a simple example code of the `pt-ocdi/before_widgets_import` filter:
94
 
95
  `
96
  function ocdi_before_widgets_import( $selected_import ) {
@@ -109,7 +109,7 @@ function ocdi_plugin_intro_text( $default_text ) {
109
 
110
  return $default_text;
111
  }
112
- add_action( 'pt-ocdi/plugin_intro_text', 'ocdi_plugin_intro_text' );
113
  `
114
 
115
  To add some text in a separate "box", you should wrap your text in a div with a class of 'ocdi__intro-text', like in the code example above.
@@ -124,6 +124,14 @@ This happens, because your hosting server is using a very old version of PHP. Th
124
 
125
  == Changelog ==
126
 
 
 
 
 
 
 
 
 
127
  = 1.0.3 =
128
 
129
  *Release Date - 27 April 2016*
3
  Tags: import, content, demo, data, widgets, settings
4
  Requires at least: 4.0.0
5
  Tested up to: 4.5
6
+ Stable tag: 1.1.0
7
  License: GPLv3 or later
8
 
9
  Import your demo content, widgets and theme settings with one click. Theme authors! Enable simple demo import for your theme demo data.
90
 
91
  = Can I add some code before the widgets get imported? =
92
 
93
+ Of course you can, use the `pt-ocdi/before_widgets_import` action. You can also target different predefined demo imports like in the example above. Here is a simple example code of the `pt-ocdi/before_widgets_import` action:
94
 
95
  `
96
  function ocdi_before_widgets_import( $selected_import ) {
109
 
110
  return $default_text;
111
  }
112
+ add_filter( 'pt-ocdi/plugin_intro_text', 'ocdi_plugin_intro_text' );
113
  `
114
 
115
  To add some text in a separate "box", you should wrap your text in a div with a class of 'ocdi__intro-text', like in the code example above.
124
 
125
  == Changelog ==
126
 
127
+ = 1.1.0 =
128
+
129
+ *Release Date - 14 May 2016*
130
+
131
+ * Content import now imports in multiple AJAX calls, so there should be no more server timeout errors,
132
+ * The setting for generation of multiple image sizes in the content import is again enabled by default,
133
+ * Plugin textdomain was loaded, so that translations can be made.
134
+
135
  = 1.0.3 =
136
 
137
  *Release Date - 27 April 2016*