Customizer Export/Import - Version 0.9

Version Description

Download this release

Release Info

Developer pross
Plugin Icon 128x128 Customizer Export/Import
Version 0.9
Comparing to
See all releases

Code changes from version 0.8 to 0.9

classes/class-cei-core.php CHANGED
@@ -27,12 +27,12 @@ final class CEI_Core {
27
  *
28
  * @since 0.1
29
  * @return void
30
- */
31
- static public function load_plugin_textdomain()
32
  {
33
  load_plugin_textdomain( 'customizer-export-import', false, basename( CEI_PLUGIN_DIR ) . '/lang/' );
34
  }
35
-
36
  /**
37
  * Check to see if we need to do an export or import.
38
  * This should be called by the customize_register action.
@@ -42,10 +42,10 @@ final class CEI_Core {
42
  * @param object $wp_customize An instance of WP_Customize_Manager.
43
  * @return void
44
  */
45
- static public function init( $wp_customize )
46
  {
47
  if ( current_user_can( 'edit_theme_options' ) ) {
48
-
49
  if ( isset( $_REQUEST['cei-export'] ) ) {
50
  self::_export( $wp_customize );
51
  }
@@ -54,50 +54,50 @@ final class CEI_Core {
54
  }
55
  }
56
  }
57
-
58
  /**
59
  * Prints scripts for the control.
60
  *
61
  * @since 0.1
62
  * @return void
63
  */
64
- static public function controls_print_scripts()
65
  {
66
  global $cei_error;
67
-
68
  if ( $cei_error ) {
69
  echo '<script> alert("' . $cei_error . '"); </script>';
70
  }
71
  }
72
-
73
  /**
74
  * Enqueues scripts for the control.
75
  *
76
  * @since 0.1
77
  * @return void
78
  */
79
- static public function controls_enqueue_scripts()
80
  {
81
  // Register
82
  wp_register_style( 'cei-css', CEI_PLUGIN_URL . '/css/customizer.css', array(), CEI_VERSION );
83
  wp_register_script( 'cei-js', CEI_PLUGIN_URL . '/js/customizer.js', array( 'jquery' ), CEI_VERSION, true );
84
-
85
  // Localize
86
  wp_localize_script( 'cei-js', 'CEIl10n', array(
87
  'emptyImport' => __( 'Please choose a file to import.', 'customizer-export-import' )
88
  ));
89
-
90
  // Config
91
  wp_localize_script( 'cei-js', 'CEIConfig', array(
92
  'customizerURL' => admin_url( 'customize.php' ),
93
  'exportNonce' => wp_create_nonce( 'cei-exporting' )
94
  ));
95
-
96
  // Enqueue
97
  wp_enqueue_style( 'cei-css' );
98
  wp_enqueue_script( 'cei-js' );
99
  }
100
-
101
  /**
102
  * Registers the control with the customizer.
103
  *
@@ -105,7 +105,7 @@ final class CEI_Core {
105
  * @param object $wp_customize An instance of WP_Customize_Manager.
106
  * @return void
107
  */
108
- static public function register( $wp_customize )
109
  {
110
  require_once CEI_PLUGIN_DIR . 'classes/class-cei-control.php';
111
 
@@ -114,24 +114,24 @@ final class CEI_Core {
114
  'title' => __( 'Export/Import', 'customizer-export-import' ),
115
  'priority' => 10000000
116
  ));
117
-
118
  // Add the export/import setting.
119
  $wp_customize->add_setting( 'cei-setting', array(
120
  'default' => '',
121
  'type' => 'none'
122
  ));
123
-
124
  // Add the export/import control.
125
- $wp_customize->add_control( new CEI_Control(
126
- $wp_customize,
127
- 'cei-setting',
128
  array(
129
  'section' => 'cei-section',
130
  'priority' => 1
131
  )
132
  ));
133
  }
134
-
135
  /**
136
  * Export customizer settings.
137
  *
@@ -141,12 +141,12 @@ final class CEI_Core {
141
  * @param object $wp_customize An instance of WP_Customize_Manager.
142
  * @return void
143
  */
144
- static private function _export( $wp_customize )
145
  {
146
  if ( ! wp_verify_nonce( $_REQUEST['cei-export'], 'cei-exporting' ) ) {
147
  return;
148
  }
149
-
150
  $theme = get_stylesheet();
151
  $template = get_template();
152
  $charset = get_option( 'blog_charset' );
@@ -165,12 +165,12 @@ final class CEI_Core {
165
  if ( 'option' == $setting->type ) {
166
 
167
  // Don't save widget data.
168
- if ( stristr( $key, 'widget_' ) ) {
169
  continue;
170
  }
171
 
172
  // Don't save sidebar data.
173
- if ( stristr( $key, 'sidebars_' ) ) {
174
  continue;
175
  }
176
 
@@ -215,25 +215,25 @@ final class CEI_Core {
215
  * @param object $wp_customize An instance of WP_Customize_Manager.
216
  * @return void
217
  */
218
- static private function _import( $wp_customize )
219
  {
220
  // Make sure we have a valid nonce.
221
  if ( ! wp_verify_nonce( $_REQUEST['cei-import'], 'cei-importing' ) ) {
222
  return;
223
  }
224
-
225
  // Make sure WordPress upload support is loaded.
226
  if ( ! function_exists( 'wp_handle_upload' ) ) {
227
  require_once( ABSPATH . 'wp-admin/includes/file.php' );
228
  }
229
-
230
  // Load the export/import option class.
231
  require_once CEI_PLUGIN_DIR . 'classes/class-cei-option.php';
232
-
233
  // Setup global vars.
234
  global $wp_customize;
235
  global $cei_error;
236
-
237
  // Setup internal vars.
238
  $cei_error = false;
239
  $template = get_template();
@@ -249,14 +249,14 @@ final class CEI_Core {
249
  $cei_error = __( 'Error importing settings! Please try again.', 'customizer-export-import' );
250
  return;
251
  }
252
-
253
  // Get the upload data.
254
  $raw = file_get_contents( $file['file'] );
255
  $data = @unserialize( $raw );
256
-
257
  // Remove the uploaded file.
258
  unlink( $file['file'] );
259
-
260
  // Data checks.
261
  if ( 'array' != gettype( $data ) ) {
262
  $cei_error = __( 'Error importing settings! Please check that you uploaded a customizer export file.', 'customizer-export-import' );
@@ -270,17 +270,17 @@ final class CEI_Core {
270
  $cei_error = __( 'Error importing settings! The settings you uploaded are not for the current theme.', 'customizer-export-import' );
271
  return;
272
  }
273
-
274
  // Import images.
275
  if ( isset( $_REQUEST['cei-import-images'] ) ) {
276
  $data['mods'] = self::_import_images( $data['mods'] );
277
  }
278
-
279
  // Import custom options.
280
  if ( isset( $data['options'] ) ) {
281
-
282
  foreach ( $data['options'] as $option_key => $option_value ) {
283
-
284
  $option = new CEI_Option( $wp_customize, $option_key, array(
285
  'default' => '',
286
  'type' => 'option',
@@ -321,18 +321,18 @@ final class CEI_Core {
321
  * @param array $mods An array of customizer mods.
322
  * @return array The mods array with any new import data.
323
  */
324
- static private function _import_images( $mods )
325
  {
326
  foreach ( $mods as $key => $val ) {
327
-
328
  if ( self::_is_image_url( $val ) ) {
329
-
330
  $data = self::_sideload_image( $val );
331
-
332
  if ( ! is_wp_error( $data ) ) {
333
-
334
  $mods[ $key ] = $data->url;
335
-
336
  // Handle header image controls.
337
  if ( isset( $mods[ $key . '_data' ] ) ) {
338
  $mods[ $key . '_data' ] = $data;
@@ -341,10 +341,10 @@ final class CEI_Core {
341
  }
342
  }
343
  }
344
-
345
  return $mods;
346
  }
347
-
348
  /**
349
  * Taken from the core media_sideload_image function and
350
  * modified to return an array of data instead of html.
@@ -354,39 +354,39 @@ final class CEI_Core {
354
  * @param string $file The image file path.
355
  * @return array An array of image data.
356
  */
357
- static private function _sideload_image( $file )
358
  {
359
  $data = new stdClass();
360
-
361
  if ( ! function_exists( 'media_handle_sideload' ) ) {
362
  require_once( ABSPATH . 'wp-admin/includes/media.php' );
363
  require_once( ABSPATH . 'wp-admin/includes/file.php' );
364
  require_once( ABSPATH . 'wp-admin/includes/image.php' );
365
  }
366
  if ( ! empty( $file ) ) {
367
-
368
  // Set variables for storage, fix file filename for query strings.
369
  preg_match( '/[^\?]+\.(jpe?g|jpe|gif|png)\b/i', $file, $matches );
370
  $file_array = array();
371
  $file_array['name'] = basename( $matches[0] );
372
-
373
  // Download file to temp location.
374
  $file_array['tmp_name'] = download_url( $file );
375
-
376
  // If error storing temporarily, return the error.
377
  if ( is_wp_error( $file_array['tmp_name'] ) ) {
378
  return $file_array['tmp_name'];
379
  }
380
-
381
  // Do the validation and storage stuff.
382
  $id = media_handle_sideload( $file_array, 0 );
383
-
384
  // If error storing permanently, unlink.
385
  if ( is_wp_error( $id ) ) {
386
  @unlink( $file_array['tmp_name'] );
387
  return $id;
388
  }
389
-
390
  // Build the object to return.
391
  $meta = wp_get_attachment_metadata( $id );
392
  $data->attachment_id = $id;
@@ -395,10 +395,10 @@ final class CEI_Core {
395
  $data->height = $meta['height'];
396
  $data->width = $meta['width'];
397
  }
398
-
399
  return $data;
400
  }
401
-
402
  /**
403
  * Checks to see whether a string is an image url or not.
404
  *
@@ -407,15 +407,15 @@ final class CEI_Core {
407
  * @param string $string The string to check.
408
  * @return bool Whether the string is an image url or not.
409
  */
410
- static private function _is_image_url( $string = '' )
411
  {
412
  if ( is_string( $string ) ) {
413
-
414
  if ( preg_match( '/\.(jpg|jpeg|png|gif)/i', $string ) ) {
415
  return true;
416
  }
417
  }
418
-
419
  return false;
420
  }
421
  }
27
  *
28
  * @since 0.1
29
  * @return void
30
+ */
31
+ static public function load_plugin_textdomain()
32
  {
33
  load_plugin_textdomain( 'customizer-export-import', false, basename( CEI_PLUGIN_DIR ) . '/lang/' );
34
  }
35
+
36
  /**
37
  * Check to see if we need to do an export or import.
38
  * This should be called by the customize_register action.
42
  * @param object $wp_customize An instance of WP_Customize_Manager.
43
  * @return void
44
  */
45
+ static public function init( $wp_customize )
46
  {
47
  if ( current_user_can( 'edit_theme_options' ) ) {
48
+
49
  if ( isset( $_REQUEST['cei-export'] ) ) {
50
  self::_export( $wp_customize );
51
  }
54
  }
55
  }
56
  }
57
+
58
  /**
59
  * Prints scripts for the control.
60
  *
61
  * @since 0.1
62
  * @return void
63
  */
64
+ static public function controls_print_scripts()
65
  {
66
  global $cei_error;
67
+
68
  if ( $cei_error ) {
69
  echo '<script> alert("' . $cei_error . '"); </script>';
70
  }
71
  }
72
+
73
  /**
74
  * Enqueues scripts for the control.
75
  *
76
  * @since 0.1
77
  * @return void
78
  */
79
+ static public function controls_enqueue_scripts()
80
  {
81
  // Register
82
  wp_register_style( 'cei-css', CEI_PLUGIN_URL . '/css/customizer.css', array(), CEI_VERSION );
83
  wp_register_script( 'cei-js', CEI_PLUGIN_URL . '/js/customizer.js', array( 'jquery' ), CEI_VERSION, true );
84
+
85
  // Localize
86
  wp_localize_script( 'cei-js', 'CEIl10n', array(
87
  'emptyImport' => __( 'Please choose a file to import.', 'customizer-export-import' )
88
  ));
89
+
90
  // Config
91
  wp_localize_script( 'cei-js', 'CEIConfig', array(
92
  'customizerURL' => admin_url( 'customize.php' ),
93
  'exportNonce' => wp_create_nonce( 'cei-exporting' )
94
  ));
95
+
96
  // Enqueue
97
  wp_enqueue_style( 'cei-css' );
98
  wp_enqueue_script( 'cei-js' );
99
  }
100
+
101
  /**
102
  * Registers the control with the customizer.
103
  *
105
  * @param object $wp_customize An instance of WP_Customize_Manager.
106
  * @return void
107
  */
108
+ static public function register( $wp_customize )
109
  {
110
  require_once CEI_PLUGIN_DIR . 'classes/class-cei-control.php';
111
 
114
  'title' => __( 'Export/Import', 'customizer-export-import' ),
115
  'priority' => 10000000
116
  ));
117
+
118
  // Add the export/import setting.
119
  $wp_customize->add_setting( 'cei-setting', array(
120
  'default' => '',
121
  'type' => 'none'
122
  ));
123
+
124
  // Add the export/import control.
125
+ $wp_customize->add_control( new CEI_Control(
126
+ $wp_customize,
127
+ 'cei-setting',
128
  array(
129
  'section' => 'cei-section',
130
  'priority' => 1
131
  )
132
  ));
133
  }
134
+
135
  /**
136
  * Export customizer settings.
137
  *
141
  * @param object $wp_customize An instance of WP_Customize_Manager.
142
  * @return void
143
  */
144
+ static private function _export( $wp_customize )
145
  {
146
  if ( ! wp_verify_nonce( $_REQUEST['cei-export'], 'cei-exporting' ) ) {
147
  return;
148
  }
149
+
150
  $theme = get_stylesheet();
151
  $template = get_template();
152
  $charset = get_option( 'blog_charset' );
165
  if ( 'option' == $setting->type ) {
166
 
167
  // Don't save widget data.
168
+ if ( 'widget_' === substr( strtolower( $key ), 0, 7 ) ) {
169
  continue;
170
  }
171
 
172
  // Don't save sidebar data.
173
+ if ( 'sidebars_' === substr( strtolower( $key ), 0, 9 ) ) {
174
  continue;
175
  }
176
 
215
  * @param object $wp_customize An instance of WP_Customize_Manager.
216
  * @return void
217
  */
218
+ static private function _import( $wp_customize )
219
  {
220
  // Make sure we have a valid nonce.
221
  if ( ! wp_verify_nonce( $_REQUEST['cei-import'], 'cei-importing' ) ) {
222
  return;
223
  }
224
+
225
  // Make sure WordPress upload support is loaded.
226
  if ( ! function_exists( 'wp_handle_upload' ) ) {
227
  require_once( ABSPATH . 'wp-admin/includes/file.php' );
228
  }
229
+
230
  // Load the export/import option class.
231
  require_once CEI_PLUGIN_DIR . 'classes/class-cei-option.php';
232
+
233
  // Setup global vars.
234
  global $wp_customize;
235
  global $cei_error;
236
+
237
  // Setup internal vars.
238
  $cei_error = false;
239
  $template = get_template();
249
  $cei_error = __( 'Error importing settings! Please try again.', 'customizer-export-import' );
250
  return;
251
  }
252
+
253
  // Get the upload data.
254
  $raw = file_get_contents( $file['file'] );
255
  $data = @unserialize( $raw );
256
+
257
  // Remove the uploaded file.
258
  unlink( $file['file'] );
259
+
260
  // Data checks.
261
  if ( 'array' != gettype( $data ) ) {
262
  $cei_error = __( 'Error importing settings! Please check that you uploaded a customizer export file.', 'customizer-export-import' );
270
  $cei_error = __( 'Error importing settings! The settings you uploaded are not for the current theme.', 'customizer-export-import' );
271
  return;
272
  }
273
+
274
  // Import images.
275
  if ( isset( $_REQUEST['cei-import-images'] ) ) {
276
  $data['mods'] = self::_import_images( $data['mods'] );
277
  }
278
+
279
  // Import custom options.
280
  if ( isset( $data['options'] ) ) {
281
+
282
  foreach ( $data['options'] as $option_key => $option_value ) {
283
+
284
  $option = new CEI_Option( $wp_customize, $option_key, array(
285
  'default' => '',
286
  'type' => 'option',
321
  * @param array $mods An array of customizer mods.
322
  * @return array The mods array with any new import data.
323
  */
324
+ static private function _import_images( $mods )
325
  {
326
  foreach ( $mods as $key => $val ) {
327
+
328
  if ( self::_is_image_url( $val ) ) {
329
+
330
  $data = self::_sideload_image( $val );
331
+
332
  if ( ! is_wp_error( $data ) ) {
333
+
334
  $mods[ $key ] = $data->url;
335
+
336
  // Handle header image controls.
337
  if ( isset( $mods[ $key . '_data' ] ) ) {
338
  $mods[ $key . '_data' ] = $data;
341
  }
342
  }
343
  }
344
+
345
  return $mods;
346
  }
347
+
348
  /**
349
  * Taken from the core media_sideload_image function and
350
  * modified to return an array of data instead of html.
354
  * @param string $file The image file path.
355
  * @return array An array of image data.
356
  */
357
+ static private function _sideload_image( $file )
358
  {
359
  $data = new stdClass();
360
+
361
  if ( ! function_exists( 'media_handle_sideload' ) ) {
362
  require_once( ABSPATH . 'wp-admin/includes/media.php' );
363
  require_once( ABSPATH . 'wp-admin/includes/file.php' );
364
  require_once( ABSPATH . 'wp-admin/includes/image.php' );
365
  }
366
  if ( ! empty( $file ) ) {
367
+
368
  // Set variables for storage, fix file filename for query strings.
369
  preg_match( '/[^\?]+\.(jpe?g|jpe|gif|png)\b/i', $file, $matches );
370
  $file_array = array();
371
  $file_array['name'] = basename( $matches[0] );
372
+
373
  // Download file to temp location.
374
  $file_array['tmp_name'] = download_url( $file );
375
+
376
  // If error storing temporarily, return the error.
377
  if ( is_wp_error( $file_array['tmp_name'] ) ) {
378
  return $file_array['tmp_name'];
379
  }
380
+
381
  // Do the validation and storage stuff.
382
  $id = media_handle_sideload( $file_array, 0 );
383
+
384
  // If error storing permanently, unlink.
385
  if ( is_wp_error( $id ) ) {
386
  @unlink( $file_array['tmp_name'] );
387
  return $id;
388
  }
389
+
390
  // Build the object to return.
391
  $meta = wp_get_attachment_metadata( $id );
392
  $data->attachment_id = $id;
395
  $data->height = $meta['height'];
396
  $data->width = $meta['width'];
397
  }
398
+
399
  return $data;
400
  }
401
+
402
  /**
403
  * Checks to see whether a string is an image url or not.
404
  *
407
  * @param string $string The string to check.
408
  * @return bool Whether the string is an image url or not.
409
  */
410
+ static private function _is_image_url( $string = '' )
411
  {
412
  if ( is_string( $string ) ) {
413
+
414
  if ( preg_match( '/\.(jpg|jpeg|png|gif)/i', $string ) ) {
415
  return true;
416
  }
417
  }
418
+
419
  return false;
420
  }
421
  }
customizer-export-import.php CHANGED
@@ -3,14 +3,14 @@
3
  * Plugin Name: Customizer Export/Import
4
  * Plugin URI: http://www.wpbeaverbuilder.com/wordpress-customizer-export-import-plugin/?utm_source=external&utm_medium=customizer-export&utm_campaign=plugins-page
5
  * Description: Adds settings export and import functionality to the WordPress customizer.
6
- * Version: 0.8
7
  * Author: The Beaver Builder Team
8
  * Author URI: http://www.wpbeaverbuilder.com/?utm_source=external&utm_medium=customizer-export&utm_campaign=plugins-page
9
  * License: GNU General Public License v2.0
10
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
  * Text Domain: customizer-export-import
12
  */
13
- define( 'CEI_VERSION', '0.8' );
14
  define( 'CEI_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
15
  define( 'CEI_PLUGIN_URL', plugins_url( '/', __FILE__ ) );
16
 
3
  * Plugin Name: Customizer Export/Import
4
  * Plugin URI: http://www.wpbeaverbuilder.com/wordpress-customizer-export-import-plugin/?utm_source=external&utm_medium=customizer-export&utm_campaign=plugins-page
5
  * Description: Adds settings export and import functionality to the WordPress customizer.
6
+ * Version: 0.9
7
  * Author: The Beaver Builder Team
8
  * Author URI: http://www.wpbeaverbuilder.com/?utm_source=external&utm_medium=customizer-export&utm_campaign=plugins-page
9
  * License: GNU General Public License v2.0
10
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
  * Text Domain: customizer-export-import
12
  */
13
+ define( 'CEI_VERSION', '0.9' );
14
  define( 'CEI_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
15
  define( 'CEI_PLUGIN_URL', plugins_url( '/', __FILE__ ) );
16
 
readme.txt CHANGED
@@ -92,3 +92,7 @@ Please visit our blog for more info on the [Customizer Export/Import plugin](htt
92
  = Version 0.8 =
93
 
94
  - Added support for option data that has an empty value.
 
 
 
 
92
  = Version 0.8 =
93
 
94
  - Added support for option data that has an empty value.
95
+
96
+ = Version 0.9 =
97
+
98
+ - Allow options with `widget` or `sidebar` in their key to be exported.