Customizer Export/Import - Version 0.2

Version Description

Download this release

Release Info

Developer justinbusa
Plugin Icon 128x128 Customizer Export/Import
Version 0.2
Comparing to
See all releases

Code changes from version 0.1 to 0.2

README.md CHANGED
@@ -10,6 +10,20 @@ Exporting customizer settings is easy. Click the export button from within the c
10
 
11
  Importing customizer settings is just as easy. Choose the export file you would like to import, select whether you would like to download and import images (similar to importing posts), and finally, click the import button. Once your settings have been imported the page will refresh and your new design will be displayed.
12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  ## Contribute! ##
14
 
15
- We'd love to hear your feedback as to how we could improve the Customizer Export/Import plugin, or better yet, see theme developers actively contribute! Don't hesitate to let us know if you're interested in contributing as we would gladly have others on board.
10
 
11
  Importing customizer settings is just as easy. Choose the export file you would like to import, select whether you would like to download and import images (similar to importing posts), and finally, click the import button. Once your settings have been imported the page will refresh and your new design will be displayed.
12
 
13
+ ## Exporting Custom Options ##
14
+
15
+ Some plugins or themes may create controls that don't store their settings as theme mods and instead store them in the WordPress options table. These settings can also be exported and imported by adding your option key to the array of options that will be exported as shown below.
16
+
17
+ ```
18
+ function my_export_option_keys( $keys ) {
19
+ $keys[] = 'my_option_key';
20
+ $keys[] = 'another_option_key';
21
+ return $keys;
22
+ }
23
+
24
+ add_filter( 'cei_export_option_keys', 'my_export_option_keys' );
25
+ ```
26
+
27
  ## Contribute! ##
28
 
29
+ We'd love to hear your feedback as to how we could improve the Customizer Export/Import plugin, or better yet, see theme developers actively contribute! Don't hesitate to let us know if you're interested in contributing as we would gladly have others on board.
classes/class-cei-core.php CHANGED
@@ -10,7 +10,7 @@ final class CEI_Core {
10
  */
11
  static public function load_plugin_textdomain()
12
  {
13
- load_plugin_textdomain( CEI_TD, false, basename( CEI_PLUGIN_DIR ) . '/lang/' );
14
  }
15
 
16
  /**
@@ -52,7 +52,7 @@ final class CEI_Core {
52
 
53
  // Localize
54
  wp_localize_script( 'cei-js', 'CEIl10n', array(
55
- 'emptyImport' => __( 'Please choose a file to import.', CEI_TD )
56
  ));
57
 
58
  // Config
@@ -75,7 +75,7 @@ final class CEI_Core {
75
 
76
  // Add the export/import section.
77
  $customizer->add_section( 'cei-section', array(
78
- 'title' => __( 'Export/Import', CEI_TD ),
79
  'priority' => 10000000
80
  ));
81
 
@@ -110,15 +110,33 @@ final class CEI_Core {
110
  $template = get_option( 'template' );
111
  $charset = get_option( 'blog_charset' );
112
  $mods = get_theme_mods();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
 
 
114
  header( 'Content-disposition: attachment; filename=' . $theme . '-export.dat' );
115
  header( 'Content-Type: application/octet-stream; charset=' . $charset );
116
 
117
- echo serialize( array(
118
- 'template' => $template,
119
- 'mods' => $mods ? $mods : array()
120
- ));
121
 
 
122
  die();
123
  }
124
 
@@ -145,15 +163,15 @@ final class CEI_Core {
145
 
146
  // Data checks.
147
  if ( 'array' != gettype( $data ) ) {
148
- $cei_error = __( 'Error importing settings! Please check that you uploaded a customizer export file.', CEI_TD );
149
  return;
150
  }
151
  if ( ! isset( $data['template'] ) || ! isset( $data['mods'] ) ) {
152
- $cei_error = __( 'Error importing settings! Please check that you uploaded a customizer export file.', CEI_TD );
153
  return;
154
  }
155
  if ( $data['template'] != $template ) {
156
- $cei_error = __( 'Error importing settings! The settings you uploaded are not for the current theme.', CEI_TD );
157
  return;
158
  }
159
 
@@ -162,6 +180,13 @@ final class CEI_Core {
162
  $data['mods'] = self::_import_images( $data['mods'] );
163
  }
164
 
 
 
 
 
 
 
 
165
  // Call the customize_save action.
166
  do_action( 'customize_save', $wp_customize );
167
 
10
  */
11
  static public function load_plugin_textdomain()
12
  {
13
+ load_plugin_textdomain( 'customizer-export-import', false, basename( CEI_PLUGIN_DIR ) . '/lang/' );
14
  }
15
 
16
  /**
52
 
53
  // Localize
54
  wp_localize_script( 'cei-js', 'CEIl10n', array(
55
+ 'emptyImport' => __( 'Please choose a file to import.', 'customizer-export-import' )
56
  ));
57
 
58
  // Config
75
 
76
  // Add the export/import section.
77
  $customizer->add_section( 'cei-section', array(
78
+ 'title' => __( 'Export/Import', 'customizer-export-import' ),
79
  'priority' => 10000000
80
  ));
81
 
110
  $template = get_option( 'template' );
111
  $charset = get_option( 'blog_charset' );
112
  $mods = get_theme_mods();
113
+ $data = array(
114
+ 'template' => $template,
115
+ 'mods' => $mods ? $mods : array(),
116
+ 'options' => array()
117
+ );
118
+
119
+ // Plugin developers can specify option keys to export.
120
+ $option_keys = apply_filters( 'cei_export_option_keys', array() );
121
+
122
+ // Add options to the data.
123
+ foreach ( $option_keys as $option_key ) {
124
+
125
+ $option_value = get_option( $option_key );
126
+
127
+ if ( $option_value ) {
128
+ $data['options'][ $option_key ] = $option_value;
129
+ }
130
+ }
131
 
132
+ // Set the download headers.
133
  header( 'Content-disposition: attachment; filename=' . $theme . '-export.dat' );
134
  header( 'Content-Type: application/octet-stream; charset=' . $charset );
135
 
136
+ // Serialize the export data.
137
+ echo serialize( $data );
 
 
138
 
139
+ // Start the download.
140
  die();
141
  }
142
 
163
 
164
  // Data checks.
165
  if ( 'array' != gettype( $data ) ) {
166
+ $cei_error = __( 'Error importing settings! Please check that you uploaded a customizer export file.', 'customizer-export-import' );
167
  return;
168
  }
169
  if ( ! isset( $data['template'] ) || ! isset( $data['mods'] ) ) {
170
+ $cei_error = __( 'Error importing settings! Please check that you uploaded a customizer export file.', 'customizer-export-import' );
171
  return;
172
  }
173
  if ( $data['template'] != $template ) {
174
+ $cei_error = __( 'Error importing settings! The settings you uploaded are not for the current theme.', 'customizer-export-import' );
175
  return;
176
  }
177
 
180
  $data['mods'] = self::_import_images( $data['mods'] );
181
  }
182
 
183
+ // Import custom options.
184
+ if ( isset( $data['options'] ) ) {
185
+ foreach ( $data['options'] as $option_key => $option_value ) {
186
+ update_option( $option_key, $option_value );
187
+ }
188
+ }
189
+
190
  // Call the customize_save action.
191
  do_action( 'customize_save', $wp_customize );
192
 
customizer-export-import.php CHANGED
@@ -13,7 +13,6 @@
13
  define( 'CEI_VERSION', '0.1' );
14
  define( 'CEI_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
15
  define( 'CEI_PLUGIN_URL', plugins_url( '/', __FILE__ ) );
16
- define( 'CEI_TD', 'customizer-export-import' );
17
 
18
  /* Classes */
19
  require_once CEI_PLUGIN_DIR . 'classes/class-cei-core.php';
13
  define( 'CEI_VERSION', '0.1' );
14
  define( 'CEI_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
15
  define( 'CEI_PLUGIN_URL', plugins_url( '/', __FILE__ ) );
 
16
 
17
  /* Classes */
18
  require_once CEI_PLUGIN_DIR . 'classes/class-cei-core.php';
includes/control.php CHANGED
@@ -1,25 +1,25 @@
1
  <span class="customize-control-title">
2
- <?php _e( 'Export', CEI_TD ); ?>
3
  </span>
4
  <span class="description customize-control-description">
5
- <?php _e( 'Click the button below to export the customization settings for this theme.', CEI_TD ); ?>
6
  </span>
7
- <input type="button" class="button" name="cei-export-button" value="<?php esc_attr_e( 'Export', CEI_TD ); ?>" />
8
 
9
  <hr class="cei-hr" />
10
 
11
  <span class="customize-control-title">
12
- <?php _e( 'Import', CEI_TD ); ?>
13
  </span>
14
  <span class="description customize-control-description">
15
- <?php _e( 'Upload a file to import customization settings for this theme.', CEI_TD ); ?>
16
  </span>
17
  <div class="cei-import-controls">
18
  <input type="file" name="cei-import-file" class="cei-import-file" />
19
  <label class="cei-import-images">
20
- <input type="checkbox" name="cei-import-images" value="1" /> <?php _e( 'Download and import image files?', CEI_TD ); ?>
21
  </label>
22
  <?php wp_nonce_field( 'cei-importing', 'cei-import' ); ?>
23
  </div>
24
- <div class="cei-uploading"><?php _e( 'Uploading...', CEI_TD ); ?></div>
25
- <input type="button" class="button" name="cei-import-button" value="<?php esc_attr_e( 'Import', CEI_TD ); ?>" />
1
  <span class="customize-control-title">
2
+ <?php _e( 'Export', 'customizer-export-import' ); ?>
3
  </span>
4
  <span class="description customize-control-description">
5
+ <?php _e( 'Click the button below to export the customization settings for this theme.', 'customizer-export-import' ); ?>
6
  </span>
7
+ <input type="button" class="button" name="cei-export-button" value="<?php esc_attr_e( 'Export', 'customizer-export-import' ); ?>" />
8
 
9
  <hr class="cei-hr" />
10
 
11
  <span class="customize-control-title">
12
+ <?php _e( 'Import', 'customizer-export-import' ); ?>
13
  </span>
14
  <span class="description customize-control-description">
15
+ <?php _e( 'Upload a file to import customization settings for this theme.', 'customizer-export-import' ); ?>
16
  </span>
17
  <div class="cei-import-controls">
18
  <input type="file" name="cei-import-file" class="cei-import-file" />
19
  <label class="cei-import-images">
20
+ <input type="checkbox" name="cei-import-images" value="1" /> <?php _e( 'Download and import image files?', 'customizer-export-import' ); ?>
21
  </label>
22
  <?php wp_nonce_field( 'cei-importing', 'cei-import' ); ?>
23
  </div>
24
+ <div class="cei-uploading"><?php _e( 'Uploading...', 'customizer-export-import' ); ?></div>
25
+ <input type="button" class="button" name="cei-import-button" value="<?php esc_attr_e( 'Import', 'customizer-export-import' ); ?>" />
readme.txt CHANGED
@@ -23,6 +23,18 @@ Exporting customizer settings is easy. Click the export button from within the c
23
 
24
  Importing customizer settings is just as easy. Choose the export file you would like to import, select whether you would like to download and import images (similar to importing posts), and finally, click the import button. Once your settings have been imported the page will refresh and your new design will be displayed.
25
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  = Contribute! =
27
 
28
  We'd love to hear your feedback as to how we could improve the Customizer Export/Import plugin, or better yet, see theme developers actively contribute! Don't hesitate to let us know if you're interested in contributing as we would gladly have others on board.
@@ -47,4 +59,8 @@ Please visit our blog for more info on the [Customizer Export/Import plugin](htt
47
 
48
  = Version 0.1 =
49
 
50
- Initial release.
 
 
 
 
23
 
24
  Importing customizer settings is just as easy. Choose the export file you would like to import, select whether you would like to download and import images (similar to importing posts), and finally, click the import button. Once your settings have been imported the page will refresh and your new design will be displayed.
25
 
26
+ = Exporting Custom Options =
27
+
28
+ Some plugins or themes may create controls that don't store their settings as theme mods and instead store them in the WordPress options table. These settings can also be exported and imported by adding your option key to the array of options that will be exported as shown below.
29
+
30
+ function my_export_option_keys( $keys ) {
31
+ $keys[] = 'my_option_key';
32
+ $keys[] = 'another_option_key';
33
+ return $keys;
34
+ }
35
+
36
+ add_filter( 'cei_export_option_keys', 'my_export_option_keys' );
37
+
38
  = Contribute! =
39
 
40
  We'd love to hear your feedback as to how we could improve the Customizer Export/Import plugin, or better yet, see theme developers actively contribute! Don't hesitate to let us know if you're interested in contributing as we would gladly have others on board.
59
 
60
  = Version 0.1 =
61
 
62
+ - Initial release.
63
+
64
+ = Version 0.2 =
65
+
66
+ - Added cei_export_option_keys filter for exporting custom options.