One Click Demo Import - Version 1.2.0

Version Description

Release Date - 9 July 2016

  • Now also accepts predefined local import files (from theme folder),
  • Fixes PHP fatal error on plugin activation, for sites using PHP versions older then 5.3.2 (added admin error notice),
  • Register log file in wp-admin -> Media, so that it's easier to access,
  • No more "[WARNING] Could not find the author for ..." messages in the log file.
Download this release

Release Info

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

Code changes from version 1.1.3 to 1.2.0

inc/class-ocdi-helpers.php CHANGED
@@ -36,7 +36,7 @@ class OCDI_Helpers {
36
  * @return boolean
37
  */
38
  private static function is_import_file_info_format_correct( $import_file_info ) {
39
- if ( empty( $import_file_info['import_file_url'] ) || empty( $import_file_info['import_file_name'] ) ) {
40
  return false;
41
  }
42
 
@@ -54,28 +54,50 @@ class OCDI_Helpers {
54
  public static function download_import_files( $import_file_info, $start_date = '' ) {
55
 
56
  $downloaded_files = array();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
 
58
- // Retrieve demo data content from the URL.
59
- $demo_import_content = self::get_content_from_url( $import_file_info['import_file_url'], $import_file_info['import_file_name'] );
60
 
61
- // Return from this function if there was an error.
62
- if ( is_wp_error( $demo_import_content ) ) {
63
- return $demo_import_content;
64
- }
65
 
66
- // Setup filename path to save the data content.
67
- $upload_dir = wp_upload_dir();
68
- $upload_path = apply_filters( 'pt-ocdi/upload_file_path', trailingslashit( $upload_dir['path'] ) );
69
- $demo_import_file_path = $upload_path . apply_filters( 'pt-ocdi/downloaded_content_file_prefix', 'demo-content-import-file_' ) . $start_date . apply_filters( 'pt-ocdi/downloaded_content_file_suffix_and_file_extension', '.xml' );
70
 
71
- // Write data content to the file and return the file path on successful write.
72
- $downloaded_files['content'] = self::write_to_file( $demo_import_content, $demo_import_file_path );
73
 
74
- // Return from this function if there was an error.
75
- if ( is_wp_error( $downloaded_files['content'] ) ) {
76
- return $downloaded_files['content'];
 
77
  }
78
 
 
79
  // Get widgets file as well. If defined!
80
  if ( ! empty( $import_file_info['import_widget_file_url'] ) ) {
81
 
@@ -98,7 +120,13 @@ class OCDI_Helpers {
98
  return $downloaded_files['widgets'];
99
  }
100
  }
 
 
 
 
 
101
 
 
102
  // Get customizer import file as well. If defined!
103
  if ( ! empty( $import_file_info['import_customizer_file_url'] ) ) {
104
 
@@ -121,6 +149,11 @@ class OCDI_Helpers {
121
  return $downloaded_files['customizer'];
122
  }
123
  }
 
 
 
 
 
124
 
125
  return $downloaded_files;
126
  }
@@ -378,7 +411,37 @@ class OCDI_Helpers {
378
  $upload_dir = wp_upload_dir();
379
  $upload_path = apply_filters( 'pt-ocdi/upload_file_path', trailingslashit( $upload_dir['path'] ) );
380
 
381
- return $upload_path . apply_filters( 'pt-ocdi/log_file_prefix', 'log_file_' ) . $start_date . apply_filters( 'pt-ocdi/log_file_suffix_and_file_extension', '.txt' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
382
  }
383
 
384
 
@@ -511,7 +574,7 @@ class OCDI_Helpers {
511
  public static function import_file_info( $selected_import_files ) {
512
  return PHP_EOL .
513
  sprintf(
514
- __( 'MAX EXECUTION TIME = %s', 'pt-ocdi' ),
515
  ini_get( 'max_execution_time' )
516
  ) . PHP_EOL .
517
  sprintf(
36
  * @return boolean
37
  */
38
  private static function is_import_file_info_format_correct( $import_file_info ) {
39
+ if ( ( empty( $import_file_info['import_file_url'] ) && empty( $import_file_info['local_import_file'] ) ) || empty( $import_file_info['import_file_name'] ) ) {
40
  return false;
41
  }
42
 
54
  public static function download_import_files( $import_file_info, $start_date = '' ) {
55
 
56
  $downloaded_files = array();
57
+ $upload_dir = wp_upload_dir();
58
+ $upload_path = apply_filters( 'pt-ocdi/upload_file_path', trailingslashit( $upload_dir['path'] ) );
59
+
60
+ // ----- Set content file path -----
61
+ // Check if 'import_file_url' is not defined. That would mean a local file.
62
+ if ( empty( $import_file_info['import_file_url'] ) ) {
63
+ if ( file_exists( $import_file_info['local_import_file'] ) ) {
64
+ $downloaded_files['content'] = $import_file_info['local_import_file'];
65
+ }
66
+ else {
67
+ return new WP_Error(
68
+ 'url_or_local_file_not_defined',
69
+ sprintf(
70
+ __( '"import_file_url" or "local_import_file" for %s%s%s are not defined!', 'pt-ocdi' ),
71
+ '<strong>',
72
+ $$import_file_info['import_file_name'],
73
+ '</strong>'
74
+ )
75
+ );
76
+ }
77
+ }
78
+ else {
79
 
80
+ // Retrieve demo data content from the URL.
81
+ $demo_import_content = self::get_content_from_url( $import_file_info['import_file_url'], $import_file_info['import_file_name'] );
82
 
83
+ // Return from this function if there was an error.
84
+ if ( is_wp_error( $demo_import_content ) ) {
85
+ return $demo_import_content;
86
+ }
87
 
88
+ // Setup filename path to save the data content.
89
+ $demo_import_file_path = $upload_path . apply_filters( 'pt-ocdi/downloaded_content_file_prefix', 'demo-content-import-file_' ) . $start_date . apply_filters( 'pt-ocdi/downloaded_content_file_suffix_and_file_extension', '.xml' );
 
 
90
 
91
+ // Write data content to the file and return the file path on successful write.
92
+ $downloaded_files['content'] = self::write_to_file( $demo_import_content, $demo_import_file_path );
93
 
94
+ // Return from this function if there was an error.
95
+ if ( is_wp_error( $downloaded_files['content'] ) ) {
96
+ return $downloaded_files['content'];
97
+ }
98
  }
99
 
100
+ // ----- Set widget file path -----
101
  // Get widgets file as well. If defined!
102
  if ( ! empty( $import_file_info['import_widget_file_url'] ) ) {
103
 
120
  return $downloaded_files['widgets'];
121
  }
122
  }
123
+ else if ( ! empty( $import_file_info['local_import_widget_file'] ) ) {
124
+ if ( file_exists( $import_file_info['local_import_widget_file'] ) ) {
125
+ $downloaded_files['widgets'] = $import_file_info['local_import_widget_file'];
126
+ }
127
+ }
128
 
129
+ // ----- Set customizer file path -----
130
  // Get customizer import file as well. If defined!
131
  if ( ! empty( $import_file_info['import_customizer_file_url'] ) ) {
132
 
149
  return $downloaded_files['customizer'];
150
  }
151
  }
152
+ else if ( ! empty( $import_file_info['local_import_customizer_file'] ) ) {
153
+ if ( file_exists( $import_file_info['local_import_customizer_file'] ) ) {
154
+ $downloaded_files['customizer'] = $import_file_info['local_import_customizer_file'];
155
+ }
156
+ }
157
 
158
  return $downloaded_files;
159
  }
411
  $upload_dir = wp_upload_dir();
412
  $upload_path = apply_filters( 'pt-ocdi/upload_file_path', trailingslashit( $upload_dir['path'] ) );
413
 
414
+ $log_path = $upload_path . apply_filters( 'pt-ocdi/log_file_prefix', 'log_file_' ) . $start_date . apply_filters( 'pt-ocdi/log_file_suffix_and_file_extension', '.txt' );
415
+
416
+ self::register_file_as_media_attachment( $log_path );
417
+
418
+ return $log_path;
419
+ }
420
+
421
+
422
+ /**
423
+ * Register file as attachment to the Media page.
424
+ *
425
+ * @param string $log_path log file path.
426
+ * @return void
427
+ */
428
+ public static function register_file_as_media_attachment( $log_path ) {
429
+
430
+ // Check the type of file.
431
+ $log_mimes = array( 'txt' => 'text/plain' );
432
+ $filetype = wp_check_filetype( basename( $log_path ), apply_filters( 'pt-ocdi/file_mimes', $log_mimes ) );
433
+
434
+ // Prepare an array of post data for the attachment.
435
+ $attachment = array(
436
+ 'guid' => self::get_log_url( $log_path ),
437
+ 'post_mime_type' => $filetype['type'],
438
+ 'post_title' => apply_filters( 'pt-ocdi/attachment_prefix', esc_html__( 'One Click Demo Import - ', 'pt-ocdi' ) ) . preg_replace( '/\.[^.]+$/', '', basename( $log_path ) ),
439
+ 'post_content' => '',
440
+ 'post_status' => 'inherit',
441
+ );
442
+
443
+ // Insert the file as attachment in Media page.
444
+ $attach_id = wp_insert_attachment( $attachment, $log_path );
445
  }
446
 
447
 
574
  public static function import_file_info( $selected_import_files ) {
575
  return PHP_EOL .
576
  sprintf(
577
+ __( 'Initial max execution time = %s', 'pt-ocdi' ),
578
  ini_get( 'max_execution_time' )
579
  ) . PHP_EOL .
580
  sprintf(
inc/class-ocdi-main.php ADDED
@@ -0,0 +1,662 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Main One Click Demo Import plugin class/file.
4
+ *
5
+ * @package ocdi
6
+ */
7
+
8
+ // Include files.
9
+ require PT_OCDI_PATH . 'inc/class-ocdi-helpers.php';
10
+ require PT_OCDI_PATH . 'inc/class-ocdi-importer.php';
11
+ require PT_OCDI_PATH . 'inc/class-ocdi-widget-importer.php';
12
+ require PT_OCDI_PATH . 'inc/class-ocdi-customizer-importer.php';
13
+ require PT_OCDI_PATH . 'inc/class-ocdi-logger.php';
14
+
15
+ /**
16
+ * One Click Demo Import class, so we don't have to worry about namespaces.
17
+ */
18
+ class PT_One_Click_Demo_Import {
19
+
20
+ /**
21
+ * @var $instance the reference to *Singleton* instance of this class
22
+ */
23
+ private static $instance;
24
+
25
+ /**
26
+ * Private variables used throughout the plugin.
27
+ */
28
+ private $importer, $plugin_page, $import_files, $logger, $log_file_path, $selected_index, $selected_import_files, $microtime, $frontend_error_messages, $ajax_call_number;
29
+
30
+
31
+ /**
32
+ * Returns the *Singleton* instance of this class.
33
+ *
34
+ * @return PT_One_Click_Demo_Import the *Singleton* instance.
35
+ */
36
+ public static function getInstance() {
37
+ if ( null === static::$instance ) {
38
+ static::$instance = new static();
39
+ }
40
+
41
+ return static::$instance;
42
+ }
43
+
44
+
45
+ /**
46
+ * Class construct function, to initiate the plugin.
47
+ * Protected constructor to prevent creating a new instance of the
48
+ * *Singleton* via the `new` operator from outside of this class.
49
+ */
50
+ protected function __construct() {
51
+
52
+ // Actions.
53
+ add_action( 'admin_menu', array( $this, 'create_plugin_page' ) );
54
+ add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
55
+ add_action( 'wp_ajax_ocdi_import_demo_data', array( $this, 'import_demo_data_ajax_callback' ) );
56
+ add_action( 'after_setup_theme', array( $this, 'setup_plugin_with_filter_data' ) );
57
+ add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) );
58
+ }
59
+
60
+
61
+ /**
62
+ * Private clone method to prevent cloning of the instance of the *Singleton* instance.
63
+ *
64
+ * @return void
65
+ */
66
+ private function __clone() {}
67
+
68
+
69
+ /**
70
+ * Private unserialize method to prevent unserializing of the *Singleton* instance.
71
+ *
72
+ * @return void
73
+ */
74
+ private function __wakeup() {}
75
+
76
+
77
+ /**
78
+ * Creates the plugin page and a submenu item in WP Appearance menu.
79
+ */
80
+ public function create_plugin_page() {
81
+ $plugin_page_setup = apply_filters( 'pt-ocdi/plugin_page_setup', array(
82
+ 'parent_slug' => 'themes.php',
83
+ 'page_title' => esc_html__( 'One Click Demo Import' , 'pt-ocdi' ),
84
+ 'menu_title' => esc_html__( 'Import Demo Data' , 'pt-ocdi' ),
85
+ 'capability' => 'import',
86
+ 'menu_slug' => 'pt-one-click-demo-import',
87
+ )
88
+ );
89
+
90
+ $this->plugin_page = add_submenu_page( $plugin_page_setup['parent_slug'], $plugin_page_setup['page_title'], $plugin_page_setup['menu_title'], $plugin_page_setup['capability'], $plugin_page_setup['menu_slug'], array( $this, 'display_plugin_page' ) );
91
+ }
92
+
93
+
94
+ /**
95
+ * Plugin page display.
96
+ */
97
+ public function display_plugin_page() {
98
+ ?>
99
+
100
+ <div class="ocdi wrap">
101
+ <h2 class="ocdi__title"><span class="dashicons dashicons-download"></span><?php esc_html_e( 'One Click Demo Import', 'pt-ocdi' ); ?></h2>
102
+
103
+ <?php
104
+
105
+ // Display warrning if PHP safe mode is enabled, since we wont be able to change the max_execution_time.
106
+ if ( ini_get( 'safe_mode' ) ) {
107
+ printf(
108
+ esc_html__( '%sWarning: your server is using %sPHP safe mode%s. This means that you might experience server timeout errors.%s', 'pt-ocdi' ),
109
+ '<div class="notice notice-warning"><p>',
110
+ '<strong>',
111
+ '</strong>',
112
+ '</p></div>'
113
+ );
114
+ }
115
+
116
+ // Start output buffer for displaying the plugin intro text.
117
+ ob_start();
118
+ ?>
119
+
120
+ <div class="ocdi__intro-text">
121
+ <p>
122
+ <?php esc_html_e( 'Importing demo data (post, pages, images, theme settings, ...) is the easiest way to setup your theme. It will allow you to quickly edit everything instead of creating content from scratch. When you import the data, the following things might happen:', 'pt-ocdi' ); ?>
123
+ </p>
124
+
125
+ <ul>
126
+ <li><?php esc_html_e( 'No existing posts, pages, categories, images, custom post types or any other data will be deleted or modified.', 'pt-ocdi' ); ?></li>
127
+ <li><?php esc_html_e( 'Posts, pages, images, widgets and menus will get imported.', 'pt-ocdi' ); ?></li>
128
+ <li><?php esc_html_e( 'Please click "Import Demo Data" button only once and wait, it can take a couple of minutes.', 'pt-ocdi' ); ?></li>
129
+ </ul>
130
+ </div>
131
+
132
+ <div class="ocdi__intro-text">
133
+ <p><?php esc_html_e( 'Before you begin, make sure all the required plugins are activated.', 'pt-ocdi' ); ?></p>
134
+ </div>
135
+
136
+ <?php
137
+ $plugin_intro_text = ob_get_clean();
138
+
139
+ // Display the plugin intro text (can be replaced with custom text through the filter below).
140
+ echo wp_kses_post( apply_filters( 'pt-ocdi/plugin_intro_text', $plugin_intro_text ) );
141
+ ?>
142
+
143
+
144
+ <?php if ( empty( $this->import_files ) ) : ?>
145
+ <div class="notice notice-info below-h2">
146
+ <p>
147
+ <?php esc_html_e( 'There are no predefined import files available in this theme. Please upload the import files manually!', 'pt-ocdi' ); ?>
148
+ </p>
149
+ </div>
150
+ <div>
151
+ <div class="ocdi__single-file-upload-container">
152
+ <h3><label for="content-file-upload"><?php esc_html_e( 'Choose a XML file for content import:', 'pt-ocdi' ); ?></label></h3>
153
+ <input id="ocdi__content-file-upload" type="file" name="content-file-upload">
154
+ </div>
155
+ <div class="ocdi__single-file-upload-container">
156
+ <h3><label for="widget-file-upload"><?php esc_html_e( 'Choose a WIE or JSON file for widget import:', 'pt-ocdi' ); ?></label> <span><?php esc_html_e( '(*optional)', 'pt-ocdi' ); ?></span></h3>
157
+ <input id="ocdi__widget-file-upload" type="file" name="widget-file-upload">
158
+ </div>
159
+ <div class="ocdi__single-file-upload-container">
160
+ <h3><label for="customizer-file-upload"><?php esc_html_e( 'Choose a DAT file for customizer import:', 'pt-ocdi' ); ?></label> <span><?php esc_html_e( '(*optional)', 'pt-ocdi' ); ?></span></h3>
161
+ <input id="ocdi__customizer-file-upload" type="file" name="customizer-file-upload">
162
+ </div>
163
+ </div>
164
+ <?php elseif ( 1 < count( $this->import_files ) ) : ?>
165
+ <div class="ocdi__multi-select-import">
166
+ <h3><?php esc_html_e( 'Choose which demo you want to import:', 'pt-ocdi' ); ?></h3>
167
+ <select id="ocdi__demo-import-files">
168
+ <?php foreach ( $this->import_files as $index => $import_file ) : ?>
169
+ <option value="<?php echo esc_attr( $index ); ?>">
170
+ <?php echo esc_html( $import_file['import_file_name'] ); ?>
171
+ </option>
172
+ <?php endforeach; ?>
173
+ </select>
174
+
175
+ <?php
176
+ // Check if at least one preview image is defined, so we can prepare the structure for display.
177
+ $preview_image_is_defined = false;
178
+ foreach ( $this->import_files as $import_file ) {
179
+ if ( isset( $import_file['import_preview_image_url'] ) ) {
180
+ $preview_image_is_defined = true;
181
+ break;
182
+ }
183
+ }
184
+
185
+ if ( $preview_image_is_defined ) :
186
+ ?>
187
+ <div>
188
+ <p><?php esc_html_e( 'Import preview:', 'pt-ocdi' ); ?></p>
189
+ <p class="ocdi__demo-import-preview-image-message js-ocdi-preview-image-message">
190
+ <?php
191
+ if ( ! isset( $this->import_files[0]['import_preview_image_url'] ) ) {
192
+ esc_html_e( 'No preview image defined for this import.', 'pt-ocdi' );
193
+ }
194
+ // Leave the img tag below and the p tag above available for later changes via JS.
195
+ ?>
196
+ </p>
197
+ <img id="ocdi__demo-import-preview-image" class="js-ocdi-preview-image" src="<?php echo ! empty( $this->import_files[0]['import_preview_image_url'] ) ? esc_url( $this->import_files[0]['import_preview_image_url'] ) : ''; ?>">
198
+ </div>
199
+ <?php endif; ?>
200
+ </div>
201
+ <?php endif; ?>
202
+
203
+ <div class="ocdi__demo-import-notice js-ocdi-demo-import-notice">
204
+ <?php
205
+ if ( is_array( $this->import_files ) && ! empty( $this->import_files[0]['import_notice'] ) ) {
206
+ echo wp_kses_post( $this->import_files[0]['import_notice'] );
207
+ }
208
+ ?>
209
+ </div>
210
+
211
+ <p>
212
+ <button class="ocdi__button button-primary js-ocdi-import-data"><?php esc_html_e( 'Import Demo Data', 'pt-ocdi' ); ?></button>
213
+ </p>
214
+
215
+ <p class="ocdi__ajax-loader js-ocdi-ajax-loader">
216
+ <span class="spinner"></span> <?php esc_html_e( 'Importing, please wait!', 'pt-ocdi' ); ?>
217
+ </p>
218
+
219
+ <div class="ocdi__response js-ocdi-ajax-response"></div>
220
+ </div>
221
+
222
+ <?php
223
+ }
224
+
225
+
226
+ /**
227
+ * Enqueue admin scripts (JS and CSS)
228
+ *
229
+ * @param string $hook holds info on which admin page you are currently loading.
230
+ */
231
+ public function admin_enqueue_scripts( $hook ) {
232
+
233
+ // Enqueue the scripts only on the plugin page.
234
+ if ( $this->plugin_page === $hook ) {
235
+ wp_enqueue_script( 'ocdi-main-js', PT_OCDI_URL . 'assets/js/main.js' , array( 'jquery', 'jquery-form' ), PT_OCDI_VERSION );
236
+
237
+ wp_localize_script( 'ocdi-main-js', 'ocdi',
238
+ array(
239
+ 'ajax_url' => admin_url( 'admin-ajax.php' ),
240
+ 'ajax_nonce' => wp_create_nonce( 'ocdi-ajax-verification' ),
241
+ 'import_files' => $this->import_files,
242
+ 'texts' => array(
243
+ 'missing_preview_image' => esc_html__( 'No preview image defined for this import.', 'pt-ocdi' ),
244
+ ),
245
+ )
246
+ );
247
+
248
+ wp_enqueue_style( 'ocdi-main-css', PT_OCDI_URL . 'assets/css/main.css', array() , PT_OCDI_VERSION );
249
+ }
250
+ }
251
+
252
+
253
+ /**
254
+ * Main AJAX callback function for:
255
+ * 1. prepare import files (uploaded or predefined via filters)
256
+ * 2. import content
257
+ * 3. before widgets import setup (optional)
258
+ * 4. import widgets (optional)
259
+ * 5. import customizer options (optional)
260
+ * 6. after import setup (optional)
261
+ */
262
+ public function import_demo_data_ajax_callback() {
263
+
264
+ // Try to update PHP memory limit (so that it does not run out of it).
265
+ ini_set( 'memory_limit', apply_filters( 'pt-ocdi/import_memory_limit', '350M' ) );
266
+
267
+ // Verify if the AJAX call is valid (checks nonce and current_user_can).
268
+ OCDI_Helpers::verify_ajax_call();
269
+
270
+ // Is this a new AJAX call to continue the previous import?
271
+ $use_existing_importer_data = $this->get_importer_data();
272
+
273
+ if ( ! $use_existing_importer_data ) {
274
+
275
+ // Set the AJAX call number.
276
+ $this->ajax_call_number = empty( $this->ajax_call_number ) ? 0 : $this->ajax_call_number;
277
+
278
+ // Error messages displayed on front page.
279
+ $this->frontend_error_messages = '';
280
+
281
+ // Create a date and time string to use for demo and log file names.
282
+ $demo_import_start_time = date( apply_filters( 'pt-ocdi/date_format_for_file_names', 'Y-m-d__H-i-s' ) );
283
+
284
+ // Define log file path.
285
+ $this->log_file_path = OCDI_Helpers::get_log_path( $demo_import_start_time );
286
+
287
+ // Get selected file index or set it to 0.
288
+ $this->selected_index = empty( $_POST['selected'] ) ? 0 : absint( $_POST['selected'] );
289
+
290
+ /**
291
+ * 1. Prepare import files.
292
+ * Manually uploaded import files or predefined import files via filter: pt-ocdi/import_files
293
+ */
294
+ if ( ! empty( $_FILES ) ) { // Using manual file uploads?
295
+
296
+ // Get paths for the uploaded files.
297
+ $this->selected_import_files = OCDI_Helpers::process_uploaded_files( $_FILES, $this->log_file_path );
298
+
299
+ // Set the name of the import files, because we used the uploaded files.
300
+ $this->import_files[ $this->selected_index ]['import_file_name'] = esc_html__( 'Manually uploaded files', 'pt-ocdi' );
301
+ }
302
+ elseif ( ! empty( $this->import_files[ $this->selected_index ] ) ) { // Use predefined import files from wp filter: pt-ocdi/import_files.
303
+
304
+ // Download the import files (content and widgets files) and save it to variable for later use.
305
+ $this->selected_import_files = OCDI_Helpers::download_import_files(
306
+ $this->import_files[ $this->selected_index ],
307
+ $demo_import_start_time
308
+ );
309
+
310
+ // Check Errors.
311
+ if ( is_wp_error( $this->selected_import_files ) ) {
312
+
313
+ // Write error to log file and send an AJAX response with the error.
314
+ OCDI_Helpers::log_error_and_send_ajax_response(
315
+ $this->selected_import_files->get_error_message(),
316
+ $this->log_file_path,
317
+ esc_html__( 'Downloaded files', 'pt-ocdi' )
318
+ );
319
+ }
320
+
321
+ // Add this message to log file.
322
+ $log_added = OCDI_Helpers::append_to_file(
323
+ sprintf(
324
+ __( 'The import files for: %s were successfully downloaded!', 'pt-ocdi' ),
325
+ $this->import_files[ $this->selected_index ]['import_file_name']
326
+ ) . OCDI_Helpers::import_file_info( $this->selected_import_files ),
327
+ $this->log_file_path,
328
+ esc_html__( 'Downloaded files' , 'pt-ocdi' )
329
+ );
330
+ }
331
+ else {
332
+
333
+ // Send JSON Error response to the AJAX call.
334
+ wp_send_json( esc_html__( 'No import files specified!', 'pt-ocdi' ) );
335
+ }
336
+ }
337
+
338
+ /**
339
+ * 2. Import content.
340
+ * Returns any errors greater then the "error" logger level, that will be displayed on front page.
341
+ */
342
+ $this->frontend_error_messages .= $this->import_content( $this->selected_import_files['content'] );
343
+
344
+ /**
345
+ * 3. Before widgets import setup.
346
+ */
347
+ $action = 'pt-ocdi/before_widgets_import';
348
+ if ( ( false !== has_action( $action ) ) && empty( $this->frontend_error_messages ) ) {
349
+
350
+ // Run the before_widgets_import action to setup other settings.
351
+ $this->do_import_action( $action, $this->import_files[ $this->selected_index ] );
352
+ }
353
+
354
+ /**
355
+ * 4. Import widgets.
356
+ */
357
+ if ( ! empty( $this->selected_import_files['widgets'] ) && empty( $this->frontend_error_messages ) ) {
358
+ $this->import_widgets( $this->selected_import_files['widgets'] );
359
+ }
360
+
361
+ /**
362
+ * 5. Import customize options.
363
+ */
364
+ if ( ! empty( $this->selected_import_files['customizer'] ) && empty( $this->frontend_error_messages ) ) {
365
+ $this->import_customizer( $this->selected_import_files['customizer'] );
366
+ }
367
+
368
+ /**
369
+ * 6. After import setup.
370
+ */
371
+ $action = 'pt-ocdi/after_import';
372
+ if ( ( false !== has_action( $action ) ) && empty( $this->frontend_error_messages ) ) {
373
+
374
+ // Run the after_import action to setup other settings.
375
+ $this->do_import_action( $action, $this->import_files[ $this->selected_index ] );
376
+ }
377
+
378
+ // Display final messages (success or error messages).
379
+ if ( empty( $this->frontend_error_messages ) ) {
380
+ $response['message'] = sprintf(
381
+ __( '%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' ),
382
+ '<div class="notice notice-success"><p>',
383
+ '<br>',
384
+ '<strong>',
385
+ '</strong>',
386
+ '</p></div>'
387
+ );
388
+ }
389
+ else {
390
+ $response['message'] = $this->frontend_error_messages . '<br>';
391
+ $response['message'] .= sprintf(
392
+ __( '%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' ),
393
+ '<div class="notice notice-error"><p>',
394
+ '<br>',
395
+ '<strong>',
396
+ '</strong>',
397
+ '<a href="' . OCDI_Helpers::get_log_url( $this->log_file_path ) .'" target="_blank">',
398
+ '</a>',
399
+ '</p></div>'
400
+ );
401
+ }
402
+
403
+ wp_send_json( $response );
404
+ }
405
+
406
+
407
+ /**
408
+ * Import content from an WP XML file.
409
+ *
410
+ * @param string $import_file_path path to the import file.
411
+ */
412
+ private function import_content( $import_file_path ) {
413
+
414
+ $this->microtime = microtime( true );
415
+
416
+ // This should be replaced with multiple AJAX calls (import in smaller chunks)
417
+ // so that it would not come to the Internal Error, because of the PHP script timeout.
418
+ // Also this function has no effect when PHP is running in safe mode
419
+ // http://php.net/manual/en/function.set-time-limit.php.
420
+ // Increase PHP max execution time.
421
+ set_time_limit( apply_filters( 'pt-ocdi/set_time_limit_for_demo_data_import', 300 ) );
422
+
423
+ // Disable import of authors.
424
+ add_filter( 'wxr_importer.pre_process.user', '__return_false' );
425
+
426
+ // Check, if we need to send another AJAX request and set the importing author to the current user.
427
+ add_filter( 'wxr_importer.pre_process.post', array( $this, 'new_ajax_request_maybe' ) );
428
+
429
+ // Disables generation of multiple image sizes (thumbnails) in the content import step.
430
+ if ( ! apply_filters( 'pt-ocdi/regenerate_thumbnails_in_content_import', true ) ) {
431
+ add_filter( 'intermediate_image_sizes_advanced',
432
+ function() {
433
+ return null;
434
+ }
435
+ );
436
+ }
437
+
438
+ // Import content.
439
+ if ( ! empty( $import_file_path ) ) {
440
+ ob_start();
441
+ $this->importer->import( $import_file_path );
442
+ $message = ob_get_clean();
443
+
444
+ // Add this message to log file.
445
+ $log_added = OCDI_Helpers::append_to_file(
446
+ $message . PHP_EOL . esc_html__( 'Max execution time after content import = ' , 'pt-ocdi' ) . ini_get( 'max_execution_time' ),
447
+ $this->log_file_path,
448
+ esc_html__( 'Importing content' , 'pt-ocdi' )
449
+ );
450
+ }
451
+
452
+ // Delete content importer data for current import from DB.
453
+ delete_transient( 'ocdi_importer_data' );
454
+
455
+ // Return any error messages for the front page output (errors, critical, alert and emergency level messages only).
456
+ return $this->logger->error_output;
457
+ }
458
+
459
+
460
+ /**
461
+ * Import widgets from WIE or JSON file.
462
+ *
463
+ * @param string $widget_import_file_path path to the widget import file.
464
+ */
465
+ private function import_widgets( $widget_import_file_path ) {
466
+
467
+ // Widget import results.
468
+ $results = array();
469
+
470
+ // Create an instance of the Widget Importer.
471
+ $widget_importer = new OCDI_Widget_Importer();
472
+
473
+ // Import widgets.
474
+ if ( ! empty( $widget_import_file_path ) ) {
475
+
476
+ // Import widgets and return result.
477
+ $results = $widget_importer->import_widgets( $widget_import_file_path );
478
+ }
479
+
480
+ // Check for errors.
481
+ if ( is_wp_error( $results ) ) {
482
+
483
+ // Write error to log file and send an AJAX response with the error.
484
+ OCDI_Helpers::log_error_and_send_ajax_response(
485
+ $results->get_error_message(),
486
+ $this->log_file_path,
487
+ esc_html__( 'Importing widgets', 'pt-ocdi' )
488
+ );
489
+ }
490
+
491
+ ob_start();
492
+ $widget_importer->format_results_for_log( $results );
493
+ $message = ob_get_clean();
494
+
495
+ // Add this message to log file.
496
+ $log_added = OCDI_Helpers::append_to_file(
497
+ $message,
498
+ $this->log_file_path,
499
+ esc_html__( 'Importing widgets' , 'pt-ocdi' )
500
+ );
501
+ }
502
+
503
+
504
+ /**
505
+ * Import customizer from a DAT file, generated by the Customizer Export/Import plugin.
506
+ *
507
+ * @param string $customizer_import_file_path path to the customizer import file.
508
+ */
509
+ private function import_customizer( $customizer_import_file_path ) {
510
+
511
+ // Try to import the customizer settings.
512
+ $results = OCDI_Customizer_Importer::import_customizer_options( $customizer_import_file_path );
513
+
514
+ // Check for errors.
515
+ if ( is_wp_error( $results ) ) {
516
+
517
+ // Write error to log file and send an AJAX response with the error.
518
+ OCDI_Helpers::log_error_and_send_ajax_response(
519
+ $results->get_error_message(),
520
+ $this->log_file_path,
521
+ esc_html__( 'Importing customizer settings', 'pt-ocdi' )
522
+ );
523
+ }
524
+
525
+ // Add this message to log file.
526
+ $log_added = OCDI_Helpers::append_to_file(
527
+ esc_html__( 'Customizer settings import finished!', 'pt-ocdi' ),
528
+ $this->log_file_path,
529
+ esc_html__( 'Importing customizer settings' , 'pt-ocdi' )
530
+ );
531
+ }
532
+
533
+
534
+ /**
535
+ * Setup other things in the passed wp action.
536
+ *
537
+ * @param string $action the action name to be executed.
538
+ * @param array $selected_import with information about the selected import.
539
+ */
540
+ private function do_import_action( $action, $selected_import ) {
541
+
542
+ ob_start();
543
+ do_action( $action, $selected_import );
544
+ $message = ob_get_clean();
545
+
546
+ // Add this message to log file.
547
+ $log_added = OCDI_Helpers::append_to_file(
548
+ $message,
549
+ $this->log_file_path,
550
+ $action
551
+ );
552
+ }
553
+
554
+
555
+ /**
556
+ * Check if we need to create a new AJAX request, so that server does not timeout.
557
+ *
558
+ * @param array $data current post data.
559
+ * @return array
560
+ */
561
+ public function new_ajax_request_maybe( $data ) {
562
+ $time = microtime( true ) - $this->microtime;
563
+
564
+ // We should make a new ajax call, if the time is right.
565
+ if ( $time > apply_filters( 'pt-ocdi/time_for_one_ajax_call', 25 ) ) {
566
+ $this->ajax_call_number++;
567
+ $this->set_importer_data();
568
+
569
+ $response = array(
570
+ 'status' => 'newAJAX',
571
+ 'message' => 'Time for new AJAX request!: ' . $time,
572
+ );
573
+
574
+ // Add any output to the log file and clear the buffers.
575
+ $message = ob_get_clean();
576
+
577
+ // Add message to log file.
578
+ $log_added = OCDI_Helpers::append_to_file(
579
+ __( 'Completed AJAX call number: ' , 'pt-ocdi' ) . $this->ajax_call_number . PHP_EOL . $message,
580
+ $this->log_file_path,
581
+ ''
582
+ );
583
+
584
+ wp_send_json( $response );
585
+ }
586
+
587
+ // Set importing author to the current user.
588
+ // Fixes the [WARNING] Could not find the author for ... log warning messages.
589
+ $current_user_obj = wp_get_current_user();
590
+ $data['post_author'] = $current_user_obj->user_login;
591
+
592
+ return $data;
593
+ }
594
+
595
+ /**
596
+ * Set current state of the content importer, so we can continue the import with new AJAX request.
597
+ */
598
+ private function set_importer_data() {
599
+ $data = array(
600
+ 'frontend_error_messages' => $this->frontend_error_messages,
601
+ 'ajax_call_number' => $this->ajax_call_number,
602
+ 'log_file_path' => $this->log_file_path,
603
+ 'selected_index' => $this->selected_index,
604
+ 'selected_import_files' => $this->selected_import_files,
605
+ );
606
+
607
+ $data = array_merge( $data, $this->importer->get_importer_data() );
608
+
609
+ set_transient( 'ocdi_importer_data', $data, 0.5 * HOUR_IN_SECONDS );
610
+ }
611
+
612
+ /**
613
+ * Get content importer data, so we can continue the import with this new AJAX request.
614
+ */
615
+ private function get_importer_data() {
616
+ if ( $data = get_transient( 'ocdi_importer_data' ) ) {
617
+ $this->frontend_error_messages = empty( $data['frontend_error_messages'] ) ? '' : $data['frontend_error_messages'];
618
+ $this->ajax_call_number = empty( $data['ajax_call_number'] ) ? 1 : $data['ajax_call_number'];
619
+ $this->log_file_path = empty( $data['log_file_path'] ) ? '' : $data['log_file_path'];
620
+ $this->selected_index = empty( $data['selected_index'] ) ? 0 : $data['selected_index'];
621
+ $this->selected_import_files = empty( $data['selected_import_files'] ) ? array() : $data['selected_import_files'];
622
+ $this->importer->set_importer_data( $data );
623
+
624
+ return true;
625
+ }
626
+ return false;
627
+ }
628
+
629
+ /**
630
+ * Load the plugin textdomain, so that translations can be made.
631
+ */
632
+ public function load_textdomain() {
633
+ load_plugin_textdomain( 'pt-ocdi', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' );
634
+ }
635
+
636
+
637
+ /**
638
+ * Get data from filters, after the theme has loaded and instantiate the importer.
639
+ */
640
+ public function setup_plugin_with_filter_data() {
641
+
642
+ // Get info of import data files and filter it.
643
+ $this->import_files = OCDI_Helpers::validate_import_file_info( apply_filters( 'pt-ocdi/import_files', array() ) );
644
+
645
+ // Importer options array.
646
+ $importer_options = apply_filters( 'pt-ocdi/importer_options', array(
647
+ 'fetch_attachments' => true,
648
+ ) );
649
+
650
+ // Logger options for the logger used in the importer.
651
+ $logger_options = apply_filters( 'pt-ocdi/logger_options', array(
652
+ 'logger_min_level' => 'warning',
653
+ ) );
654
+
655
+ // Configure logger instance and set it to the importer.
656
+ $this->logger = new OCDI_Logger();
657
+ $this->logger->min_level = $logger_options['logger_min_level'];
658
+
659
+ // Create importer instance with proper parameters.
660
+ $this->importer = new OCDI_Importer( $importer_options, $this->logger );
661
+ }
662
+ }
inc/class-ocdi-wxr-importer.php CHANGED
@@ -14,6 +14,15 @@ if ( ! class_exists( 'WXR_Importer' ) ) {
14
 
15
  class OCDI_WXR_Importer extends WXR_Importer {
16
 
 
 
 
 
 
 
 
 
 
17
  /**
18
  * Get all protected variables from the WXR_Importer needed for continuing the import.
19
  */
14
 
15
  class OCDI_WXR_Importer extends WXR_Importer {
16
 
17
+ public function __construct( $options = array() ) {
18
+ parent::__construct( $options );
19
+
20
+ // Set current user to $mapping variable.
21
+ // Fixes the [WARNING] Could not find the author for ... log warning messages.
22
+ $current_user_obj = wp_get_current_user();
23
+ $this->mapping['user_slug'][ $current_user_obj->user_login ] = $current_user_obj->ID;
24
+ }
25
+
26
  /**
27
  * Get all protected variables from the WXR_Importer needed for continuing the import.
28
  */
languages/pt-ocdi.pot CHANGED
@@ -2,7 +2,7 @@
2
  # This file is distributed under the GPL 2.0.
3
  msgid ""
4
  msgstr ""
5
- "Project-Id-Version: One Click Demo Import 1.1.2\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"
@@ -40,29 +40,33 @@ msgid ""
40
  "import customizer settings for the same theme or a child theme."
41
  msgstr ""
42
 
43
- #: inc/class-ocdi-helpers.php:143
 
 
 
 
44
  msgid "URL for %s%s%s file is not defined!"
45
  msgstr ""
46
 
47
- #: inc/class-ocdi-helpers.php:165
48
  msgid ""
49
  "An error occurred while fetching %s%s%s file from the server!%sReason: %s - "
50
  "%s."
51
  msgstr ""
52
 
53
- #: inc/class-ocdi-helpers.php:205 inc/class-ocdi-helpers.php:249
54
  msgid ""
55
  "An error occurred while writing file to your server! Tried to write a file "
56
  "to: %s%s."
57
  msgstr ""
58
 
59
- #: inc/class-ocdi-helpers.php:284
60
  msgid ""
61
  "An error occurred while reading a file from your server! Tried reading file "
62
  "from path: %s%s."
63
  msgstr ""
64
 
65
- #: inc/class-ocdi-helpers.php:308
66
  msgid ""
67
  "This WordPress page does not have %sdirect%s write file access. This plugin "
68
  "needs it in order to save the demo import xml file to the upload directory "
@@ -73,108 +77,76 @@ msgstr ""
73
  msgid "One Click Demo Import"
74
  msgstr ""
75
 
76
- #: inc/class-ocdi-helpers.php:320 one-click-demo-import.php:101
77
- #: one-click-demo-import.php:229
78
  msgid "Import Demo Data"
79
  msgstr ""
80
 
81
- #: inc/class-ocdi-helpers.php:332
82
  msgid ""
83
  "An error occurred while retrieving reading/writing permissions to your "
84
  "server (could not retrieve WP filesystem credentials)!"
85
  msgstr ""
86
 
87
- #: inc/class-ocdi-helpers.php:340
88
  msgid "Your WordPress login credentials don't allow to use WP_Filesystem!"
89
  msgstr ""
90
 
91
- #: inc/class-ocdi-helpers.php:411
 
 
 
 
92
  msgid ""
93
  "%sYour user role isn't high enough. You don't have permission to import "
94
  "demo data.%s"
95
  msgstr ""
96
 
97
- #: inc/class-ocdi-helpers.php:447
98
  msgid ""
99
  "Please upload XML file for content import. If you want to import widgets or "
100
  "customizer settings only, please use Widget Importer & Exporter or the "
101
  "Customizer Export/Import plugin."
102
  msgstr ""
103
 
104
- #: inc/class-ocdi-helpers.php:449 inc/class-ocdi-helpers.php:471
105
- #: inc/class-ocdi-helpers.php:490 inc/class-ocdi-helpers.php:498
106
  msgid "Upload files"
107
  msgstr ""
108
 
109
- #: inc/class-ocdi-helpers.php:467
110
  msgid "Widget file was not uploaded. Error: %s"
111
  msgstr ""
112
 
113
- #: inc/class-ocdi-helpers.php:486
114
  msgid "Customizer file was not uploaded. Error: %s"
115
  msgstr ""
116
 
117
- #: inc/class-ocdi-helpers.php:496
118
  msgid "The import files were successfully uploaded!"
119
  msgstr ""
120
 
121
- #: inc/class-ocdi-helpers.php:514
122
- msgid "MAX EXECUTION TIME = %s"
123
  msgstr ""
124
 
125
- #: inc/class-ocdi-helpers.php:518
126
  msgid ""
127
  "Files info:%1$sSite URL = %2$s%1$sData file = %3$s%1$sWidget file = "
128
  "%4$s%1$sCustomizer file = %5$s"
129
  msgstr ""
130
 
131
- #: inc/class-ocdi-helpers.php:522 inc/class-ocdi-helpers.php:523
132
  msgid "not defined!"
133
  msgstr ""
134
 
135
- #: inc/class-ocdi-widget-importer.php:44
136
- msgid "Widget import file could not be found."
137
- msgstr ""
138
-
139
- #: inc/class-ocdi-widget-importer.php:76
140
- msgid "Widget import data could not be read. Please try a different file."
141
- msgstr ""
142
-
143
- #: inc/class-ocdi-widget-importer.php:116
144
- msgid "Sidebar does not exist in theme (moving widget to Inactive)"
145
- msgstr ""
146
-
147
- #: inc/class-ocdi-widget-importer.php:138
148
- msgid "Site does not support widget"
149
- msgstr ""
150
-
151
- #: inc/class-ocdi-widget-importer.php:173
152
- msgid "Widget already exists"
153
- msgstr ""
154
-
155
- #: inc/class-ocdi-widget-importer.php:232
156
- msgid "Imported"
157
- msgstr ""
158
-
159
- #: inc/class-ocdi-widget-importer.php:236
160
- msgid "Imported to Inactive"
161
- msgstr ""
162
-
163
- #: inc/class-ocdi-widget-importer.php:242
164
- msgid "No Title"
165
- msgstr ""
166
-
167
- #: inc/class-ocdi-widget-importer.php:291
168
- msgid "No results for widget import!"
169
- msgstr ""
170
-
171
- #: one-click-demo-import.php:125
172
  msgid ""
173
  "%sWarning: your server is using %sPHP safe mode%s. This means that you "
174
  "might experience server timeout errors.%s"
175
  msgstr ""
176
 
177
- #: one-click-demo-import.php:139
178
  msgid ""
179
  "Importing demo data (post, pages, images, theme settings, ...) is the "
180
  "easiest way to setup your theme. It will allow you to quickly edit "
@@ -182,81 +154,81 @@ msgid ""
182
  "data, the following things might happen:"
183
  msgstr ""
184
 
185
- #: one-click-demo-import.php:143
186
  msgid ""
187
  "No existing posts, pages, categories, images, custom post types or any "
188
  "other data will be deleted or modified."
189
  msgstr ""
190
 
191
- #: one-click-demo-import.php:144
192
  msgid "Posts, pages, images, widgets and menus will get imported."
193
  msgstr ""
194
 
195
- #: one-click-demo-import.php:145
196
  msgid ""
197
  "Please click \"Import Demo Data\" button only once and wait, it can take a "
198
  "couple of minutes."
199
  msgstr ""
200
 
201
- #: one-click-demo-import.php:150
202
  msgid "Before you begin, make sure all the required plugins are activated."
203
  msgstr ""
204
 
205
- #: one-click-demo-import.php:164
206
  msgid ""
207
  "There are no predefined import files available in this theme. Please upload "
208
  "the import files manually!"
209
  msgstr ""
210
 
211
- #: one-click-demo-import.php:169
212
  msgid "Choose a XML file for content import:"
213
  msgstr ""
214
 
215
- #: one-click-demo-import.php:173
216
  msgid "Choose a WIE or JSON file for widget import:"
217
  msgstr ""
218
 
219
- #: one-click-demo-import.php:173 one-click-demo-import.php:177
220
  msgid "(*optional)"
221
  msgstr ""
222
 
223
- #: one-click-demo-import.php:177
224
  msgid "Choose a DAT file for customizer import:"
225
  msgstr ""
226
 
227
- #: one-click-demo-import.php:183
228
  msgid "Choose which demo you want to import:"
229
  msgstr ""
230
 
231
- #: one-click-demo-import.php:205
232
  msgid "Import preview:"
233
  msgstr ""
234
 
235
- #: one-click-demo-import.php:209 one-click-demo-import.php:260
236
  msgid "No preview image defined for this import."
237
  msgstr ""
238
 
239
- #: one-click-demo-import.php:233
240
  msgid "Importing, please wait!"
241
  msgstr ""
242
 
243
- #: one-click-demo-import.php:317
244
  msgid "Manually uploaded files"
245
  msgstr ""
246
 
247
- #: one-click-demo-import.php:334 one-click-demo-import.php:345
248
  msgid "Downloaded files"
249
  msgstr ""
250
 
251
- #: one-click-demo-import.php:341
252
  msgid "The import files for: %s were successfully downloaded!"
253
  msgstr ""
254
 
255
- #: one-click-demo-import.php:351
256
  msgid "No import files specified!"
257
  msgstr ""
258
 
259
- #: one-click-demo-import.php:398
260
  msgid ""
261
  "%1$s%3$sThat's it, all done!%4$s%2$sThe demo import has finished. Please "
262
  "check your page and make sure that everything has imported correctly. If it "
@@ -264,33 +236,81 @@ msgid ""
264
  "it has done its job.%5$s"
265
  msgstr ""
266
 
267
- #: one-click-demo-import.php:409
268
  msgid ""
269
  "%1$sThe demo import has finished, but there were some import "
270
  "errors.%2$sMore details about the errors can be found in this %3$s%5$slog "
271
  "file%6$s%4$s%7$s"
272
  msgstr ""
273
 
274
- #: one-click-demo-import.php:465
 
 
 
 
275
  msgid "Importing content"
276
  msgstr ""
277
 
278
- #: one-click-demo-import.php:504 one-click-demo-import.php:516
279
  msgid "Importing widgets"
280
  msgstr ""
281
 
282
- #: one-click-demo-import.php:538 one-click-demo-import.php:546
283
  msgid "Importing customizer settings"
284
  msgstr ""
285
 
286
- #: one-click-demo-import.php:544
287
  msgid "Customizer settings import finished!"
288
  msgstr ""
289
 
290
- #: one-click-demo-import.php:596
291
  msgid "Completed AJAX call number: "
292
  msgstr ""
293
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
294
  #. Plugin URI of the plugin/theme
295
  msgid "https://wordpress.org/plugins/one-click-demo-import/"
296
  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.3\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"
40
  "import customizer settings for the same theme or a child theme."
41
  msgstr ""
42
 
43
+ #: inc/class-ocdi-helpers.php:70
44
+ msgid "\"import_file_url\" or \"local_import_file\" for %s%s%s are not defined!"
45
+ msgstr ""
46
+
47
+ #: inc/class-ocdi-helpers.php:176
48
  msgid "URL for %s%s%s file is not defined!"
49
  msgstr ""
50
 
51
+ #: inc/class-ocdi-helpers.php:198
52
  msgid ""
53
  "An error occurred while fetching %s%s%s file from the server!%sReason: %s - "
54
  "%s."
55
  msgstr ""
56
 
57
+ #: inc/class-ocdi-helpers.php:238 inc/class-ocdi-helpers.php:282
58
  msgid ""
59
  "An error occurred while writing file to your server! Tried to write a file "
60
  "to: %s%s."
61
  msgstr ""
62
 
63
+ #: inc/class-ocdi-helpers.php:317
64
  msgid ""
65
  "An error occurred while reading a file from your server! Tried reading file "
66
  "from path: %s%s."
67
  msgstr ""
68
 
69
+ #: inc/class-ocdi-helpers.php:341
70
  msgid ""
71
  "This WordPress page does not have %sdirect%s write file access. This plugin "
72
  "needs it in order to save the demo import xml file to the upload directory "
77
  msgid "One Click Demo Import"
78
  msgstr ""
79
 
80
+ #: inc/class-ocdi-helpers.php:353 inc/class-ocdi-main.php:84
81
+ #: inc/class-ocdi-main.php:212
82
  msgid "Import Demo Data"
83
  msgstr ""
84
 
85
+ #: inc/class-ocdi-helpers.php:365
86
  msgid ""
87
  "An error occurred while retrieving reading/writing permissions to your "
88
  "server (could not retrieve WP filesystem credentials)!"
89
  msgstr ""
90
 
91
+ #: inc/class-ocdi-helpers.php:373
92
  msgid "Your WordPress login credentials don't allow to use WP_Filesystem!"
93
  msgstr ""
94
 
95
+ #: inc/class-ocdi-helpers.php:438
96
+ msgid "One Click Demo Import - "
97
+ msgstr ""
98
+
99
+ #: inc/class-ocdi-helpers.php:474
100
  msgid ""
101
  "%sYour user role isn't high enough. You don't have permission to import "
102
  "demo data.%s"
103
  msgstr ""
104
 
105
+ #: inc/class-ocdi-helpers.php:510
106
  msgid ""
107
  "Please upload XML file for content import. If you want to import widgets or "
108
  "customizer settings only, please use Widget Importer & Exporter or the "
109
  "Customizer Export/Import plugin."
110
  msgstr ""
111
 
112
+ #: inc/class-ocdi-helpers.php:512 inc/class-ocdi-helpers.php:534
113
+ #: inc/class-ocdi-helpers.php:553 inc/class-ocdi-helpers.php:561
114
  msgid "Upload files"
115
  msgstr ""
116
 
117
+ #: inc/class-ocdi-helpers.php:530
118
  msgid "Widget file was not uploaded. Error: %s"
119
  msgstr ""
120
 
121
+ #: inc/class-ocdi-helpers.php:549
122
  msgid "Customizer file was not uploaded. Error: %s"
123
  msgstr ""
124
 
125
+ #: inc/class-ocdi-helpers.php:559
126
  msgid "The import files were successfully uploaded!"
127
  msgstr ""
128
 
129
+ #: inc/class-ocdi-helpers.php:577
130
+ msgid "Initial max execution time = %s"
131
  msgstr ""
132
 
133
+ #: inc/class-ocdi-helpers.php:581
134
  msgid ""
135
  "Files info:%1$sSite URL = %2$s%1$sData file = %3$s%1$sWidget file = "
136
  "%4$s%1$sCustomizer file = %5$s"
137
  msgstr ""
138
 
139
+ #: inc/class-ocdi-helpers.php:585 inc/class-ocdi-helpers.php:586
140
  msgid "not defined!"
141
  msgstr ""
142
 
143
+ #: inc/class-ocdi-main.php:108
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ #: inc/class-ocdi-main.php:122
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
  "data, the following things might happen:"
155
  msgstr ""
156
 
157
+ #: inc/class-ocdi-main.php:126
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
+ #: inc/class-ocdi-main.php:127
164
  msgid "Posts, pages, images, widgets and menus will get imported."
165
  msgstr ""
166
 
167
+ #: inc/class-ocdi-main.php:128
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
+ #: inc/class-ocdi-main.php:133
174
  msgid "Before you begin, make sure all the required plugins are activated."
175
  msgstr ""
176
 
177
+ #: inc/class-ocdi-main.php:147
178
  msgid ""
179
  "There are no predefined import files available in this theme. Please upload "
180
  "the import files manually!"
181
  msgstr ""
182
 
183
+ #: inc/class-ocdi-main.php:152
184
  msgid "Choose a XML file for content import:"
185
  msgstr ""
186
 
187
+ #: inc/class-ocdi-main.php:156
188
  msgid "Choose a WIE or JSON file for widget import:"
189
  msgstr ""
190
 
191
+ #: inc/class-ocdi-main.php:156 inc/class-ocdi-main.php:160
192
  msgid "(*optional)"
193
  msgstr ""
194
 
195
+ #: inc/class-ocdi-main.php:160
196
  msgid "Choose a DAT file for customizer import:"
197
  msgstr ""
198
 
199
+ #: inc/class-ocdi-main.php:166
200
  msgid "Choose which demo you want to import:"
201
  msgstr ""
202
 
203
+ #: inc/class-ocdi-main.php:188
204
  msgid "Import preview:"
205
  msgstr ""
206
 
207
+ #: inc/class-ocdi-main.php:192 inc/class-ocdi-main.php:243
208
  msgid "No preview image defined for this import."
209
  msgstr ""
210
 
211
+ #: inc/class-ocdi-main.php:216
212
  msgid "Importing, please wait!"
213
  msgstr ""
214
 
215
+ #: inc/class-ocdi-main.php:300
216
  msgid "Manually uploaded files"
217
  msgstr ""
218
 
219
+ #: inc/class-ocdi-main.php:317 inc/class-ocdi-main.php:328
220
  msgid "Downloaded files"
221
  msgstr ""
222
 
223
+ #: inc/class-ocdi-main.php:324
224
  msgid "The import files for: %s were successfully downloaded!"
225
  msgstr ""
226
 
227
+ #: inc/class-ocdi-main.php:334
228
  msgid "No import files specified!"
229
  msgstr ""
230
 
231
+ #: inc/class-ocdi-main.php:381
232
  msgid ""
233
  "%1$s%3$sThat's it, all done!%4$s%2$sThe demo import has finished. Please "
234
  "check your page and make sure that everything has imported correctly. If it "
236
  "it has done its job.%5$s"
237
  msgstr ""
238
 
239
+ #: inc/class-ocdi-main.php:392
240
  msgid ""
241
  "%1$sThe demo import has finished, but there were some import "
242
  "errors.%2$sMore details about the errors can be found in this %3$s%5$slog "
243
  "file%6$s%4$s%7$s"
244
  msgstr ""
245
 
246
+ #: inc/class-ocdi-main.php:446
247
+ msgid "Max execution time after content import = "
248
+ msgstr ""
249
+
250
+ #: inc/class-ocdi-main.php:448
251
  msgid "Importing content"
252
  msgstr ""
253
 
254
+ #: inc/class-ocdi-main.php:487 inc/class-ocdi-main.php:499
255
  msgid "Importing widgets"
256
  msgstr ""
257
 
258
+ #: inc/class-ocdi-main.php:521 inc/class-ocdi-main.php:529
259
  msgid "Importing customizer settings"
260
  msgstr ""
261
 
262
+ #: inc/class-ocdi-main.php:527
263
  msgid "Customizer settings import finished!"
264
  msgstr ""
265
 
266
+ #: inc/class-ocdi-main.php:579
267
  msgid "Completed AJAX call number: "
268
  msgstr ""
269
 
270
+ #: inc/class-ocdi-widget-importer.php:44
271
+ msgid "Widget import file could not be found."
272
+ msgstr ""
273
+
274
+ #: inc/class-ocdi-widget-importer.php:76
275
+ msgid "Widget import data could not be read. Please try a different file."
276
+ msgstr ""
277
+
278
+ #: inc/class-ocdi-widget-importer.php:116
279
+ msgid "Sidebar does not exist in theme (moving widget to Inactive)"
280
+ msgstr ""
281
+
282
+ #: inc/class-ocdi-widget-importer.php:138
283
+ msgid "Site does not support widget"
284
+ msgstr ""
285
+
286
+ #: inc/class-ocdi-widget-importer.php:173
287
+ msgid "Widget already exists"
288
+ msgstr ""
289
+
290
+ #: inc/class-ocdi-widget-importer.php:232
291
+ msgid "Imported"
292
+ msgstr ""
293
+
294
+ #: inc/class-ocdi-widget-importer.php:236
295
+ msgid "Imported to Inactive"
296
+ msgstr ""
297
+
298
+ #: inc/class-ocdi-widget-importer.php:242
299
+ msgid "No Title"
300
+ msgstr ""
301
+
302
+ #: inc/class-ocdi-widget-importer.php:291
303
+ msgid "No results for widget import!"
304
+ msgstr ""
305
+
306
+ #: one-click-demo-import.php:29
307
+ msgid ""
308
+ "The %2$sOne Click Demo Import%3$s plugin requires %2$sPHP 5.3.2+%3$s to run "
309
+ "properly. Please contact your hosting company and ask them to update the "
310
+ "PHP version of your site to at least PHP 5.3.2.%4$s Your current version of "
311
+ "PHP: %2$s%1$s%3$s"
312
+ msgstr ""
313
+
314
  #. Plugin URI of the plugin/theme
315
  msgid "https://wordpress.org/plugins/one-click-demo-import/"
316
  msgstr ""
one-click-demo-import.php CHANGED
@@ -4,7 +4,7 @@
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.3
8
  Author: ProteusThemes
9
  Author URI: http://www.proteusthemes.com
10
  License: GPL3
@@ -15,662 +15,35 @@ Text Domain: pt-ocdi
15
  // Block direct access to the main plugin file.
16
  defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
17
 
18
- // Path/URL to root of this plugin, with trailing slash.
19
- 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.1.3' );
24
-
25
- // Include files.
26
- require PT_OCDI_PATH . 'inc/class-ocdi-helpers.php';
27
- require PT_OCDI_PATH . 'inc/class-ocdi-importer.php';
28
- require PT_OCDI_PATH . 'inc/class-ocdi-widget-importer.php';
29
- require PT_OCDI_PATH . 'inc/class-ocdi-customizer-importer.php';
30
- require PT_OCDI_PATH . 'inc/class-ocdi-logger.php';
31
-
32
  /**
33
- * One Click Demo Import class, so we don't have to worry about namespaces.
 
34
  */
35
- class PT_One_Click_Demo_Import {
36
-
37
- /**
38
- * @var $instance the reference to *Singleton* instance of this class
39
- */
40
- private static $instance;
41
-
42
- /**
43
- * Private variables used throughout the plugin.
44
- */
45
- private $importer, $plugin_page, $import_files, $logger, $log_file_path, $selected_index, $selected_import_files, $microtime, $frontend_error_messages, $ajax_call_number;
46
-
47
-
48
- /**
49
- * Returns the *Singleton* instance of this class.
50
- *
51
- * @return PT_One_Click_Demo_Import the *Singleton* instance.
52
- */
53
- public static function getInstance() {
54
- if ( null === static::$instance ) {
55
- static::$instance = new static();
56
- }
57
-
58
- return static::$instance;
59
- }
60
-
61
 
62
  /**
63
- * Class construct function, to initiate the plugin.
64
- * Protected constructor to prevent creating a new instance of the
65
- * *Singleton* via the `new` operator from outside of this class.
66
  */
67
- protected function __construct() {
 
68
 
69
- // Actions.
70
- add_action( 'admin_menu', array( $this, 'create_plugin_page' ) );
71
- add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
72
- add_action( 'wp_ajax_ocdi_import_demo_data', array( $this, 'import_demo_data_ajax_callback' ) );
73
- add_action( 'after_setup_theme', array( $this, 'setup_plugin_with_filter_data' ) );
74
- add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) );
75
  }
 
 
 
76
 
 
 
77
 
78
- /**
79
- * Private clone method to prevent cloning of the instance of the *Singleton* instance.
80
- *
81
- * @return void
82
- */
83
- private function __clone() {}
84
-
85
-
86
- /**
87
- * Private unserialize method to prevent unserializing of the *Singleton* instance.
88
- *
89
- * @return void
90
- */
91
- private function __wakeup() {}
92
-
93
-
94
- /**
95
- * Creates the plugin page and a submenu item in WP Appearance menu.
96
- */
97
- public function create_plugin_page() {
98
- $plugin_page_setup = apply_filters( 'pt-ocdi/plugin_page_setup', array(
99
- 'parent_slug' => 'themes.php',
100
- 'page_title' => esc_html__( 'One Click Demo Import' , 'pt-ocdi' ),
101
- 'menu_title' => esc_html__( 'Import Demo Data' , 'pt-ocdi' ),
102
- 'capability' => 'import',
103
- 'menu_slug' => 'pt-one-click-demo-import',
104
- )
105
- );
106
-
107
- $this->plugin_page = add_submenu_page( $plugin_page_setup['parent_slug'], $plugin_page_setup['page_title'], $plugin_page_setup['menu_title'], $plugin_page_setup['capability'], $plugin_page_setup['menu_slug'], array( $this, 'display_plugin_page' ) );
108
- }
109
-
110
-
111
- /**
112
- * Plugin page display.
113
- */
114
- public function display_plugin_page() {
115
- ?>
116
-
117
- <div class="ocdi wrap">
118
- <h2 class="ocdi__title"><span class="dashicons dashicons-download"></span><?php esc_html_e( 'One Click Demo Import', 'pt-ocdi' ); ?></h2>
119
-
120
- <?php
121
-
122
- // Display warrning if PHP safe mode is enabled, since we wont be able to change the max_execution_time.
123
- if ( ini_get( 'safe_mode' ) ) {
124
- printf(
125
- esc_html__( '%sWarning: your server is using %sPHP safe mode%s. This means that you might experience server timeout errors.%s', 'pt-ocdi' ),
126
- '<div class="notice notice-warning"><p>',
127
- '<strong>',
128
- '</strong>',
129
- '</p></div>'
130
- );
131
- }
132
-
133
- // Start output buffer for displaying the plugin intro text.
134
- ob_start();
135
- ?>
136
-
137
- <div class="ocdi__intro-text">
138
- <p>
139
- <?php esc_html_e( 'Importing demo data (post, pages, images, theme settings, ...) is the easiest way to setup your theme. It will allow you to quickly edit everything instead of creating content from scratch. When you import the data, the following things might happen:', 'pt-ocdi' ); ?>
140
- </p>
141
-
142
- <ul>
143
- <li><?php esc_html_e( 'No existing posts, pages, categories, images, custom post types or any other data will be deleted or modified.', 'pt-ocdi' ); ?></li>
144
- <li><?php esc_html_e( 'Posts, pages, images, widgets and menus will get imported.', 'pt-ocdi' ); ?></li>
145
- <li><?php esc_html_e( 'Please click "Import Demo Data" button only once and wait, it can take a couple of minutes.', 'pt-ocdi' ); ?></li>
146
- </ul>
147
- </div>
148
-
149
- <div class="ocdi__intro-text">
150
- <p><?php esc_html_e( 'Before you begin, make sure all the required plugins are activated.', 'pt-ocdi' ); ?></p>
151
- </div>
152
-
153
- <?php
154
- $plugin_intro_text = ob_get_clean();
155
-
156
- // Display the plugin intro text (can be replaced with custom text through the filter below).
157
- echo wp_kses_post( apply_filters( 'pt-ocdi/plugin_intro_text', $plugin_intro_text ) );
158
- ?>
159
-
160
-
161
- <?php if ( empty( $this->import_files ) ) : ?>
162
- <div class="notice notice-info below-h2">
163
- <p>
164
- <?php esc_html_e( 'There are no predefined import files available in this theme. Please upload the import files manually!', 'pt-ocdi' ); ?>
165
- </p>
166
- </div>
167
- <div>
168
- <div class="ocdi__single-file-upload-container">
169
- <h3><label for="content-file-upload"><?php esc_html_e( 'Choose a XML file for content import:', 'pt-ocdi' ); ?></label></h3>
170
- <input id="ocdi__content-file-upload" type="file" name="content-file-upload">
171
- </div>
172
- <div class="ocdi__single-file-upload-container">
173
- <h3><label for="widget-file-upload"><?php esc_html_e( 'Choose a WIE or JSON file for widget import:', 'pt-ocdi' ); ?></label> <span><?php esc_html_e( '(*optional)', 'pt-ocdi' ); ?></span></h3>
174
- <input id="ocdi__widget-file-upload" type="file" name="widget-file-upload">
175
- </div>
176
- <div class="ocdi__single-file-upload-container">
177
- <h3><label for="customizer-file-upload"><?php esc_html_e( 'Choose a DAT file for customizer import:', 'pt-ocdi' ); ?></label> <span><?php esc_html_e( '(*optional)', 'pt-ocdi' ); ?></span></h3>
178
- <input id="ocdi__customizer-file-upload" type="file" name="customizer-file-upload">
179
- </div>
180
- </div>
181
- <?php elseif ( 1 < count( $this->import_files ) ) : ?>
182
- <div class="ocdi__multi-select-import">
183
- <h3><?php esc_html_e( 'Choose which demo you want to import:', 'pt-ocdi' ); ?></h3>
184
- <select id="ocdi__demo-import-files">
185
- <?php foreach ( $this->import_files as $index => $import_file ) : ?>
186
- <option value="<?php echo esc_attr( $index ); ?>">
187
- <?php echo esc_html( $import_file['import_file_name'] ); ?>
188
- </option>
189
- <?php endforeach; ?>
190
- </select>
191
-
192
- <?php
193
- // Check if at least one preview image is defined, so we can prepare the structure for display.
194
- $preview_image_is_defined = false;
195
- foreach ( $this->import_files as $import_file ) {
196
- if ( isset( $import_file['import_preview_image_url'] ) ) {
197
- $preview_image_is_defined = true;
198
- break;
199
- }
200
- }
201
-
202
- if ( $preview_image_is_defined ) :
203
- ?>
204
- <div>
205
- <p><?php esc_html_e( 'Import preview:', 'pt-ocdi' ); ?></p>
206
- <p class="ocdi__demo-import-preview-image-message js-ocdi-preview-image-message">
207
- <?php
208
- if ( ! isset( $this->import_files[0]['import_preview_image_url'] ) ) {
209
- esc_html_e( 'No preview image defined for this import.', 'pt-ocdi' );
210
- }
211
- // Leave the img tag below and the p tag above available for later changes via JS.
212
- ?>
213
- </p>
214
- <img id="ocdi__demo-import-preview-image" class="js-ocdi-preview-image" src="<?php echo ! empty( $this->import_files[0]['import_preview_image_url'] ) ? esc_url( $this->import_files[0]['import_preview_image_url'] ) : ''; ?>">
215
- </div>
216
- <?php endif; ?>
217
- </div>
218
- <?php endif; ?>
219
-
220
- <div class="ocdi__demo-import-notice js-ocdi-demo-import-notice">
221
- <?php
222
- if ( is_array( $this->import_files ) && ! empty( $this->import_files[0]['import_notice'] ) ) {
223
- echo wp_kses_post( $this->import_files[0]['import_notice'] );
224
- }
225
- ?>
226
- </div>
227
-
228
- <p>
229
- <button class="ocdi__button button-primary js-ocdi-import-data"><?php esc_html_e( 'Import Demo Data', 'pt-ocdi' ); ?></button>
230
- </p>
231
-
232
- <p class="ocdi__ajax-loader js-ocdi-ajax-loader">
233
- <span class="spinner"></span> <?php esc_html_e( 'Importing, please wait!', 'pt-ocdi' ); ?>
234
- </p>
235
-
236
- <div class="ocdi__response js-ocdi-ajax-response"></div>
237
- </div>
238
-
239
- <?php
240
- }
241
-
242
-
243
- /**
244
- * Enqueue admin scripts (JS and CSS)
245
- *
246
- * @param string $hook holds info on which admin page you are currently loading.
247
- */
248
- public function admin_enqueue_scripts( $hook ) {
249
-
250
- // Enqueue the scripts only on the plugin page.
251
- if ( $this->plugin_page === $hook ) {
252
- wp_enqueue_script( 'ocdi-main-js', PT_OCDI_URL . 'assets/js/main.js' , array( 'jquery', 'jquery-form' ), PT_OCDI_VERSION );
253
-
254
- wp_localize_script( 'ocdi-main-js', 'ocdi',
255
- array(
256
- 'ajax_url' => admin_url( 'admin-ajax.php' ),
257
- 'ajax_nonce' => wp_create_nonce( 'ocdi-ajax-verification' ),
258
- 'import_files' => $this->import_files,
259
- 'texts' => array(
260
- 'missing_preview_image' => esc_html__( 'No preview image defined for this import.', 'pt-ocdi' ),
261
- ),
262
- )
263
- );
264
-
265
- wp_enqueue_style( 'ocdi-main-css', PT_OCDI_URL . 'assets/css/main.css', array() , PT_OCDI_VERSION );
266
- }
267
- }
268
-
269
-
270
- /**
271
- * Main AJAX callback function for:
272
- * 1. prepare import files (uploaded or predefined via filters)
273
- * 2. import content
274
- * 3. before widgets import setup (optional)
275
- * 4. import widgets (optional)
276
- * 5. import customizer options (optional)
277
- * 6. after import setup (optional)
278
- */
279
- public function import_demo_data_ajax_callback() {
280
-
281
- // Try to update PHP memory limit (so that it does not run out of it).
282
- ini_set( 'memory_limit', apply_filters( 'pt-ocdi/import_memory_limit', '350M' ) );
283
-
284
- // Verify if the AJAX call is valid (checks nonce and current_user_can).
285
- OCDI_Helpers::verify_ajax_call();
286
-
287
- // Is this a new AJAX call to continue the previous import?
288
- $use_existing_importer_data = $this->get_importer_data();
289
-
290
- if ( ! $use_existing_importer_data ) {
291
-
292
- // Set the AJAX call number.
293
- $this->ajax_call_number = empty( $this->ajax_call_number ) ? 0 : $this->ajax_call_number;
294
-
295
- // Error messages displayed on front page.
296
- $this->frontend_error_messages = '';
297
-
298
- // Create a date and time string to use for demo and log file names.
299
- $demo_import_start_time = date( apply_filters( 'pt-ocdi/date_format_for_file_names', 'Y-m-d__H-i-s' ) );
300
-
301
- // Define log file path.
302
- $this->log_file_path = OCDI_Helpers::get_log_path( $demo_import_start_time );
303
-
304
- // Get selected file index or set it to 0.
305
- $this->selected_index = empty( $_POST['selected'] ) ? 0 : absint( $_POST['selected'] );
306
-
307
- /**
308
- * 1. Prepare import files.
309
- * Manually uploaded import files or predefined import files via filter: pt-ocdi/import_files
310
- */
311
- if ( ! empty( $_FILES ) ) { // Using manual file uploads?
312
-
313
- // Get paths for the uploaded files.
314
- $this->selected_import_files = OCDI_Helpers::process_uploaded_files( $_FILES, $this->log_file_path );
315
-
316
- // Set the name of the import files, because we used the uploaded files.
317
- $this->import_files[ $this->selected_index ]['import_file_name'] = esc_html__( 'Manually uploaded files', 'pt-ocdi' );
318
- }
319
- elseif ( ! empty( $this->import_files[ $this->selected_index ] ) ) { // Use predefined import files from wp filter: pt-ocdi/import_files.
320
-
321
- // Download the import files (content and widgets files) and save it to variable for later use.
322
- $this->selected_import_files = OCDI_Helpers::download_import_files(
323
- $this->import_files[ $this->selected_index ],
324
- $demo_import_start_time
325
- );
326
-
327
- // Check Errors.
328
- if ( is_wp_error( $this->selected_import_files ) ) {
329
-
330
- // Write error to log file and send an AJAX response with the error.
331
- OCDI_Helpers::log_error_and_send_ajax_response(
332
- $this->selected_import_files->get_error_message(),
333
- $this->log_file_path,
334
- esc_html__( 'Downloaded files', 'pt-ocdi' )
335
- );
336
- }
337
-
338
- // Add this message to log file.
339
- $log_added = OCDI_Helpers::append_to_file(
340
- sprintf(
341
- __( 'The import files for: %s were successfully downloaded!', 'pt-ocdi' ),
342
- $this->import_files[ $this->selected_index ]['import_file_name']
343
- ) . OCDI_Helpers::import_file_info( $this->selected_import_files ),
344
- $this->log_file_path,
345
- esc_html__( 'Downloaded files' , 'pt-ocdi' )
346
- );
347
- }
348
- else {
349
-
350
- // Send JSON Error response to the AJAX call.
351
- wp_send_json( esc_html__( 'No import files specified!', 'pt-ocdi' ) );
352
- }
353
- }
354
-
355
- /**
356
- * 2. Import content.
357
- * Returns any errors greater then the "error" logger level, that will be displayed on front page.
358
- */
359
- $this->frontend_error_messages .= $this->import_content( $this->selected_import_files['content'] );
360
-
361
- /**
362
- * 3. Before widgets import setup.
363
- */
364
- $action = 'pt-ocdi/before_widgets_import';
365
- if ( ( false !== has_action( $action ) ) && empty( $this->frontend_error_messages ) ) {
366
-
367
- // Run the before_widgets_import action to setup other settings.
368
- $this->do_import_action( $action, $this->import_files[ $this->selected_index ] );
369
- }
370
-
371
- /**
372
- * 4. Import widgets.
373
- */
374
- if ( ! empty( $this->selected_import_files['widgets'] ) && empty( $this->frontend_error_messages ) ) {
375
- $this->import_widgets( $this->selected_import_files['widgets'] );
376
- }
377
-
378
- /**
379
- * 5. Import customize options.
380
- */
381
- if ( ! empty( $this->selected_import_files['customizer'] ) && empty( $this->frontend_error_messages ) ) {
382
- $this->import_customizer( $this->selected_import_files['customizer'] );
383
- }
384
-
385
- /**
386
- * 6. After import setup.
387
- */
388
- $action = 'pt-ocdi/after_import';
389
- if ( ( false !== has_action( $action ) ) && empty( $this->frontend_error_messages ) ) {
390
-
391
- // Run the after_import action to setup other settings.
392
- $this->do_import_action( $action, $this->import_files[ $this->selected_index ] );
393
- }
394
-
395
- // Display final messages (success or error messages).
396
- if ( empty( $this->frontend_error_messages ) ) {
397
- $response['message'] = sprintf(
398
- __( '%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' ),
399
- '<div class="notice notice-success"><p>',
400
- '<br>',
401
- '<strong>',
402
- '</strong>',
403
- '</p></div>'
404
- );
405
- }
406
- else {
407
- $response['message'] = $this->frontend_error_messages . '<br>';
408
- $response['message'] .= sprintf(
409
- __( '%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' ),
410
- '<div class="notice notice-error"><p>',
411
- '<br>',
412
- '<strong>',
413
- '</strong>',
414
- '<a href="' . OCDI_Helpers::get_log_url( $this->log_file_path ) .'" target="_blank">',
415
- '</a>',
416
- '</p></div>'
417
- );
418
- }
419
-
420
- wp_send_json( $response );
421
- }
422
-
423
-
424
- /**
425
- * Import content from an WP XML file.
426
- *
427
- * @param string $import_file_path path to the import file.
428
- */
429
- private function import_content( $import_file_path ) {
430
-
431
- $this->microtime = microtime( true );
432
-
433
- // This should be replaced with multiple AJAX calls (import in smaller chunks)
434
- // so that it would not come to the Internal Error, because of the PHP script timeout.
435
- // Also this function has no effect when PHP is running in safe mode
436
- // http://php.net/manual/en/function.set-time-limit.php.
437
- // Increase PHP max execution time.
438
- set_time_limit( apply_filters( 'pt-ocdi/set_time_limit_for_demo_data_import', 300 ) );
439
-
440
- // Disable import of authors.
441
- add_filter( 'wxr_importer.pre_process.user', '__return_false' );
442
-
443
- // Check, if we need to send another AJAX request.
444
- add_filter( 'wxr_importer.pre_process.post', array( $this, 'new_ajax_request_maybe' ) );
445
-
446
- // Disables generation of multiple image sizes (thumbnails) in the content import step.
447
- if ( ! apply_filters( 'pt-ocdi/regenerate_thumbnails_in_content_import', true ) ) {
448
- add_filter( 'intermediate_image_sizes_advanced',
449
- function() {
450
- return null;
451
- }
452
- );
453
- }
454
-
455
- // Import content.
456
- if ( ! empty( $import_file_path ) ) {
457
- ob_start();
458
- $this->importer->import( $import_file_path );
459
- $message = ob_get_clean();
460
-
461
- // Add this message to log file.
462
- $log_added = OCDI_Helpers::append_to_file(
463
- $message . PHP_EOL . 'MAX EXECUTION TIME = ' . ini_get( 'max_execution_time' ),
464
- $this->log_file_path,
465
- esc_html__( 'Importing content' , 'pt-ocdi' )
466
- );
467
- }
468
-
469
- // Delete content importer data for current import from DB.
470
- delete_transient( 'ocdi_importer_data' );
471
-
472
- // Return any error messages for the front page output (errors, critical, alert and emergency level messages only).
473
- return $this->logger->error_output;
474
- }
475
-
476
-
477
- /**
478
- * Import widgets from WIE or JSON file.
479
- *
480
- * @param string $widget_import_file_path path to the widget import file.
481
- */
482
- private function import_widgets( $widget_import_file_path ) {
483
-
484
- // Widget import results.
485
- $results = array();
486
-
487
- // Create an instance of the Widget Importer.
488
- $widget_importer = new OCDI_Widget_Importer();
489
-
490
- // Import widgets.
491
- if ( ! empty( $widget_import_file_path ) ) {
492
-
493
- // Import widgets and return result.
494
- $results = $widget_importer->import_widgets( $widget_import_file_path );
495
- }
496
-
497
- // Check for errors.
498
- if ( is_wp_error( $results ) ) {
499
-
500
- // Write error to log file and send an AJAX response with the error.
501
- OCDI_Helpers::log_error_and_send_ajax_response(
502
- $results->get_error_message(),
503
- $this->log_file_path,
504
- esc_html__( 'Importing widgets', 'pt-ocdi' )
505
- );
506
- }
507
-
508
- ob_start();
509
- $widget_importer->format_results_for_log( $results );
510
- $message = ob_get_clean();
511
-
512
- // Add this message to log file.
513
- $log_added = OCDI_Helpers::append_to_file(
514
- $message,
515
- $this->log_file_path,
516
- esc_html__( 'Importing widgets' , 'pt-ocdi' )
517
- );
518
- }
519
-
520
-
521
- /**
522
- * Import customizer from a DAT file, generated by the Customizer Export/Import plugin.
523
- *
524
- * @param string $customizer_import_file_path path to the customizer import file.
525
- */
526
- private function import_customizer( $customizer_import_file_path ) {
527
-
528
- // Try to import the customizer settings.
529
- $results = OCDI_Customizer_Importer::import_customizer_options( $customizer_import_file_path );
530
-
531
- // Check for errors.
532
- if ( is_wp_error( $results ) ) {
533
-
534
- // Write error to log file and send an AJAX response with the error.
535
- OCDI_Helpers::log_error_and_send_ajax_response(
536
- $results->get_error_message(),
537
- $this->log_file_path,
538
- esc_html__( 'Importing customizer settings', 'pt-ocdi' )
539
- );
540
- }
541
-
542
- // Add this message to log file.
543
- $log_added = OCDI_Helpers::append_to_file(
544
- esc_html__( 'Customizer settings import finished!', 'pt-ocdi' ),
545
- $this->log_file_path,
546
- esc_html__( 'Importing customizer settings' , 'pt-ocdi' )
547
- );
548
- }
549
-
550
-
551
- /**
552
- * Setup other things in the passed wp action.
553
- *
554
- * @param string $action the action name to be executed.
555
- * @param array $selected_import with information about the selected import.
556
- */
557
- private function do_import_action( $action, $selected_import ) {
558
-
559
- ob_start();
560
- do_action( $action, $selected_import );
561
- $message = ob_get_clean();
562
-
563
- // Add this message to log file.
564
- $log_added = OCDI_Helpers::append_to_file(
565
- $message,
566
- $this->log_file_path,
567
- $action
568
- );
569
- }
570
-
571
-
572
- /**
573
- * Check if we need to create a new AJAX request, so that server does not timeout.
574
- *
575
- * @param array $data current post data.
576
- * @return array
577
- */
578
- public function new_ajax_request_maybe( $data ) {
579
- $time = microtime( true ) - $this->microtime;
580
-
581
- // We should make a new ajax call, if the time is right.
582
- if ( $time > apply_filters( 'pt-ocdi/time_for_one_ajax_call', 25 ) ) {
583
- $this->ajax_call_number++;
584
- $this->set_importer_data();
585
-
586
- $response = array(
587
- 'status' => 'newAJAX',
588
- 'message' => 'Time for new AJAX request!: ' . $time,
589
- );
590
-
591
- // Add any output to the log file and clear the buffers.
592
- $message = ob_get_clean();
593
-
594
- // Add message to log file.
595
- $log_added = OCDI_Helpers::append_to_file(
596
- __( 'Completed AJAX call number: ' , 'pt-ocdi' ) . $this->ajax_call_number . PHP_EOL . $message,
597
- $this->log_file_path,
598
- ''
599
- );
600
-
601
- wp_send_json( $response );
602
- }
603
-
604
- return $data;
605
- }
606
-
607
- /**
608
- * Set current state of the content importer, so we can continue the import with new AJAX request.
609
- */
610
- private function set_importer_data() {
611
- $data = array(
612
- 'frontend_error_messages' => $this->frontend_error_messages,
613
- 'ajax_call_number' => $this->ajax_call_number,
614
- 'log_file_path' => $this->log_file_path,
615
- 'selected_index' => $this->selected_index,
616
- 'selected_import_files' => $this->selected_import_files,
617
- );
618
-
619
- $data = array_merge( $data, $this->importer->get_importer_data() );
620
-
621
- set_transient( 'ocdi_importer_data', $data, 0.5 * HOUR_IN_SECONDS );
622
- }
623
-
624
- /**
625
- * Get content importer data, so we can continue the import with this new AJAX request.
626
- */
627
- private function get_importer_data() {
628
- if ( $data = get_transient( 'ocdi_importer_data' ) ) {
629
- $this->frontend_error_messages = empty( $data['frontend_error_messages'] ) ? '' : $data['frontend_error_messages'];
630
- $this->ajax_call_number = empty( $data['ajax_call_number'] ) ? 1 : $data['ajax_call_number'];
631
- $this->log_file_path = empty( $data['log_file_path'] ) ? '' : $data['log_file_path'];
632
- $this->selected_index = empty( $data['selected_index'] ) ? 0 : $data['selected_index'];
633
- $this->selected_import_files = empty( $data['selected_import_files'] ) ? array() : $data['selected_import_files'];
634
- $this->importer->set_importer_data( $data );
635
-
636
- return true;
637
- }
638
- return false;
639
- }
640
-
641
- /**
642
- * Load the plugin textdomain, so that translations can be made.
643
- */
644
- public function load_textdomain() {
645
- load_plugin_textdomain( 'pt-ocdi', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' );
646
- }
647
-
648
-
649
- /**
650
- * Get data from filters, after the theme has loaded and instantiate the importer.
651
- */
652
- public function setup_plugin_with_filter_data() {
653
-
654
- // Get info of import data files and filter it.
655
- $this->import_files = OCDI_Helpers::validate_import_file_info( apply_filters( 'pt-ocdi/import_files', array() ) );
656
-
657
- // Importer options array.
658
- $importer_options = apply_filters( 'pt-ocdi/importer_options', array(
659
- 'fetch_attachments' => true,
660
- ) );
661
-
662
- // Logger options for the logger used in the importer.
663
- $logger_options = apply_filters( 'pt-ocdi/logger_options', array(
664
- 'logger_min_level' => 'warning',
665
- ) );
666
 
667
- // Configure logger instance and set it to the importer.
668
- $this->logger = new OCDI_Logger();
669
- $this->logger->min_level = $logger_options['logger_min_level'];
670
 
671
- // Create importer instance with proper parameters.
672
- $this->importer = new OCDI_Importer( $importer_options, $this->logger );
673
- }
674
  }
675
-
676
- $pt_one_click_demo_import = PT_One_Click_Demo_Import::getInstance();
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.2.0
8
  Author: ProteusThemes
9
  Author URI: http://www.proteusthemes.com
10
  License: GPL3
15
  // Block direct access to the main plugin file.
16
  defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  /**
19
+ * Display admin error message if PHP version is older than 5.3.2.
20
+ * Otherwise execute the main plugin class.
21
  */
22
+ if ( version_compare( phpversion(), '5.3.2', '<' ) ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
 
24
  /**
25
+ * Display an admin error notice when PHP is older the version 5.3.2.
26
+ * Hook it to the 'admin_notices' action.
 
27
  */
28
+ function ocdi_old_php_admin_error_notice() {
29
+ $message = sprintf( esc_html__( 'The %2$sOne Click Demo Import%3$s plugin requires %2$sPHP 5.3.2+%3$s to run properly. Please contact your hosting company and ask them to update the PHP version of your site to at least PHP 5.3.2.%4$s Your current version of PHP: %2$s%1$s%3$s', 'pt-ocdi' ), phpversion(), '<strong>', '</strong>', '<br>' );
30
 
31
+ printf( '<div class="notice notice-error"><p>%1$s</p></div>', wp_kses_post( $message ) );
 
 
 
 
 
32
  }
33
+ add_action( 'admin_notices', 'ocdi_old_php_admin_error_notice' );
34
+ }
35
+ else {
36
 
37
+ // Current version of the plugin.
38
+ define( 'PT_OCDI_VERSION', '1.2.0' );
39
 
40
+ // Path/URL to root of this plugin, with trailing slash.
41
+ define( 'PT_OCDI_PATH', plugin_dir_path( __FILE__ ) );
42
+ define( 'PT_OCDI_URL', plugin_dir_url( __FILE__ ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
 
44
+ // Require main plugin file.
45
+ require PT_OCDI_PATH . 'inc/class-ocdi-main.php';
 
46
 
47
+ // Instantiate the main plugin class *Singleton*.
48
+ $pt_one_click_demo_import = PT_One_Click_Demo_Import::getInstance();
 
49
  }
 
 
readme.txt CHANGED
@@ -3,28 +3,28 @@ 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.1.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.
10
 
11
  == Description ==
12
 
13
- This plugin will create a submenu page under Appearance with the title **Import demo data**.
14
 
15
- If the theme you are using does not have any predefined import files, then you will be presented with three file upload inputs. First one is required and you will have to upload a demo content XML file, for the actual demo import. The second one is optional and will ask you for a WIE or JSON file for widgets import. You create that file using the [Widget Importer & Exporter](https://wordpress.org/plugins/widget-importer-exporter/) plugin. The third one is also optional and will import the customizer settings, select the DAT file which you can generate from [Customizer Export/Import](https://wordpress.org/plugins/customizer-export-import/) plugin (the customizer settings will be imported only if the export file was created from the same theme).
16
 
17
- This plugin is using the improved WP import that you can find here: https://github.com/humanmade/WordPress-Importer.
18
 
19
- The best feature of this plugin is, that theme authors can define import files in their themes and so all you (the user of the theme) have to do is click on the "Import Demo Data" button.
20
 
21
- **How do theme author define these files?** The answer is in the FAQ section.
22
 
23
  All progress of this plugin's work is logged in a log file in the default WP upload directory, together with the demo content and widgets import files used in the importing process.
24
 
25
  NOTE: This plugin is still a work in progress!
26
 
27
- NOTE: There is no setting to "connect" authors from the demo import file to the existing users in your WP site (like there is in the original WP Importer plugin).
28
 
29
  **Do you want to contribute?**
30
 
@@ -32,9 +32,19 @@ Please refer to the official [GitHub repository](https://github.com/proteustheme
32
 
33
  == Installation ==
34
 
35
- Upload the One Click Demo Import plugin to your WordPress site, Activate it, and that's it.
36
 
37
- Once the plugin is activated you will find the actual import setting page under *Appearance -> Import Demo Data*.
 
 
 
 
 
 
 
 
 
 
38
 
39
  == Frequently Asked Questions ==
40
 
@@ -46,6 +56,8 @@ You will find the import page in *wp-admin -> Appearance -> Import Demo Data*.
46
 
47
  The files used in the demo import will be saved to the default WordPress uploads directory. An example of that directory would be: `../wp-content/uploads/2016/03/`.
48
 
 
 
49
  = How to predefine demo imports? =
50
 
51
  This question is for theme authors. To predefine demo imports, you just have to add the following code structure, with your own values to your theme (using the `pt-ocdi/import_files` filter):
@@ -58,7 +70,7 @@ function ocdi_import_files() {
58
  'import_file_url' => 'http://www.your_domain.com/ocdi/demo-content.xml',
59
  'import_widget_file_url' => 'http://www.your_domain.com/ocdi/widgets.json',
60
  'import_customizer_file_url' => 'http://www.your_domain.com/ocdi/customizer.dat',
61
- 'import_preview_image_url' => 'http://www.your_domain.com/ocdi/preview_import_image1.json',
62
  'import_notice' => __( 'After you import this demo, you will have to setup the slider separately.', 'your-textdomain' ),
63
  ),
64
  array(
@@ -66,7 +78,7 @@ function ocdi_import_files() {
66
  'import_file_url' => 'http://www.your_domain.com/ocdi/demo-content2.xml',
67
  'import_widget_file_url' => 'http://www.your_domain.com/ocdi/widgets2.json',
68
  'import_customizer_file_url' => 'http://www.your_domain.com/ocdi/customizer2.dat',
69
- 'import_preview_image_url' => 'http://www.your_domain.com/ocdi/preview_import_image2.json',
70
  'import_notice' => __( 'A special note for this import.', 'your-textdomain' ),
71
  ),
72
  );
@@ -76,6 +88,34 @@ add_filter( 'pt-ocdi/import_files', 'ocdi_import_files' );
76
 
77
  You can set content import, widgets, and customizer import files. You can also define a preview image, which will be used only when multiple demo imports are defined, so that the user will see the difference between imports.
78
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
  = How to handle different "after import setups" depending on which predefined import was selected? =
80
 
81
  This question might be asked by a theme author wanting to implement different after import setups for multiple predefined demo imports. Lets say we have predefined two demo imports with the following names: 'Demo Import 1' and 'Demo Import 2', the code for after import setup would be (using the `pt-ocdi/after_import` filter):
@@ -151,12 +191,18 @@ add_filter( 'pt-ocdi/plugin_page_setup', 'ocdi_plugin_page_setup' );
151
 
152
  = I can't activate the plugin, because of a fatal error, what can I do? =
153
 
 
 
154
  You want to activate the plugin, but this error shows up:
155
 
156
  *Plugin could not be activated because it triggered a fatal error*
157
 
158
  This happens, because your hosting server is using a very old version of PHP. This plugin requires PHP version of at least **5.3.x**, but we recommend version *5.6.x*. Please contact your hosting company and ask them to update the PHP version for your site.
159
 
 
 
 
 
160
  == Screenshots ==
161
 
162
  1. Example of multiple predefined demo imports, that a user can choose from.
@@ -165,6 +211,15 @@ This happens, because your hosting server is using a very old version of PHP. Th
165
 
166
  == Changelog ==
167
 
 
 
 
 
 
 
 
 
 
168
  = 1.1.3 =
169
 
170
  *Release Date - 17 June 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.2.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.
10
 
11
  == Description ==
12
 
13
+ The best feature of this plugin is, that theme authors can define import files in their themes and so all you (the user of the theme) have to do is click on the "Import Demo Data" button.
14
 
15
+ **How do theme author define these files?** The answer is in the FAQ section.
16
 
17
+ This plugin will create a submenu page under Appearance with the title **Import demo data**.
18
 
19
+ If the theme you are using does not have any predefined import files, then you will be presented with three file upload inputs. First one is required and you will have to upload a demo content XML file, for the actual demo import. The second one is optional and will ask you for a WIE or JSON file for widgets import. You create that file using the [Widget Importer & Exporter](https://wordpress.org/plugins/widget-importer-exporter/) plugin. The third one is also optional and will import the customizer settings, select the DAT file which you can generate from [Customizer Export/Import](https://wordpress.org/plugins/customizer-export-import/) plugin (the customizer settings will be imported only if the export file was created from the same theme).
20
 
21
+ This plugin is using the improved WP import 2.0 that is still in development and can be found here: https://github.com/humanmade/WordPress-Importer.
22
 
23
  All progress of this plugin's work is logged in a log file in the default WP upload directory, together with the demo content and widgets import files used in the importing process.
24
 
25
  NOTE: This plugin is still a work in progress!
26
 
27
+ NOTE: There is no setting to "connect" authors from the demo import file to the existing users in your WP site (like there is in the original WP Importer plugin). All demo content will be imported under the current user.
28
 
29
  **Do you want to contribute?**
30
 
32
 
33
  == Installation ==
34
 
35
+ **From your WordPress dashboard**
36
 
37
+ 1. Visit 'Plugins > Add New',
38
+ 2. Search for 'One Click Demo Import' and install the plugin,
39
+ 3. Activate 'One Click Demo Import' from your Plugins page.
40
+
41
+ **From WordPress.org**
42
+
43
+ 1. Download 'One Click Demo Import'.
44
+ 2. Upload the 'one-click-demo-import' directory to your '/wp-content/plugins/' directory, using your favorite method (ftp, sftp, scp, etc...)
45
+ 3. Activate 'One Click Demo Import' from your Plugins page.
46
+
47
+ **Once the plugin is activated you will find the actual import page in: Appearance -> Import Demo Data.**
48
 
49
  == Frequently Asked Questions ==
50
 
56
 
57
  The files used in the demo import will be saved to the default WordPress uploads directory. An example of that directory would be: `../wp-content/uploads/2016/03/`.
58
 
59
+ The log file will also be registered in the *wp-admin -> Media* section, so you can access it easily.
60
+
61
  = How to predefine demo imports? =
62
 
63
  This question is for theme authors. To predefine demo imports, you just have to add the following code structure, with your own values to your theme (using the `pt-ocdi/import_files` filter):
70
  'import_file_url' => 'http://www.your_domain.com/ocdi/demo-content.xml',
71
  'import_widget_file_url' => 'http://www.your_domain.com/ocdi/widgets.json',
72
  'import_customizer_file_url' => 'http://www.your_domain.com/ocdi/customizer.dat',
73
+ 'import_preview_image_url' => 'http://www.your_domain.com/ocdi/preview_import_image1.jpg',
74
  'import_notice' => __( 'After you import this demo, you will have to setup the slider separately.', 'your-textdomain' ),
75
  ),
76
  array(
78
  'import_file_url' => 'http://www.your_domain.com/ocdi/demo-content2.xml',
79
  'import_widget_file_url' => 'http://www.your_domain.com/ocdi/widgets2.json',
80
  'import_customizer_file_url' => 'http://www.your_domain.com/ocdi/customizer2.dat',
81
+ 'import_preview_image_url' => 'http://www.your_domain.com/ocdi/preview_import_image2.jpg',
82
  'import_notice' => __( 'A special note for this import.', 'your-textdomain' ),
83
  ),
84
  );
88
 
89
  You can set content import, widgets, and customizer import files. You can also define a preview image, which will be used only when multiple demo imports are defined, so that the user will see the difference between imports.
90
 
91
+ = What about using local import files (from theme folder)? =
92
+
93
+ You have to use the same filter as in above example, but with a slightly different array keys: `local_*`. The values have to be absolute paths (not URLs) to your import files. To use local import files, that reside in your theme folder, please use the below code. Note: make sure your import files are readable!
94
+
95
+ `
96
+ function ocdi_import_files() {
97
+ return array(
98
+ array(
99
+ 'import_file_name' => 'Demo Import 1',
100
+ 'local_import_file' => trailingslashit( get_template_directory() ) . 'ocdi/demo-content.xml',
101
+ 'local_import_widget_file' => trailingslashit( get_template_directory() ) . 'ocdi/widgets.json',
102
+ 'local_import_customizer_file' => trailingslashit( get_template_directory() ) . 'ocdi/customizer.dat',
103
+ 'import_preview_image_url' => 'http://www.your_domain.com/ocdi/preview_import_image1.jpg',
104
+ 'import_notice' => __( 'After you import this demo, you will have to setup the slider separately.', 'your-textdomain' ),
105
+ ),
106
+ array(
107
+ 'import_file_name' => 'Demo Import 2',
108
+ 'local_import_file' => trailingslashit( get_template_directory() ) . 'ocdi/demo-content2.xml',
109
+ 'local_import_widget_file' => trailingslashit( get_template_directory() ) . 'ocdi/widgets2.json',
110
+ 'local_import_customizer_file' => trailingslashit( get_template_directory() ) . 'ocdi/customizer2.dat',
111
+ 'import_preview_image_url' => 'http://www.your_domain.com/ocdi/preview_import_image2.jpg',
112
+ 'import_notice' => __( 'A special note for this import.', 'your-textdomain' ),
113
+ ),
114
+ );
115
+ }
116
+ add_filter( 'pt-ocdi/import_files', 'ocdi_import_files' );
117
+ `
118
+
119
  = How to handle different "after import setups" depending on which predefined import was selected? =
120
 
121
  This question might be asked by a theme author wanting to implement different after import setups for multiple predefined demo imports. Lets say we have predefined two demo imports with the following names: 'Demo Import 1' and 'Demo Import 2', the code for after import setup would be (using the `pt-ocdi/after_import` filter):
191
 
192
  = I can't activate the plugin, because of a fatal error, what can I do? =
193
 
194
+ *Update: since version 1.2.0, there is now a admin error notice, stating that the minimal PHP version required for this plugin is 5.3.2.*
195
+
196
  You want to activate the plugin, but this error shows up:
197
 
198
  *Plugin could not be activated because it triggered a fatal error*
199
 
200
  This happens, because your hosting server is using a very old version of PHP. This plugin requires PHP version of at least **5.3.x**, but we recommend version *5.6.x*. Please contact your hosting company and ask them to update the PHP version for your site.
201
 
202
+ = Issues with the import, that we can fix in the plugin =
203
+
204
+ Please visit this [docs page](https://github.com/proteusthemes/one-click-demo-import/blob/master/docs/import-problems.md), for more answers to issues with importing data.
205
+
206
  == Screenshots ==
207
 
208
  1. Example of multiple predefined demo imports, that a user can choose from.
211
 
212
  == Changelog ==
213
 
214
+ = 1.2.0 =
215
+
216
+ *Release Date - 9 July 2016*
217
+
218
+ * Now also accepts predefined local import files (from theme folder),
219
+ * Fixes PHP fatal error on plugin activation, for sites using PHP versions older then 5.3.2 (added admin error notice),
220
+ * Register log file in *wp-admin -> Media*, so that it's easier to access,
221
+ * No more "[WARNING] Could not find the author for ..." messages in the log file.
222
+
223
  = 1.1.3 =
224
 
225
  *Release Date - 17 June 2016*
vendor/humanmade/WordPress-Importer/class-wxr-importer.php CHANGED
@@ -1067,7 +1067,7 @@ class WXR_Importer extends WP_Importer {
1067
  if ( $this->options['aggressive_url_search'] ) {
1068
  // remap resized image URLs, works by stripping the extension and remapping the URL stub.
1069
  /*if ( preg_match( '!^image/!', $info['type'] ) ) {
1070
- $parts = pathinfo( $url );
1071
  $name = basename( $parts['basename'], ".{$parts['extension']}" ); // PATHINFO_FILENAME in PHP 5.2
1072
 
1073
  $parts_new = pathinfo( $upload['url'] );
1067
  if ( $this->options['aggressive_url_search'] ) {
1068
  // remap resized image URLs, works by stripping the extension and remapping the URL stub.
1069
  /*if ( preg_match( '!^image/!', $info['type'] ) ) {
1070
+ $parts = pathinfo( $remote_url );
1071
  $name = basename( $parts['basename'], ".{$parts['extension']}" ); // PATHINFO_FILENAME in PHP 5.2
1072
 
1073
  $parts_new = pathinfo( $upload['url'] );