Import / Export Customizer Settings - Version 1.0.0

Version Description

  • Initial release
Download this release

Release Info

Developer patilvikasj
Plugin Icon Import / Export Customizer Settings
Version 1.0.0
Comparing to
See all releases

Version 1.0.0

astra-import-export.php ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Plugin Name: Import / Export Customizer Settings
4
+ * Plugin URI: https://wpastra.com/
5
+ * Description: This plugin is an add-on for the Astra WordPress Theme. It will help in Import Export Customizer settings.
6
+ * Version: 1.0.0
7
+ * Author: Brainstorm Force
8
+ * Author URI: http://www.brainstormforce.com
9
+ * Text Domain: astra-import-export
10
+ *
11
+ * @package Import / Export Customizer Settings
12
+ */
13
+
14
+ /**
15
+ * Set constants.
16
+ */
17
+ define( 'ASTRA_IMPORT_EXPORT_VER', '1.0.0' );
18
+ define( 'ASTRA_IMPORT_EXPORT_FILE', __FILE__ );
19
+ define( 'ASTRA_IMPORT_EXPORT_BASE', plugin_basename( ASTRA_IMPORT_EXPORT_FILE ) );
20
+ define( 'ASTRA_IMPORT_EXPORT_DIR', plugin_dir_path( ASTRA_IMPORT_EXPORT_FILE ) );
21
+ define( 'ASTRA_IMPORT_EXPORT_URI', plugins_url( '/', ASTRA_IMPORT_EXPORT_FILE ) );
22
+
23
+
24
+ /**
25
+ * Import / Export Customizer Settings Setup
26
+ *
27
+ * @since 1.0.0
28
+ */
29
+ function astra_import_export_setup() {
30
+ require_once ASTRA_IMPORT_EXPORT_DIR . 'inc/class-astra-import-export.php';
31
+ }
32
+
33
+ add_action( 'plugins_loaded', 'astra_import_export_setup' );
34
+
35
+ /**
36
+ * Add plugin settings link.
37
+ *
38
+ * @param Array $links Plugin links to be displayed on the plugins.php.
39
+ * @return Array
40
+ */
41
+ function aix_plugin_action_links( $links ) {
42
+ $links[] = '<a href="' . esc_url( get_admin_url( null, 'themes.php?page=astra' ) ) . '">' . __( 'Settings', 'astra-import-export' ) . '</a>';
43
+
44
+ return $links;
45
+ }
46
+
47
+ add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'aix_plugin_action_links' );
inc/assets/css/style.css ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ #astra-ie label {
2
+ display: block;
3
+ }
4
+
5
+ #astra-ie input[type=file] {
6
+ width: 100%
7
+ }
inc/class-astra-import-export.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Astra Import Export
4
+ *
5
+ * @package Astra Import Export for Astra Theme
6
+ * @since 1.0.0
7
+ */
8
+
9
+ if ( ! class_exists( 'Astra_Import_Export' ) ) {
10
+
11
+ /**
12
+ * Advanced Headers Initial Setup
13
+ *
14
+ * @since 1.0.0
15
+ */
16
+ class Astra_Import_Export {
17
+
18
+
19
+ /**
20
+ * Member Variable
21
+ *
22
+ * @var object instance
23
+ */
24
+ private static $instance;
25
+
26
+ /**
27
+ * Initiator
28
+ */
29
+ public static function get_instance() {
30
+ if ( ! isset( self::$instance ) ) {
31
+ self::$instance = new self();
32
+ }
33
+
34
+ return self::$instance;
35
+ }
36
+
37
+ /**
38
+ * Constructor function that initializes required actions and hooks
39
+ */
40
+ public function __construct() {
41
+ require_once ASTRA_IMPORT_EXPORT_DIR . 'inc/classes/class-astra-import-export-loader.php';
42
+ }
43
+ }
44
+
45
+ /**
46
+ * Kicking this off by calling 'get_instance()' method
47
+ */
48
+ Astra_Import_Export::get_instance();
49
+
50
+ }
inc/classes/class-astra-import-export-loader.php ADDED
@@ -0,0 +1,227 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Astra Import Export - Customizer.
4
+ *
5
+ * @package Astra Import Export for Astra Theme
6
+ * @since 1.0.0
7
+ */
8
+
9
+ if ( ! class_exists( 'Astra_Import_Export_Loader' ) ) {
10
+
11
+ /**
12
+ * Customizer Initialization
13
+ *
14
+ * @since 1.0.0
15
+ */
16
+ class Astra_Import_Export_Loader {
17
+
18
+ /**
19
+ * Member Variable
20
+ *
21
+ * @var instance
22
+ */
23
+ private static $instance;
24
+
25
+ /**
26
+ * Initiator
27
+ */
28
+ public static function get_instance() {
29
+ if ( ! isset( self::$instance ) ) {
30
+ self::$instance = new self();
31
+ }
32
+ return self::$instance;
33
+ }
34
+
35
+ /**
36
+ * Constructor
37
+ */
38
+ public function __construct() {
39
+ add_action( 'astra_welcome_page_right_sidebar_content', array( $this, 'astra_import_export_section' ), 50 );
40
+ add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
41
+ add_action( 'admin_init', array( $this, 'export' ) );
42
+ add_action( 'admin_init', array( $this, 'import' ) );
43
+ add_action( 'admin_notices', array( $this, 'astra_admin_errors' ) );
44
+ }
45
+
46
+ /**
47
+ * Function enqueue_scripts() to enqueue files.
48
+ */
49
+ public function enqueue_scripts() {
50
+
51
+ wp_register_style( 'astra-import-export-css', ASTRA_IMPORT_EXPORT_URI . 'inc/assets/css/style.css', array(), ASTRA_IMPORT_EXPORT_VER );
52
+
53
+ }
54
+
55
+ /**
56
+ * Add postMessage support for site title and description for the Theme Customizer.
57
+ */
58
+ public function astra_import_export_section() {
59
+ // Enqueue.
60
+ wp_enqueue_style( 'astra-import-export-css' );
61
+ ?>
62
+ <div class="postbox" id="astra-ie">
63
+ <h2 class="hndle ast-normal-cusror"><span class="dashicons dashicons-download"></span><?php esc_html_e( 'Export Settings', 'astra-import-export' ); ?></h2>
64
+ <div class="inside">
65
+ <p><?php esc_html_e( 'Export your current Astra Customizer settings.', 'astra-import-export' ); ?></p>
66
+ <form method="post">
67
+ <p><input type="hidden" name="astra_ie_action" value="export_settings" /></p>
68
+ <p style="margin-bottom:0">
69
+ <?php wp_nonce_field( 'astra_export_nonce', 'astra_export_nonce' ); ?>
70
+ <?php submit_button( __( 'Export', 'astra-import-export' ), 'button', 'submit', false, array( 'id' => '' ) ); ?>
71
+ </p>
72
+ </form>
73
+ </div>
74
+ </div>
75
+
76
+ <div class="postbox" id="astra-ie">
77
+ <h2 class="hndle ast-normal-cusror"><span class="dashicons dashicons-upload"></span><?php esc_html_e( 'Import Settings', 'astra-import-export' ); ?></h2>
78
+ <div class="inside">
79
+ <p><?php esc_html_e( 'Import your Astra Customizer settings.', 'astra-import-export' ); ?></p>
80
+ <form method="post" enctype="multipart/form-data">
81
+ <p>
82
+ <input type="file" name="import_file"/>
83
+ </p>
84
+ <p style="margin-bottom:0">
85
+ <input type="hidden" name="astra_ie_action" value="import_settings" />
86
+ <?php wp_nonce_field( 'astra_import_nonce', 'astra_import_nonce' ); ?>
87
+ <?php submit_button( __( 'Import', 'astra-import-export' ), 'button', 'submit', false, array( 'id' => '' ) ); ?>
88
+ </p>
89
+ </form>
90
+
91
+ </div>
92
+ </div>
93
+ <?php
94
+ }
95
+
96
+ /**
97
+ * Display import status in the admin notices.
98
+ *
99
+ * @since 1.0.0
100
+ */
101
+ public function astra_admin_errors() {
102
+ // Verify correct source for the $_GET data.
103
+ if ( isset( $_GET['_wpnonce'] ) && ! wp_verify_nonce( $_GET['_wpnonce'], 'astra-import-complete' ) ) {
104
+ return;
105
+ }
106
+
107
+ if ( ! isset( $_GET['status'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
108
+ return;
109
+ }
110
+
111
+ if ( 'imported' === $_GET['status'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
112
+ add_settings_error( 'astra-notices', 'imported', esc_html__( 'Import successful.', 'astra-import-export' ), 'updated' );
113
+ }
114
+
115
+ settings_errors( 'astra-notices' );
116
+ }
117
+
118
+ /**
119
+ * Import our exported file.
120
+ *
121
+ * @since 1.0.0
122
+ */
123
+ public static function import() {
124
+
125
+ if ( ! isset( $_POST['astra_import_nonce'] ) || ! wp_verify_nonce( $_POST['astra_import_nonce'], 'astra_import_nonce' ) ) {
126
+ return;
127
+ }
128
+ if ( empty( $_POST['astra_ie_action'] ) || 'import_settings' !== $_POST['astra_ie_action'] ) {
129
+ return;
130
+ }
131
+
132
+ if ( ! current_user_can( 'manage_options' ) ) {
133
+ return;
134
+ }
135
+
136
+ $filename = $_FILES['import_file']['name'];
137
+
138
+ if ( empty( $filename ) ) {
139
+ return;
140
+ }
141
+
142
+ $extension = end( explode( '.', $filename ) );
143
+
144
+ if ( 'json' !== $extension ) {
145
+ wp_die( esc_html__( 'Please upload a valid .json file', 'astra-import-export' ) );
146
+ }
147
+
148
+ $import_file = $_FILES['import_file']['tmp_name'];
149
+
150
+ if ( empty( $import_file ) ) {
151
+ wp_die( esc_html__( 'Please upload a file to import', 'astra-import-export' ) );
152
+ }
153
+
154
+ global $wp_filesystem;
155
+ if ( empty( $wp_filesystem ) ) {
156
+ require_once ABSPATH . '/wp-admin/includes/file.php';
157
+ WP_Filesystem();
158
+ }
159
+ // Retrieve the settings from the file and convert the json object to an array.
160
+ $file_contants = $wp_filesystem->get_contents( $import_file );
161
+ $settings = json_decode( $file_contants, 1 );
162
+
163
+ // Astra addons activation.
164
+ if ( class_exists( 'Astra_Admin_Helper' ) ) {
165
+ Astra_Admin_Helper::update_admin_settings_option( '_astra_ext_enabled_extensions', $settings['astra-addons'] );
166
+ }
167
+
168
+ // Delete existing dynamic CSS cache.
169
+ delete_option( 'astra-settings' );
170
+
171
+ update_option( 'astra-settings', $settings['customizer-settings'] );
172
+
173
+ wp_safe_redirect(
174
+ wp_nonce_url(
175
+ add_query_arg(
176
+ array(
177
+ 'page' => 'astra',
178
+ 'status' => 'imported',
179
+ ),
180
+ admin_url( 'themes.php' )
181
+ ),
182
+ 'astra-import-complete'
183
+ )
184
+ );
185
+ exit;
186
+ }
187
+
188
+ /**
189
+ * Export our chosen options.
190
+ *
191
+ * @since 1.0.0
192
+ */
193
+ public static function export() {
194
+ if ( ! isset( $_POST['astra_export_nonce'] ) || ! wp_verify_nonce( $_POST['astra_export_nonce'], 'astra_export_nonce' ) ) {
195
+ return;
196
+ }
197
+ if ( empty( $_POST['astra_ie_action'] ) || 'export_settings' !== $_POST['astra_ie_action'] ) {
198
+ return;
199
+ }
200
+ if ( ! current_user_can( 'manage_options' ) ) {
201
+ return;
202
+ }
203
+
204
+ // Get options from the Customizer API.
205
+ $theme_options['customizer-settings'] = Astra_Theme_Options::get_options();
206
+
207
+ // Add Astra Addons to import.
208
+ if ( class_exists( 'Astra_Ext_Extension' ) ) {
209
+ $theme_options['astra-addons'] = Astra_Ext_Extension::get_enabled_addons();
210
+ }
211
+
212
+ $theme_options = apply_filters( 'astra_export_data', $theme_options );
213
+ nocache_headers();
214
+ header( 'Content-Type: application/json; charset=utf-8' );
215
+ header( 'Content-Disposition: attachment; filename=astra-settings-export-' . date( 'm-d-Y' ) . '.json' );
216
+ header( 'Expires: 0' );
217
+ echo wp_json_encode( $theme_options );
218
+ // Start the download.
219
+ die();
220
+ }
221
+ }
222
+ }
223
+
224
+ /**
225
+ * Kicking this off by calling 'get_instance()' method
226
+ */
227
+ Astra_Import_Export_Loader::get_instance();
inc/classes/index.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Index file
4
+ *
5
+ * @package Astra
6
+ * @since Astra 1.0.0
7
+ */
8
+
9
+ /* Silence is golden, and we agree. */
inc/index.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Index file
4
+ *
5
+ * @package Astra
6
+ * @since Astra 1.0.0
7
+ */
8
+
9
+ /* Silence is golden, and we agree. */
index.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Index file
4
+ *
5
+ * @package Astra
6
+ * @since Astra 1.0.0
7
+ */
8
+
9
+ /* Silence is golden, and we agree. */
readme.txt ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Import / Export Customizer Settings ===
2
+ Contributors: brainstormforce
3
+ Donate link: https://www.brainstormforce.com/payment/
4
+ Requires at least: 4.4
5
+ Tags: astra addons export, import, settings, customizer settings, theme settings, theme options
6
+ Stable tag: 1.0.0
7
+ Requires PHP: 5.4
8
+ Tested up to: 5.2.1
9
+ License: GPLv2 or later
10
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
+
12
+ == Description ==
13
+
14
+ Astra theme customizer offers several settings for header/footer layout, sidebar and blog designs, colors, backgrounds, typography and much more. You need to tweak the number of settings to make your site look flawless. These settings can be moved to other Astra sites easily with Import / Export Customizer Settings plugin. It will save repetitive work to arrange all customizer settings for each new Astra site or while moving the site from local to live.
15
+
16
+ It is an easy-to-use plugin for the Astra theme that lets you import-export customizer settings.
17
+
18
+ <strong>Note:</strong>
19
+
20
+ This Import/Export plugin is created only for the <a href="https://wpastra.com/?utm_source=wp-repo&utm_campaign=home-page-banner-for-astra-theme&utm_medium=description">Astra theme</a>. You should have the Astra theme installed and activated on your website.
21
+
22
+ == Installation ==
23
+
24
+ 1. Make sure you have the Astra theme installed and activated.
25
+ 2. Upload the plugin files to the `/wp-content/plugins/` directory, or install the plugin through the WordPress plugins screen directly.
26
+ 3. Activate the plugin through the 'Plugins' screen in WordPress
27
+ 4. Once activated, you’ll find Import Export settings in the Astra Options page.
28
+
29
+ == Frequently Asked Questions ==
30
+
31
+ = Can I use this plugin with other themes? =
32
+
33
+ No! This plugin will only work with the Astra theme.
34
+
35
+ = How to use this plugin? =
36
+
37
+ 1. From the Appearance > Astra Options page, install and activate the plugin with a single click. (Make sure you have Astra theme installed and activated.)
38
+ 2. After activating the plugin, refresh the page once. You will see import/export options on the same page.
39
+
40
+ = Will this plugin work for premium Astra version i.e. Astra Pro? =
41
+ Yes! Astra Pro settings that are available with customizer can be imported/exported with this plugin.
42
+
43
+ == Changelog ==
44
+
45
+ = 1.0.0 =
46
+ - Initial release