Version Description
Download this release
Release Info
Developer | vrundakansara |
Plugin | |
Version | 1.3.18 |
Comparing to | |
See all releases |
Code changes from version 1.3.17 to 1.3.18
- astra-sites.php +2 -2
- inc/assets/js/admin-page.js +5 -36
- inc/classes/class-astra-sites-importer.php +605 -602
- inc/classes/class-astra-sites-page.php +434 -434
- inc/classes/class-astra-sites-white-label.php +239 -239
- inc/classes/class-astra-sites.php +1 -1
- inc/classes/compatibility/class-astra-sites-compatibility.php +69 -69
- inc/importers/batch-processing/class-astra-sites-batch-processing-beaver-builder.php +261 -261
- inc/importers/batch-processing/class-astra-sites-batch-processing-brizy.php +125 -125
- inc/importers/batch-processing/class-astra-sites-batch-processing-elementor.php +109 -109
- inc/importers/batch-processing/class-astra-sites-batch-processing-gutenberg.php +167 -167
- inc/importers/batch-processing/class-astra-sites-batch-processing.php +227 -227
- inc/importers/batch-processing/helpers/class-astra-sites-image-importer.php +263 -263
- inc/importers/class-astra-site-options-import.php +309 -309
- inc/importers/class-astra-sites-helper.php +311 -311
- inc/importers/wxr-importer/class-astra-wxr-importer.php +446 -446
- languages/astra-sites.pot +11 -15
- readme.txt +7 -8
astra-sites.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
* Plugin Name: Astra Starter Sites
|
4 |
* Plugin URI: http://www.wpastra.com/pro/
|
5 |
* Description: Import free sites build with Astra theme.
|
6 |
-
* Version: 1.3.
|
7 |
* Author: Brainstorm Force
|
8 |
* Author URI: http://www.brainstormforce.com
|
9 |
* Text Domain: astra-sites
|
@@ -19,7 +19,7 @@ if ( ! defined( 'ASTRA_SITES_NAME' ) ) {
|
|
19 |
}
|
20 |
|
21 |
if ( ! defined( 'ASTRA_SITES_VER' ) ) {
|
22 |
-
define( 'ASTRA_SITES_VER', '1.3.
|
23 |
}
|
24 |
|
25 |
if ( ! defined( 'ASTRA_SITES_FILE' ) ) {
|
3 |
* Plugin Name: Astra Starter Sites
|
4 |
* Plugin URI: http://www.wpastra.com/pro/
|
5 |
* Description: Import free sites build with Astra theme.
|
6 |
+
* Version: 1.3.18
|
7 |
* Author: Brainstorm Force
|
8 |
* Author URI: http://www.brainstormforce.com
|
9 |
* Text Domain: astra-sites
|
19 |
}
|
20 |
|
21 |
if ( ! defined( 'ASTRA_SITES_VER' ) ) {
|
22 |
+
define( 'ASTRA_SITES_VER', '1.3.18' );
|
23 |
}
|
24 |
|
25 |
if ( ! defined( 'ASTRA_SITES_FILE' ) ) {
|
inc/assets/js/admin-page.js
CHANGED
@@ -930,7 +930,7 @@ var AstraSitesAjaxQueue = (function() {
|
|
930 |
*
|
931 |
* @param {string} data Error message.
|
932 |
*/
|
933 |
-
_importFailMessage: function( message
|
934 |
|
935 |
$('.astra-demo-import')
|
936 |
.addClass('go-pro button-primary')
|
@@ -940,40 +940,10 @@ var AstraSitesAjaxQueue = (function() {
|
|
940 |
.append('<i class="dashicons dashicons-external"></i>')
|
941 |
.removeClass('astra-demo-import');
|
942 |
|
943 |
-
|
944 |
-
if( 'undefined' === from ) {
|
945 |
|
946 |
-
|
947 |
-
|
948 |
-
$('.go-pro').attr('href', astraSitesAdmin.log.serverConfiguration );
|
949 |
-
|
950 |
-
// Add the import log file link.
|
951 |
-
} else {
|
952 |
-
|
953 |
-
$('.wp-full-overlay-header .go-pro').text( astraSitesAdmin.strings.importFailBtn );
|
954 |
-
$('.wp-full-overlay-footer .go-pro').text( astraSitesAdmin.strings.importFailBtnLarge )
|
955 |
-
|
956 |
-
// Add the import log file link.
|
957 |
-
if( 'undefined' !== AstraSitesAdmin.log_file_url ) {
|
958 |
-
$('.go-pro').attr('href', AstraSitesAdmin.log_file_url );
|
959 |
-
} else {
|
960 |
-
$('.go-pro').attr('href', astraSitesAdmin.log.serverConfiguration );
|
961 |
-
}
|
962 |
-
}
|
963 |
-
|
964 |
-
var output = '<div class="astra-api-error notice notice-error notice-alt is-dismissible">';
|
965 |
-
output += ' <p>'+message+'</p>';
|
966 |
-
output += ' <button type="button" class="notice-dismiss">';
|
967 |
-
output += ' <span class="screen-reader-text">'+commonL10n.dismiss+'</span>';
|
968 |
-
output += ' </button>';
|
969 |
-
output += '</div>';
|
970 |
-
|
971 |
-
// Fail Notice.
|
972 |
-
$('.install-theme-info').append( output );
|
973 |
-
|
974 |
-
// !important to add trigger.
|
975 |
-
// Which reinitialize the dismiss error message events.
|
976 |
-
$(document).trigger('wp-updates-notice-added');
|
977 |
},
|
978 |
|
979 |
|
@@ -1376,8 +1346,7 @@ var AstraSitesAjaxQueue = (function() {
|
|
1376 |
|
1377 |
// 1. Fail - Request Site Import
|
1378 |
if( false === demo_data.success ) {
|
1379 |
-
|
1380 |
-
|
1381 |
} else {
|
1382 |
|
1383 |
// Set log file URL.
|
930 |
*
|
931 |
* @param {string} data Error message.
|
932 |
*/
|
933 |
+
_importFailMessage: function( message ) {
|
934 |
|
935 |
$('.astra-demo-import')
|
936 |
.addClass('go-pro button-primary')
|
940 |
.append('<i class="dashicons dashicons-external"></i>')
|
941 |
.removeClass('astra-demo-import');
|
942 |
|
943 |
+
AstraSitesAdmin._log_title( message );
|
|
|
944 |
|
945 |
+
$('.wp-full-overlay-header .go-pro').text( astraSitesAdmin.strings.importFailBtn );
|
946 |
+
$('.wp-full-overlay-footer .go-pro').text( astraSitesAdmin.strings.importFailBtnLarge )
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
947 |
},
|
948 |
|
949 |
|
1346 |
|
1347 |
// 1. Fail - Request Site Import
|
1348 |
if( false === demo_data.success ) {
|
1349 |
+
AstraSitesAdmin._importFailMessage( demo_data.data );
|
|
|
1350 |
} else {
|
1351 |
|
1352 |
// Set log file URL.
|
inc/classes/class-astra-sites-importer.php
CHANGED
@@ -1,602 +1,605 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Astra Sites Importer
|
4 |
-
*
|
5 |
-
* @since 1.0.0
|
6 |
-
* @package Astra Sites
|
7 |
-
*/
|
8 |
-
|
9 |
-
defined( 'ABSPATH' ) or exit;
|
10 |
-
|
11 |
-
if ( ! class_exists( 'Astra_Sites_Importer' ) ) :
|
12 |
-
|
13 |
-
/**
|
14 |
-
* Astra Sites Importer
|
15 |
-
*/
|
16 |
-
class Astra_Sites_Importer {
|
17 |
-
|
18 |
-
/**
|
19 |
-
* Instance
|
20 |
-
*
|
21 |
-
* @since 1.0.0
|
22 |
-
* @var (Object) Class object
|
23 |
-
*/
|
24 |
-
public static $_instance = null;
|
25 |
-
|
26 |
-
/**
|
27 |
-
* Set Instance
|
28 |
-
*
|
29 |
-
* @since 1.0.0
|
30 |
-
*
|
31 |
-
* @return object Class object.
|
32 |
-
*/
|
33 |
-
public static function get_instance() {
|
34 |
-
if ( ! isset( self::$_instance ) ) {
|
35 |
-
self::$_instance = new self;
|
36 |
-
}
|
37 |
-
|
38 |
-
return self::$_instance;
|
39 |
-
}
|
40 |
-
|
41 |
-
/**
|
42 |
-
* Constructor.
|
43 |
-
*
|
44 |
-
* @since 1.0.0
|
45 |
-
*/
|
46 |
-
public function __construct() {
|
47 |
-
|
48 |
-
require_once ASTRA_SITES_DIR . 'inc/classes/class-astra-sites-importer-log.php';
|
49 |
-
require_once ASTRA_SITES_DIR . 'inc/importers/class-astra-sites-helper.php';
|
50 |
-
require_once ASTRA_SITES_DIR . 'inc/importers/class-widgets-importer.php';
|
51 |
-
require_once ASTRA_SITES_DIR . 'inc/importers/class-astra-customizer-import.php';
|
52 |
-
require_once ASTRA_SITES_DIR . 'inc/importers/class-astra-site-options-import.php';
|
53 |
-
|
54 |
-
// Import AJAX.
|
55 |
-
add_action( 'wp_ajax_astra-sites-import-set-site-data', array( $this, 'import_start' ) );
|
56 |
-
add_action( 'wp_ajax_astra-sites-import-wpforms', array( $this, 'import_wpforms' ) );
|
57 |
-
add_action( 'wp_ajax_astra-sites-import-customizer-settings', array( $this, 'import_customizer_settings' ) );
|
58 |
-
add_action( 'wp_ajax_astra-sites-import-prepare-xml', array( $this, 'prepare_xml_data' ) );
|
59 |
-
add_action( 'wp_ajax_astra-sites-import-options', array( $this, 'import_options' ) );
|
60 |
-
add_action( 'wp_ajax_astra-sites-import-widgets', array( $this, 'import_widgets' ) );
|
61 |
-
add_action( 'wp_ajax_astra-sites-import-end', array( $this, 'import_end' ) );
|
62 |
-
|
63 |
-
// Hooks in AJAX.
|
64 |
-
add_action( 'astra_sites_import_complete', array( $this, 'clear_cache' ) );
|
65 |
-
add_action( 'init', array( $this, 'load_importer' ) );
|
66 |
-
|
67 |
-
require_once ASTRA_SITES_DIR . 'inc/importers/batch-processing/class-astra-sites-batch-processing.php';
|
68 |
-
|
69 |
-
add_action( 'astra_sites_image_import_complete', array( $this, 'clear_cache' ) );
|
70 |
-
|
71 |
-
// Reset Customizer Data.
|
72 |
-
add_action( 'wp_ajax_astra-sites-reset-customizer-data', array( $this, 'reset_customizer_data' ) );
|
73 |
-
add_action( 'wp_ajax_astra-sites-reset-site-options', array( $this, 'reset_site_options' ) );
|
74 |
-
add_action( 'wp_ajax_astra-sites-reset-widgets-data', array( $this, 'reset_widgets_data' ) );
|
75 |
-
|
76 |
-
// Reset Post & Terms.
|
77 |
-
add_action( 'wp_ajax_astra-sites-delete-posts', array( $this, 'delete_imported_posts' ) );
|
78 |
-
add_action( 'wp_ajax_astra-sites-delete-wp-forms', array( $this, 'delete_imported_wp_forms' ) );
|
79 |
-
add_action( 'wp_ajax_astra-sites-delete-terms', array( $this, 'delete_imported_terms' ) );
|
80 |
-
|
81 |
-
if ( version_compare( get_bloginfo( 'version' ), '5.1.0', '>=' ) ) {
|
82 |
-
add_filter( 'http_request_timeout', array( $this, 'set_timeout_for_images' ), 10, 2 );
|
83 |
-
}
|
84 |
-
}
|
85 |
-
|
86 |
-
/**
|
87 |
-
* Set the timeout for the HTTP request by request URL.
|
88 |
-
*
|
89 |
-
* E.g. If URL is images (jpg|png|gif|jpeg) are from the domain `https://websitedemos.net` then we have set the timeout by 30 seconds. Default 5 seconds.
|
90 |
-
*
|
91 |
-
* @since 1.3.8
|
92 |
-
*
|
93 |
-
* @param int $timeout_value Time in seconds until a request times out. Default 5.
|
94 |
-
* @param string $url The request URL.
|
95 |
-
*/
|
96 |
-
function set_timeout_for_images( $timeout_value, $url ) {
|
97 |
-
|
98 |
-
// URL not contain `https://websitedemos.net` then return $timeout_value.
|
99 |
-
if ( strpos( $url, 'https://websitedemos.net' ) === false ) {
|
100 |
-
return $timeout_value;
|
101 |
-
}
|
102 |
-
|
103 |
-
// Check is image URL of type jpg|png|gif|jpeg.
|
104 |
-
if ( Astra_Sites_Image_Importer::get_instance()->is_image_url( $url ) ) {
|
105 |
-
$timeout_value = 30;
|
106 |
-
}
|
107 |
-
return $timeout_value;
|
108 |
-
}
|
109 |
-
|
110 |
-
/**
|
111 |
-
* Load WordPress WXR importer.
|
112 |
-
*/
|
113 |
-
public function load_importer() {
|
114 |
-
require_once ASTRA_SITES_DIR . 'inc/importers/wxr-importer/class-astra-wxr-importer.php';
|
115 |
-
}
|
116 |
-
|
117 |
-
/**
|
118 |
-
* Start Site Import
|
119 |
-
*
|
120 |
-
* @since 1.1.0
|
121 |
-
* @return void
|
122 |
-
*/
|
123 |
-
function import_start() {
|
124 |
-
|
125 |
-
if ( ! current_user_can( 'customize' ) ) {
|
126 |
-
wp_send_json_error( __( 'You have not "customize" access to import the Astra site.', 'astra-sites' ) );
|
127 |
-
}
|
128 |
-
|
129 |
-
$demo_api_uri = isset( $_POST['api_url'] ) ? esc_url( $_POST['api_url'] ) : '';
|
130 |
-
|
131 |
-
if ( ! empty( $demo_api_uri ) ) {
|
132 |
-
|
133 |
-
$demo_data = self::get_astra_single_demo( $demo_api_uri );
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
$log_file
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
*
|
157 |
-
*
|
158 |
-
*
|
159 |
-
*
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
$
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
$
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
'
|
192 |
-
'
|
193 |
-
'
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
'
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
*
|
230 |
-
*
|
231 |
-
* @
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
*
|
257 |
-
*
|
258 |
-
* @
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
$data
|
279 |
-
$data
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
*
|
295 |
-
*
|
296 |
-
* @
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
$options_importer
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
*
|
322 |
-
*
|
323 |
-
* @
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
$widgets_importer
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
*
|
352 |
-
*
|
353 |
-
* @
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
*
|
363 |
-
*
|
364 |
-
*
|
365 |
-
*
|
366 |
-
*
|
367 |
-
*
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
$
|
374 |
-
|
375 |
-
'
|
376 |
-
'astra-site-
|
377 |
-
'astra-site-
|
378 |
-
'astra-
|
379 |
-
'astra-
|
380 |
-
'astra-site-
|
381 |
-
'astra-
|
382 |
-
'astra-
|
383 |
-
'
|
384 |
-
'
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
'
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
$remote_args['
|
426 |
-
$remote_args['astra-
|
427 |
-
$remote_args['astra-site-
|
428 |
-
$remote_args['astra-site-
|
429 |
-
$remote_args['astra-
|
430 |
-
$remote_args['astra-
|
431 |
-
$remote_args['
|
432 |
-
$remote_args['astra-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
*
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
*
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
*
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
*
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
*
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
*
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Astra Sites Importer
|
4 |
+
*
|
5 |
+
* @since 1.0.0
|
6 |
+
* @package Astra Sites
|
7 |
+
*/
|
8 |
+
|
9 |
+
defined( 'ABSPATH' ) or exit;
|
10 |
+
|
11 |
+
if ( ! class_exists( 'Astra_Sites_Importer' ) ) :
|
12 |
+
|
13 |
+
/**
|
14 |
+
* Astra Sites Importer
|
15 |
+
*/
|
16 |
+
class Astra_Sites_Importer {
|
17 |
+
|
18 |
+
/**
|
19 |
+
* Instance
|
20 |
+
*
|
21 |
+
* @since 1.0.0
|
22 |
+
* @var (Object) Class object
|
23 |
+
*/
|
24 |
+
public static $_instance = null;
|
25 |
+
|
26 |
+
/**
|
27 |
+
* Set Instance
|
28 |
+
*
|
29 |
+
* @since 1.0.0
|
30 |
+
*
|
31 |
+
* @return object Class object.
|
32 |
+
*/
|
33 |
+
public static function get_instance() {
|
34 |
+
if ( ! isset( self::$_instance ) ) {
|
35 |
+
self::$_instance = new self;
|
36 |
+
}
|
37 |
+
|
38 |
+
return self::$_instance;
|
39 |
+
}
|
40 |
+
|
41 |
+
/**
|
42 |
+
* Constructor.
|
43 |
+
*
|
44 |
+
* @since 1.0.0
|
45 |
+
*/
|
46 |
+
public function __construct() {
|
47 |
+
|
48 |
+
require_once ASTRA_SITES_DIR . 'inc/classes/class-astra-sites-importer-log.php';
|
49 |
+
require_once ASTRA_SITES_DIR . 'inc/importers/class-astra-sites-helper.php';
|
50 |
+
require_once ASTRA_SITES_DIR . 'inc/importers/class-widgets-importer.php';
|
51 |
+
require_once ASTRA_SITES_DIR . 'inc/importers/class-astra-customizer-import.php';
|
52 |
+
require_once ASTRA_SITES_DIR . 'inc/importers/class-astra-site-options-import.php';
|
53 |
+
|
54 |
+
// Import AJAX.
|
55 |
+
add_action( 'wp_ajax_astra-sites-import-set-site-data', array( $this, 'import_start' ) );
|
56 |
+
add_action( 'wp_ajax_astra-sites-import-wpforms', array( $this, 'import_wpforms' ) );
|
57 |
+
add_action( 'wp_ajax_astra-sites-import-customizer-settings', array( $this, 'import_customizer_settings' ) );
|
58 |
+
add_action( 'wp_ajax_astra-sites-import-prepare-xml', array( $this, 'prepare_xml_data' ) );
|
59 |
+
add_action( 'wp_ajax_astra-sites-import-options', array( $this, 'import_options' ) );
|
60 |
+
add_action( 'wp_ajax_astra-sites-import-widgets', array( $this, 'import_widgets' ) );
|
61 |
+
add_action( 'wp_ajax_astra-sites-import-end', array( $this, 'import_end' ) );
|
62 |
+
|
63 |
+
// Hooks in AJAX.
|
64 |
+
add_action( 'astra_sites_import_complete', array( $this, 'clear_cache' ) );
|
65 |
+
add_action( 'init', array( $this, 'load_importer' ) );
|
66 |
+
|
67 |
+
require_once ASTRA_SITES_DIR . 'inc/importers/batch-processing/class-astra-sites-batch-processing.php';
|
68 |
+
|
69 |
+
add_action( 'astra_sites_image_import_complete', array( $this, 'clear_cache' ) );
|
70 |
+
|
71 |
+
// Reset Customizer Data.
|
72 |
+
add_action( 'wp_ajax_astra-sites-reset-customizer-data', array( $this, 'reset_customizer_data' ) );
|
73 |
+
add_action( 'wp_ajax_astra-sites-reset-site-options', array( $this, 'reset_site_options' ) );
|
74 |
+
add_action( 'wp_ajax_astra-sites-reset-widgets-data', array( $this, 'reset_widgets_data' ) );
|
75 |
+
|
76 |
+
// Reset Post & Terms.
|
77 |
+
add_action( 'wp_ajax_astra-sites-delete-posts', array( $this, 'delete_imported_posts' ) );
|
78 |
+
add_action( 'wp_ajax_astra-sites-delete-wp-forms', array( $this, 'delete_imported_wp_forms' ) );
|
79 |
+
add_action( 'wp_ajax_astra-sites-delete-terms', array( $this, 'delete_imported_terms' ) );
|
80 |
+
|
81 |
+
if ( version_compare( get_bloginfo( 'version' ), '5.1.0', '>=' ) ) {
|
82 |
+
add_filter( 'http_request_timeout', array( $this, 'set_timeout_for_images' ), 10, 2 );
|
83 |
+
}
|
84 |
+
}
|
85 |
+
|
86 |
+
/**
|
87 |
+
* Set the timeout for the HTTP request by request URL.
|
88 |
+
*
|
89 |
+
* E.g. If URL is images (jpg|png|gif|jpeg) are from the domain `https://websitedemos.net` then we have set the timeout by 30 seconds. Default 5 seconds.
|
90 |
+
*
|
91 |
+
* @since 1.3.8
|
92 |
+
*
|
93 |
+
* @param int $timeout_value Time in seconds until a request times out. Default 5.
|
94 |
+
* @param string $url The request URL.
|
95 |
+
*/
|
96 |
+
function set_timeout_for_images( $timeout_value, $url ) {
|
97 |
+
|
98 |
+
// URL not contain `https://websitedemos.net` then return $timeout_value.
|
99 |
+
if ( strpos( $url, 'https://websitedemos.net' ) === false ) {
|
100 |
+
return $timeout_value;
|
101 |
+
}
|
102 |
+
|
103 |
+
// Check is image URL of type jpg|png|gif|jpeg.
|
104 |
+
if ( Astra_Sites_Image_Importer::get_instance()->is_image_url( $url ) ) {
|
105 |
+
$timeout_value = 30;
|
106 |
+
}
|
107 |
+
return $timeout_value;
|
108 |
+
}
|
109 |
+
|
110 |
+
/**
|
111 |
+
* Load WordPress WXR importer.
|
112 |
+
*/
|
113 |
+
public function load_importer() {
|
114 |
+
require_once ASTRA_SITES_DIR . 'inc/importers/wxr-importer/class-astra-wxr-importer.php';
|
115 |
+
}
|
116 |
+
|
117 |
+
/**
|
118 |
+
* Start Site Import
|
119 |
+
*
|
120 |
+
* @since 1.1.0
|
121 |
+
* @return void
|
122 |
+
*/
|
123 |
+
function import_start() {
|
124 |
+
|
125 |
+
if ( ! current_user_can( 'customize' ) ) {
|
126 |
+
wp_send_json_error( __( 'You have not "customize" access to import the Astra site.', 'astra-sites' ) );
|
127 |
+
}
|
128 |
+
|
129 |
+
$demo_api_uri = isset( $_POST['api_url'] ) ? esc_url( $_POST['api_url'] ) : '';
|
130 |
+
|
131 |
+
if ( ! empty( $demo_api_uri ) ) {
|
132 |
+
|
133 |
+
$demo_data = self::get_astra_single_demo( $demo_api_uri );
|
134 |
+
update_option( 'astra_sites_import_data', $demo_data );
|
135 |
+
|
136 |
+
if ( is_wp_error( $demo_data ) ) {
|
137 |
+
wp_send_json_error( $demo_data->get_error_message() );
|
138 |
+
} else {
|
139 |
+
$log_file = Astra_Sites_Importer_Log::add_log_file_url();
|
140 |
+
if ( isset( $log_file['url'] ) && ! empty( $log_file['url'] ) ) {
|
141 |
+
$demo_data['log_file'] = $log_file['url'];
|
142 |
+
}
|
143 |
+
do_action( 'astra_sites_import_start', $demo_data, $demo_api_uri );
|
144 |
+
}
|
145 |
+
|
146 |
+
wp_send_json_success( $demo_data );
|
147 |
+
|
148 |
+
} else {
|
149 |
+
wp_send_json_error( __( 'Request site API URL is empty. Try again!', 'astra-sites' ) );
|
150 |
+
}
|
151 |
+
|
152 |
+
}
|
153 |
+
|
154 |
+
/**
|
155 |
+
* Import WP Forms
|
156 |
+
*
|
157 |
+
* @since 1.2.14
|
158 |
+
*
|
159 |
+
* @return void
|
160 |
+
*/
|
161 |
+
function import_wpforms() {
|
162 |
+
|
163 |
+
$wpforms_url = ( isset( $_REQUEST['wpforms_url'] ) ) ? urldecode( $_REQUEST['wpforms_url'] ) : '';
|
164 |
+
$ids_mapping = array();
|
165 |
+
|
166 |
+
if ( ! empty( $wpforms_url ) && function_exists( 'wpforms_encode' ) ) {
|
167 |
+
|
168 |
+
// Download XML file.
|
169 |
+
$xml_path = Astra_Sites_Helper::download_file( $wpforms_url );
|
170 |
+
|
171 |
+
if ( $xml_path['success'] ) {
|
172 |
+
if ( isset( $xml_path['data']['file'] ) ) {
|
173 |
+
|
174 |
+
$ext = strtolower( pathinfo( $xml_path['data']['file'], PATHINFO_EXTENSION ) );
|
175 |
+
|
176 |
+
if ( 'json' === $ext ) {
|
177 |
+
$forms = json_decode( file_get_contents( $xml_path['data']['file'] ), true );
|
178 |
+
|
179 |
+
if ( ! empty( $forms ) ) {
|
180 |
+
|
181 |
+
foreach ( $forms as $form ) {
|
182 |
+
$title = ! empty( $form['settings']['form_title'] ) ? $form['settings']['form_title'] : '';
|
183 |
+
$desc = ! empty( $form['settings']['form_desc'] ) ? $form['settings']['form_desc'] : '';
|
184 |
+
|
185 |
+
$new_id = post_exists( $title );
|
186 |
+
|
187 |
+
if ( ! $new_id ) {
|
188 |
+
$new_id = wp_insert_post(
|
189 |
+
array(
|
190 |
+
'post_title' => $title,
|
191 |
+
'post_status' => 'publish',
|
192 |
+
'post_type' => 'wpforms',
|
193 |
+
'post_excerpt' => $desc,
|
194 |
+
)
|
195 |
+
);
|
196 |
+
|
197 |
+
// Set meta for tracking the post.
|
198 |
+
update_post_meta( $new_id, '_astra_sites_imported_wp_forms', true );
|
199 |
+
Astra_Sites_Importer_Log::add( 'Inserted WP Form ' . $new_id );
|
200 |
+
}
|
201 |
+
|
202 |
+
if ( $new_id ) {
|
203 |
+
|
204 |
+
// ID mapping.
|
205 |
+
$ids_mapping[ $form['id'] ] = $new_id;
|
206 |
+
|
207 |
+
$form['id'] = $new_id;
|
208 |
+
wp_update_post(
|
209 |
+
array(
|
210 |
+
'ID' => $new_id,
|
211 |
+
'post_content' => wpforms_encode( $form ),
|
212 |
+
)
|
213 |
+
);
|
214 |
+
}
|
215 |
+
}
|
216 |
+
}
|
217 |
+
}
|
218 |
+
}
|
219 |
+
}
|
220 |
+
}
|
221 |
+
|
222 |
+
update_option( 'astra_sites_wpforms_ids_mapping', $ids_mapping );
|
223 |
+
|
224 |
+
wp_send_json_success( $ids_mapping );
|
225 |
+
}
|
226 |
+
|
227 |
+
/**
|
228 |
+
* Import Customizer Settings.
|
229 |
+
*
|
230 |
+
* @since 1.0.14
|
231 |
+
* @return void
|
232 |
+
*/
|
233 |
+
function import_customizer_settings() {
|
234 |
+
|
235 |
+
$customizer_data = ( isset( $_POST['customizer_data'] ) ) ? (array) json_decode( stripcslashes( $_POST['customizer_data'] ), 1 ) : array();
|
236 |
+
|
237 |
+
if ( ! empty( $customizer_data ) ) {
|
238 |
+
|
239 |
+
Astra_Sites_Importer_Log::add( 'Imported Customizer Settings ' . json_encode( $customizer_data ) );
|
240 |
+
|
241 |
+
// Set meta for tracking the post.
|
242 |
+
update_option( '_astra_sites_old_customizer_data', $customizer_data );
|
243 |
+
|
244 |
+
Astra_Customizer_Import::instance()->import( $customizer_data );
|
245 |
+
|
246 |
+
wp_send_json_success( $customizer_data );
|
247 |
+
|
248 |
+
} else {
|
249 |
+
wp_send_json_error( __( 'Customizer data is empty!', 'astra-sites' ) );
|
250 |
+
}
|
251 |
+
|
252 |
+
}
|
253 |
+
|
254 |
+
/**
|
255 |
+
* Prepare XML Data.
|
256 |
+
*
|
257 |
+
* @since 1.1.0
|
258 |
+
* @return void
|
259 |
+
*/
|
260 |
+
function prepare_xml_data() {
|
261 |
+
|
262 |
+
if ( ! class_exists( 'XMLReader' ) ) {
|
263 |
+
wp_send_json_error( __( 'If XMLReader is not available, it imports all other settings and only skips XML import. This creates an incomplete website. We should bail early and not import anything if this is not present.', 'astra-sites' ) );
|
264 |
+
}
|
265 |
+
|
266 |
+
$wxr_url = ( isset( $_REQUEST['wxr_url'] ) ) ? urldecode( $_REQUEST['wxr_url'] ) : '';
|
267 |
+
|
268 |
+
if ( isset( $wxr_url ) ) {
|
269 |
+
|
270 |
+
Astra_Sites_Importer_Log::add( 'Importing from XML ' . $wxr_url );
|
271 |
+
|
272 |
+
// Download XML file.
|
273 |
+
$xml_path = Astra_Sites_Helper::download_file( $wxr_url );
|
274 |
+
|
275 |
+
if ( $xml_path['success'] ) {
|
276 |
+
if ( isset( $xml_path['data']['file'] ) ) {
|
277 |
+
$data = Astra_WXR_Importer::instance()->get_xml_data( $xml_path['data']['file'] );
|
278 |
+
$data['xml'] = $xml_path['data'];
|
279 |
+
wp_send_json_success( $data );
|
280 |
+
} else {
|
281 |
+
wp_send_json_error( __( 'There was an error downloading the XML file.', 'astra-sites' ) );
|
282 |
+
}
|
283 |
+
} else {
|
284 |
+
wp_send_json_error( $xml_path['data'] );
|
285 |
+
}
|
286 |
+
} else {
|
287 |
+
wp_send_json_error( __( 'Invalid site XML file!', 'astra-sites' ) );
|
288 |
+
}
|
289 |
+
|
290 |
+
}
|
291 |
+
|
292 |
+
/**
|
293 |
+
* Import Options.
|
294 |
+
*
|
295 |
+
* @since 1.0.14
|
296 |
+
* @return void
|
297 |
+
*/
|
298 |
+
function import_options() {
|
299 |
+
|
300 |
+
$options_data = ( isset( $_POST['options_data'] ) ) ? (array) json_decode( stripcslashes( $_POST['options_data'] ), 1 ) : '';
|
301 |
+
|
302 |
+
if ( ! empty( $options_data ) ) {
|
303 |
+
|
304 |
+
// Set meta for tracking the post.
|
305 |
+
if ( is_array( $options_data ) ) {
|
306 |
+
Astra_Sites_Importer_Log::add( 'Imported - Site Options ' . json_encode( $options_data ) );
|
307 |
+
update_option( '_astra_sites_old_site_options', $options_data );
|
308 |
+
}
|
309 |
+
|
310 |
+
$options_importer = Astra_Site_Options_Import::instance();
|
311 |
+
$options_importer->import_options( $options_data );
|
312 |
+
wp_send_json_success( $options_data );
|
313 |
+
} else {
|
314 |
+
wp_send_json_error( __( 'Site options are empty!', 'astra-sites' ) );
|
315 |
+
}
|
316 |
+
|
317 |
+
}
|
318 |
+
|
319 |
+
/**
|
320 |
+
* Import Widgets.
|
321 |
+
*
|
322 |
+
* @since 1.0.14
|
323 |
+
* @return void
|
324 |
+
*/
|
325 |
+
function import_widgets() {
|
326 |
+
|
327 |
+
$widgets_data = ( isset( $_POST['widgets_data'] ) ) ? (object) json_decode( stripcslashes( $_POST['widgets_data'] ) ) : '';
|
328 |
+
|
329 |
+
Astra_Sites_Importer_Log::add( 'Imported - Widgets ' . json_encode( $widgets_data ) );
|
330 |
+
|
331 |
+
if ( ! empty( $widgets_data ) ) {
|
332 |
+
|
333 |
+
$widgets_importer = Astra_Widget_Importer::instance();
|
334 |
+
$status = $widgets_importer->import_widgets_data( $widgets_data );
|
335 |
+
|
336 |
+
// Set meta for tracking the post.
|
337 |
+
if ( is_object( $widgets_data ) ) {
|
338 |
+
$widgets_data = (array) $widgets_data;
|
339 |
+
update_option( '_astra_sites_old_widgets_data', $widgets_data );
|
340 |
+
}
|
341 |
+
|
342 |
+
wp_send_json_success( $widgets_data );
|
343 |
+
} else {
|
344 |
+
wp_send_json_error( __( 'Widget data is empty!', 'astra-sites' ) );
|
345 |
+
}
|
346 |
+
|
347 |
+
}
|
348 |
+
|
349 |
+
/**
|
350 |
+
* Import End.
|
351 |
+
*
|
352 |
+
* @since 1.0.14
|
353 |
+
* @return void
|
354 |
+
*/
|
355 |
+
function import_end() {
|
356 |
+
do_action( 'astra_sites_import_complete' );
|
357 |
+
}
|
358 |
+
|
359 |
+
|
360 |
+
/**
|
361 |
+
* Get single demo.
|
362 |
+
*
|
363 |
+
* @since 1.0.0
|
364 |
+
*
|
365 |
+
* @param (String) $demo_api_uri API URL of a demo.
|
366 |
+
*
|
367 |
+
* @return (Array) $astra_demo_data demo data for the demo.
|
368 |
+
*/
|
369 |
+
public static function get_astra_single_demo( $demo_api_uri ) {
|
370 |
+
|
371 |
+
// default values.
|
372 |
+
$remote_args = array();
|
373 |
+
$defaults = array(
|
374 |
+
'id' => '',
|
375 |
+
'astra-site-widgets-data' => '',
|
376 |
+
'astra-site-customizer-data' => '',
|
377 |
+
'astra-site-options-data' => '',
|
378 |
+
'astra-post-data-mapping' => '',
|
379 |
+
'astra-site-wxr-path' => '',
|
380 |
+
'astra-site-wpforms-path' => '',
|
381 |
+
'astra-enabled-extensions' => '',
|
382 |
+
'astra-custom-404' => '',
|
383 |
+
'required-plugins' => '',
|
384 |
+
'astra-site-taxonomy-mapping' => '',
|
385 |
+
);
|
386 |
+
|
387 |
+
$api_args = apply_filters(
|
388 |
+
'astra_sites_api_args',
|
389 |
+
array(
|
390 |
+
'timeout' => 15,
|
391 |
+
)
|
392 |
+
);
|
393 |
+
|
394 |
+
// Use this for premium demos.
|
395 |
+
$request_params = apply_filters(
|
396 |
+
'astra_sites_api_params',
|
397 |
+
array(
|
398 |
+
'purchase_key' => '',
|
399 |
+
'site_url' => '',
|
400 |
+
)
|
401 |
+
);
|
402 |
+
|
403 |
+
$demo_api_uri = add_query_arg( $request_params, $demo_api_uri );
|
404 |
+
|
405 |
+
// API Call.
|
406 |
+
$response = wp_remote_get( $demo_api_uri, $api_args );
|
407 |
+
|
408 |
+
if ( is_wp_error( $response ) || ( isset( $response->status ) && 0 === $response->status ) ) {
|
409 |
+
if ( isset( $response->status ) ) {
|
410 |
+
$data = json_decode( $response, true );
|
411 |
+
} else {
|
412 |
+
return new WP_Error( 'api_invalid_response_code', $response->get_error_message() );
|
413 |
+
}
|
414 |
+
}
|
415 |
+
|
416 |
+
if ( wp_remote_retrieve_response_code( $response ) !== 200 ) {
|
417 |
+
return new WP_Error( 'api_invalid_response_code', wp_remote_retrieve_body( $response ) );
|
418 |
+
} else {
|
419 |
+
$data = json_decode( wp_remote_retrieve_body( $response ), true );
|
420 |
+
}
|
421 |
+
|
422 |
+
$data = json_decode( wp_remote_retrieve_body( $response ), true );
|
423 |
+
|
424 |
+
if ( ! isset( $data['code'] ) ) {
|
425 |
+
$remote_args['id'] = $data['id'];
|
426 |
+
$remote_args['astra-site-widgets-data'] = json_decode( $data['astra-site-widgets-data'] );
|
427 |
+
$remote_args['astra-site-customizer-data'] = $data['astra-site-customizer-data'];
|
428 |
+
$remote_args['astra-site-options-data'] = $data['astra-site-options-data'];
|
429 |
+
$remote_args['astra-post-data-mapping'] = $data['astra-post-data-mapping'];
|
430 |
+
$remote_args['astra-site-wxr-path'] = $data['astra-site-wxr-path'];
|
431 |
+
$remote_args['astra-site-wpforms-path'] = $data['astra-site-wpforms-path'];
|
432 |
+
$remote_args['astra-enabled-extensions'] = $data['astra-enabled-extensions'];
|
433 |
+
$remote_args['astra-custom-404'] = $data['astra-custom-404'];
|
434 |
+
$remote_args['required-plugins'] = $data['required-plugins'];
|
435 |
+
$remote_args['astra-site-taxonomy-mapping'] = $data['astra-site-taxonomy-mapping'];
|
436 |
+
}
|
437 |
+
|
438 |
+
// Merge remote demo and defaults.
|
439 |
+
return wp_parse_args( $remote_args, $defaults );
|
440 |
+
}
|
441 |
+
|
442 |
+
/**
|
443 |
+
* Clear Cache.
|
444 |
+
*
|
445 |
+
* @since 1.0.9
|
446 |
+
*/
|
447 |
+
public function clear_cache() {
|
448 |
+
// Clear 'Elementor' file cache.
|
449 |
+
if ( class_exists( '\Elementor\Plugin' ) ) {
|
450 |
+
Elementor\Plugin::$instance->posts_css_manager->clear_cache();
|
451 |
+
}
|
452 |
+
|
453 |
+
// Clear 'Builder Builder' cache.
|
454 |
+
if ( is_callable( 'FLBuilderModel::delete_asset_cache_for_all_posts' ) ) {
|
455 |
+
FLBuilderModel::delete_asset_cache_for_all_posts();
|
456 |
+
}
|
457 |
+
|
458 |
+
// Clear 'Astra Addon' cache.
|
459 |
+
if ( is_callable( 'Astra_Minify::refresh_assets' ) ) {
|
460 |
+
Astra_Minify::refresh_assets();
|
461 |
+
}
|
462 |
+
|
463 |
+
Astra_Sites_Importer_Log::add( 'Complete ' );
|
464 |
+
}
|
465 |
+
|
466 |
+
/**
|
467 |
+
* Reset customizer data
|
468 |
+
*
|
469 |
+
* @since 1.3.0
|
470 |
+
* @return void
|
471 |
+
*/
|
472 |
+
function reset_customizer_data() {
|
473 |
+
Astra_Sites_Importer_Log::add( 'Deleted customizer Settings ' . json_encode( get_option( 'astra-settings', array() ) ) );
|
474 |
+
|
475 |
+
delete_option( 'astra-settings' );
|
476 |
+
|
477 |
+
wp_send_json_success();
|
478 |
+
}
|
479 |
+
|
480 |
+
/**
|
481 |
+
* Reset site options
|
482 |
+
*
|
483 |
+
* @since 1.3.0
|
484 |
+
* @return void
|
485 |
+
*/
|
486 |
+
function reset_site_options() {
|
487 |
+
|
488 |
+
$options = get_option( '_astra_sites_old_site_options', array() );
|
489 |
+
|
490 |
+
Astra_Sites_Importer_Log::add( 'Deleted - Site Options ' . json_encode( $options ) );
|
491 |
+
|
492 |
+
if ( $options ) {
|
493 |
+
foreach ( $options as $option_key => $option_value ) {
|
494 |
+
delete_option( $option_key );
|
495 |
+
}
|
496 |
+
}
|
497 |
+
|
498 |
+
wp_send_json_success();
|
499 |
+
}
|
500 |
+
|
501 |
+
/**
|
502 |
+
* Reset widgets data
|
503 |
+
*
|
504 |
+
* @since 1.3.0
|
505 |
+
* @return void
|
506 |
+
*/
|
507 |
+
function reset_widgets_data() {
|
508 |
+
$old_widgets = get_option( '_astra_sites_old_widgets_data', array() );
|
509 |
+
|
510 |
+
Astra_Sites_Importer_Log::add( 'DELETED - WIDGETS ' . json_encode( $old_widgets ) );
|
511 |
+
|
512 |
+
if ( $old_widgets ) {
|
513 |
+
$sidebars_widgets = get_option( 'sidebars_widgets', array() );
|
514 |
+
|
515 |
+
foreach ( $old_widgets as $sidebar_id => $widgets ) {
|
516 |
+
|
517 |
+
if ( $widgets ) {
|
518 |
+
foreach ( $widgets as $widget_key => $widget_data ) {
|
519 |
+
|
520 |
+
if ( isset( $sidebars_widgets['wp_inactive_widgets'] ) ) {
|
521 |
+
if ( ! in_array( $widget_key, $sidebars_widgets['wp_inactive_widgets'], true ) ) {
|
522 |
+
$sidebars_widgets['wp_inactive_widgets'][] = $widget_key;
|
523 |
+
}
|
524 |
+
}
|
525 |
+
}
|
526 |
+
}
|
527 |
+
}
|
528 |
+
|
529 |
+
update_option( 'sidebars_widgets', $sidebars_widgets );
|
530 |
+
}
|
531 |
+
|
532 |
+
wp_send_json_success();
|
533 |
+
}
|
534 |
+
|
535 |
+
/**
|
536 |
+
* Delete imported posts
|
537 |
+
*
|
538 |
+
* @since 1.3.0
|
539 |
+
* @return void
|
540 |
+
*/
|
541 |
+
function delete_imported_posts() {
|
542 |
+
$post_id = isset( $_REQUEST['post_id'] ) ? absint( $_REQUEST['post_id'] ) : '';
|
543 |
+
$message = 'Deleted - Post ID ' . $post_id . ' - ' . get_post_type( $post_id ) . ' - ' . get_the_title( $post_id );
|
544 |
+
|
545 |
+
Astra_Sites_Importer_Log::add( $message );
|
546 |
+
wp_delete_post( $post_id, true );
|
547 |
+
|
548 |
+
/* translators: %s is the post ID */
|
549 |
+
wp_send_json_success( $message );
|
550 |
+
}
|
551 |
+
|
552 |
+
/**
|
553 |
+
* Delete imported WP forms
|
554 |
+
*
|
555 |
+
* @since 1.3.0
|
556 |
+
* @return void
|
557 |
+
*/
|
558 |
+
function delete_imported_wp_forms() {
|
559 |
+
$post_id = isset( $_REQUEST['post_id'] ) ? absint( $_REQUEST['post_id'] ) : '';
|
560 |
+
|
561 |
+
$message = 'Deleted - Form ID ' . $post_id . ' - ' . get_post_type( $post_id ) . ' - ' . get_the_title( $post_id );
|
562 |
+
|
563 |
+
Astra_Sites_Importer_Log::add( $message );
|
564 |
+
|
565 |
+
wp_delete_post( $post_id, true );
|
566 |
+
|
567 |
+
/* translators: %s is the form ID */
|
568 |
+
wp_send_json_success( $message );
|
569 |
+
}
|
570 |
+
|
571 |
+
/**
|
572 |
+
* Delete imported terms
|
573 |
+
*
|
574 |
+
* @since 1.3.0
|
575 |
+
* @return void
|
576 |
+
*/
|
577 |
+
function delete_imported_terms() {
|
578 |
+
|
579 |
+
$term_id = isset( $_REQUEST['term_id'] ) ? absint( $_REQUEST['term_id'] ) : '';
|
580 |
+
|
581 |
+
$message = '';
|
582 |
+
|
583 |
+
if ( $term_id ) {
|
584 |
+
$term = get_term( $term_id );
|
585 |
+
if ( $term ) {
|
586 |
+
$message = 'Deleted - Term ' . $term_id . ' - ' . $term->name . ' ' . $term->taxonomy;
|
587 |
+
Astra_Sites_Importer_Log::add( $message );
|
588 |
+
wp_delete_term( $term_id, $term->taxonomy );
|
589 |
+
}
|
590 |
+
}
|
591 |
+
|
592 |
+
/* translators: %s is the term ID */
|
593 |
+
wp_send_json_success( $message );
|
594 |
+
}
|
595 |
+
|
596 |
+
}
|
597 |
+
|
598 |
+
/**
|
599 |
+
* Kicking this off by calling 'get_instance()' method
|
600 |
+
*/
|
601 |
+
Astra_Sites_Importer::get_instance();
|
602 |
+
|
603 |
+
endif;
|
604 |
+
|
605 |
+
|
inc/classes/class-astra-sites-page.php
CHANGED
@@ -1,434 +1,434 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Astra Sites Page
|
4 |
-
*
|
5 |
-
* @since 1.0.6
|
6 |
-
* @package Astra Sites
|
7 |
-
*/
|
8 |
-
|
9 |
-
if ( ! defined( 'ABSPATH' ) ) {
|
10 |
-
exit;
|
11 |
-
}
|
12 |
-
|
13 |
-
if ( ! class_exists( 'Astra_Sites_Page' ) ) {
|
14 |
-
|
15 |
-
/**
|
16 |
-
* Astra Admin Settings
|
17 |
-
*/
|
18 |
-
class Astra_Sites_Page {
|
19 |
-
|
20 |
-
/**
|
21 |
-
* View all actions
|
22 |
-
*
|
23 |
-
* @since 1.0.6
|
24 |
-
* @var array $view_actions
|
25 |
-
*/
|
26 |
-
public $view_actions = array();
|
27 |
-
|
28 |
-
/**
|
29 |
-
* Member Variable
|
30 |
-
*
|
31 |
-
* @var instance
|
32 |
-
*/
|
33 |
-
private static $instance;
|
34 |
-
|
35 |
-
/**
|
36 |
-
* Initiator
|
37 |
-
*
|
38 |
-
* @since 1.3.0
|
39 |
-
*/
|
40 |
-
public static function get_instance() {
|
41 |
-
if ( ! isset( self::$instance ) ) {
|
42 |
-
self::$instance = new self;
|
43 |
-
}
|
44 |
-
return self::$instance;
|
45 |
-
}
|
46 |
-
|
47 |
-
/**
|
48 |
-
* Constructor
|
49 |
-
*
|
50 |
-
* @since 1.3.0
|
51 |
-
*/
|
52 |
-
public function __construct() {
|
53 |
-
|
54 |
-
if ( ! is_admin() ) {
|
55 |
-
return;
|
56 |
-
}
|
57 |
-
|
58 |
-
add_action( 'after_setup_theme', array( $this, 'init_admin_settings' ), 99 );
|
59 |
-
add_action( 'admin_init', array( $this, 'save_page_builder' ) );
|
60 |
-
add_action( 'admin_notices', array( $this, 'getting_started' ) );
|
61 |
-
}
|
62 |
-
|
63 |
-
/**
|
64 |
-
* Admin notice
|
65 |
-
*
|
66 |
-
* @since 1.3.5
|
67 |
-
*
|
68 |
-
* @return void
|
69 |
-
*/
|
70 |
-
function getting_started() {
|
71 |
-
if ( 'plugins' !== get_current_screen()->base ) {
|
72 |
-
return;
|
73 |
-
}
|
74 |
-
|
75 |
-
$processed = get_user_meta( get_current_user_id(), '_astra_sites_gettings_started', true );
|
76 |
-
$product_name = Astra_Sites_White_Label::get_instance()->page_title( 'Astra' );
|
77 |
-
|
78 |
-
if ( $processed ) {
|
79 |
-
return;
|
80 |
-
}
|
81 |
-
|
82 |
-
?>
|
83 |
-
<div class="notice notice-info is-dismissible astra-sites-getting-started-notice">
|
84 |
-
<?php /* translators: %1$s is the admin page URL, %2$s is product name. */ ?>
|
85 |
-
<p><?php printf( __( 'Thank you for choosing %1$s! Check the library of <a class="astra-sites-getting-started-btn" href="%2$s">ready starter sites here »</a>', 'astra-sites' ), $product_name, admin_url( 'themes.php?page=astra-sites' ) ); ?></p>
|
86 |
-
</div>
|
87 |
-
<?php
|
88 |
-
}
|
89 |
-
|
90 |
-
/**
|
91 |
-
* Save Page Builder
|
92 |
-
*
|
93 |
-
* @return void
|
94 |
-
*/
|
95 |
-
function save_page_builder() {
|
96 |
-
|
97 |
-
// Only admins can save settings.
|
98 |
-
if ( ! current_user_can( 'manage_options' ) ) {
|
99 |
-
return;
|
100 |
-
}
|
101 |
-
|
102 |
-
// Make sure we have a valid nonce.
|
103 |
-
if ( isset( $_REQUEST['astra-sites-page-builder'] ) && wp_verify_nonce( $_REQUEST['astra-sites-page-builder'], 'astra-sites-welcome-screen' ) ) {
|
104 |
-
|
105 |
-
// Stored Settings.
|
106 |
-
$stored_data = $this->get_settings();
|
107 |
-
|
108 |
-
// New settings.
|
109 |
-
$new_data = array(
|
110 |
-
'page_builder' => ( isset( $_REQUEST['page_builder'] ) ) ? sanitize_key( $_REQUEST['page_builder'] ) : '',
|
111 |
-
);
|
112 |
-
|
113 |
-
// Merge settings.
|
114 |
-
$data = wp_parse_args( $new_data, $stored_data );
|
115 |
-
|
116 |
-
// Update settings.
|
117 |
-
update_option( 'astra_sites_settings', $data );
|
118 |
-
|
119 |
-
wp_redirect( admin_url( '/themes.php?page=astra-sites' ) );
|
120 |
-
}
|
121 |
-
}
|
122 |
-
|
123 |
-
/**
|
124 |
-
* Get single setting value
|
125 |
-
*
|
126 |
-
* @param string $key Setting key.
|
127 |
-
* @param mixed $defaults Setting value.
|
128 |
-
* @return mixed Stored setting value.
|
129 |
-
*/
|
130 |
-
function get_setting( $key = '', $defaults = '' ) {
|
131 |
-
|
132 |
-
$settings = $this->get_settings();
|
133 |
-
|
134 |
-
if ( empty( $settings ) ) {
|
135 |
-
return $defaults;
|
136 |
-
}
|
137 |
-
|
138 |
-
if ( array_key_exists( $key, $settings ) ) {
|
139 |
-
return $settings[ $key ];
|
140 |
-
}
|
141 |
-
|
142 |
-
return $defaults;
|
143 |
-
}
|
144 |
-
|
145 |
-
/**
|
146 |
-
* Get Settings
|
147 |
-
*
|
148 |
-
* @return array Stored settings.
|
149 |
-
*/
|
150 |
-
function get_settings() {
|
151 |
-
|
152 |
-
$defaults = array(
|
153 |
-
'page_builder' => '',
|
154 |
-
);
|
155 |
-
|
156 |
-
$stored_data = get_option( 'astra_sites_settings', $defaults );
|
157 |
-
|
158 |
-
return wp_parse_args( $stored_data, $defaults );
|
159 |
-
}
|
160 |
-
|
161 |
-
/**
|
162 |
-
* Admin settings init
|
163 |
-
*/
|
164 |
-
public function init_admin_settings() {
|
165 |
-
add_action( 'admin_menu', array( $this, 'add_admin_menu' ), 100 );
|
166 |
-
add_action( 'admin_notices', array( $this, 'notices' ) );
|
167 |
-
add_action( 'astra_sites_menu_general_action', array( $this, 'general_page' ) );
|
168 |
-
}
|
169 |
-
|
170 |
-
/**
|
171 |
-
* Admin notice
|
172 |
-
*
|
173 |
-
* @since 1.2.8
|
174 |
-
*/
|
175 |
-
public function notices() {
|
176 |
-
|
177 |
-
if ( 'appearance_page_astra-sites' !== get_current_screen()->id ) {
|
178 |
-
return;
|
179 |
-
}
|
180 |
-
|
181 |
-
if ( ! class_exists( 'XMLReader' ) ) {
|
182 |
-
?>
|
183 |
-
<div class="notice astra-sites-xml-notice notice-error">
|
184 |
-
<p><b><?php _e( 'Required XMLReader PHP extension is missing on your server!', 'astra-sites' ); ?></b></p>
|
185 |
-
<?php /* translators: %s is the white label name. */ ?>
|
186 |
-
<p><?php printf( __( '%s import requires XMLReader extension to be installed. Please contact your web hosting provider and ask them to install and activate the XMLReader PHP extension.', 'astra-sites' ), ASTRA_SITES_NAME ); ?></p>
|
187 |
-
</div>
|
188 |
-
<?php
|
189 |
-
}
|
190 |
-
}
|
191 |
-
|
192 |
-
/**
|
193 |
-
* Init Nav Menu
|
194 |
-
*
|
195 |
-
* @param mixed $action Action name.
|
196 |
-
* @since 1.0.6
|
197 |
-
*/
|
198 |
-
public function init_nav_menu( $action = '' ) {
|
199 |
-
|
200 |
-
if ( '' !== $action ) {
|
201 |
-
$this->render_tab_menu( $action );
|
202 |
-
}
|
203 |
-
}
|
204 |
-
|
205 |
-
/**
|
206 |
-
* Render tab menu
|
207 |
-
*
|
208 |
-
* @param mixed $action Action name.
|
209 |
-
* @since 1.0.6
|
210 |
-
*/
|
211 |
-
public function render_tab_menu( $action = '' ) {
|
212 |
-
?>
|
213 |
-
<div id="astra-sites-menu-page">
|
214 |
-
<?php $this->render( $action ); ?>
|
215 |
-
</div>
|
216 |
-
<?php
|
217 |
-
}
|
218 |
-
|
219 |
-
/**
|
220 |
-
* View actions
|
221 |
-
*
|
222 |
-
* @since 1.0.11
|
223 |
-
*/
|
224 |
-
public function get_view_actions() {
|
225 |
-
|
226 |
-
if ( empty( $this->view_actions ) ) {
|
227 |
-
|
228 |
-
$this->view_actions = apply_filters(
|
229 |
-
'astra_sites_menu_item',
|
230 |
-
array()
|
231 |
-
);
|
232 |
-
}
|
233 |
-
|
234 |
-
return $this->view_actions;
|
235 |
-
}
|
236 |
-
|
237 |
-
/**
|
238 |
-
* Prints HTML content for tabs
|
239 |
-
*
|
240 |
-
* @param mixed $action Action name.
|
241 |
-
* @since 1.0.6
|
242 |
-
*/
|
243 |
-
public function render( $action ) {
|
244 |
-
|
245 |
-
// Settings update message.
|
246 |
-
if ( isset( $_REQUEST['message'] ) && ( 'saved' === $_REQUEST['message'] || 'saved_ext' === $_REQUEST['message'] ) ) {
|
247 |
-
?>
|
248 |
-
<span id="message" class="notice notice-success is-dismissive"><p> <?php esc_html_e( 'Settings saved successfully.', 'astra-sites' ); ?> </p></span>
|
249 |
-
<?php
|
250 |
-
}
|
251 |
-
|
252 |
-
$default_page_builder = $this->get_setting( 'page_builder' );
|
253 |
-
|
254 |
-
if ( empty( $default_page_builder ) || isset( $_GET['change-page-builder'] ) ) {
|
255 |
-
|
256 |
-
$plugins = get_option( 'active_plugins', array() );
|
257 |
-
$page_builders = array();
|
258 |
-
if ( $plugins ) {
|
259 |
-
foreach ( $plugins as $key => $plugin_init ) {
|
260 |
-
if ( false !== strpos( $plugin_init, 'elementor' ) ) {
|
261 |
-
$page_builders[] = 'elementor';
|
262 |
-
}
|
263 |
-
if ( false !== strpos( $plugin_init, 'beaver-builder' ) ) {
|
264 |
-
$page_builders[] = 'beaver-builder';
|
265 |
-
}
|
266 |
-
if ( false !== strpos( $plugin_init, 'brizy' ) ) {
|
267 |
-
$page_builders[] = 'brizy';
|
268 |
-
}
|
269 |
-
}
|
270 |
-
}
|
271 |
-
$page_builders = array_unique( $page_builders );
|
272 |
-
$page_builders[] = 'gutenberg';
|
273 |
-
$page_builders = implode( ',', $page_builders );
|
274 |
-
?>
|
275 |
-
<div class="astra-sites-welcome" data-plugins="<?php echo esc_attr( $page_builders ); ?>">
|
276 |
-
<div class="inner">
|
277 |
-
<form id="astra-sites-welcome-form" enctype="multipart/form-data" method="post">
|
278 |
-
<h1><?php _e( 'Select Page Builder', 'astra-sites' ); ?></h1>
|
279 |
-
<p><?php _e( 'Astra offers starter sites that can be imported in one click. These templates are available in few different page builders. Please choose your preferred page builder from the list below.', 'astra-sites' ); ?></p>
|
280 |
-
<div class="fields">
|
281 |
-
<ul class="page-builders">
|
282 |
-
<li>
|
283 |
-
<label>
|
284 |
-
<input type="radio" name="page_builder" value="gutenberg">
|
285 |
-
<img src="<?php echo esc_url( ASTRA_SITES_URI . 'inc/assets/images/gutenberg.jpg' ); ?>" />
|
286 |
-
<div class="title"><?php _e( 'Gutenberg', 'astra-sites' ); ?></div>
|
287 |
-
</label>
|
288 |
-
</li>
|
289 |
-
<li>
|
290 |
-
<label>
|
291 |
-
<input type="radio" name="page_builder" value="elementor">
|
292 |
-
<img src="<?php echo esc_url( ASTRA_SITES_URI . 'inc/assets/images/elementor.jpg' ); ?>" />
|
293 |
-
<div class="title"><?php _e( 'Elementor', 'astra-sites' ); ?></div>
|
294 |
-
</label>
|
295 |
-
</li>
|
296 |
-
<li>
|
297 |
-
<label>
|
298 |
-
<input type="radio" name="page_builder" value="beaver-builder">
|
299 |
-
<img src="<?php echo esc_url( ASTRA_SITES_URI . 'inc/assets/images/beaver-builder.png' ); ?>" />
|
300 |
-
<div class="title"><?php _e( 'Beaver Builder', 'astra-sites' ); ?></div>
|
301 |
-
</li>
|
302 |
-
<li>
|
303 |
-
<label>
|
304 |
-
<input type="radio" name="page_builder" value="brizy">
|
305 |
-
<img src="<?php echo esc_url( ASTRA_SITES_URI . 'inc/assets/images/brizy.jpg' ); ?>" />
|
306 |
-
<div class="title"><?php _e( 'Brizy', 'astra-sites' ); ?></div>
|
307 |
-
</label>
|
308 |
-
</li>
|
309 |
-
</ul>
|
310 |
-
<div class="astra-sites-page-builder-notice" style="display: none;">
|
311 |
-
<p class="description"><?php _e( 'Please select your favorite page builder to continue..', 'astra-sites' ); ?></p>
|
312 |
-
</div>
|
313 |
-
<?php submit_button( __( 'Next', 'astra-sites' ), 'primary button-hero disabled' ); ?>
|
314 |
-
</div>
|
315 |
-
|
316 |
-
<input type="hidden" name="message" value="saved" />
|
317 |
-
<?php wp_nonce_field( 'astra-sites-welcome-screen', 'astra-sites-page-builder' ); ?>
|
318 |
-
</form>
|
319 |
-
</div>
|
320 |
-
</div>
|
321 |
-
<?php } else { ?>
|
322 |
-
<?php
|
323 |
-
$page_title = apply_filters( 'astra_sites_page_title', __( 'Astra Starter Sites - Your Library of 100+ Ready Templates!', 'astra-sites' ) );
|
324 |
-
?>
|
325 |
-
<div class="nav-tab-wrapper">
|
326 |
-
<h1 class='astra-sites-title'> <?php echo esc_html( $page_title ); ?> </h1>
|
327 |
-
<form id="astra-sites-welcome-form-inline" enctype="multipart/form-data" method="post">
|
328 |
-
<div class="fields">
|
329 |
-
<select name="page_builder" required="required">
|
330 |
-
<option value="gutenberg" <?php selected( $default_page_builder, 'gutenberg' ); ?>><?php _e( 'Block Editor (Gutenberg)', 'astra-sites' ); ?></option>
|
331 |
-
<option value="elementor" <?php selected( $default_page_builder, 'elementor' ); ?>><?php _e( 'Elementor', 'astra-sites' ); ?></option>
|
332 |
-
<option value="beaver-builder" <?php selected( $default_page_builder, 'beaver-builder' ); ?>><?php _e( 'Beaver Builder', 'astra-sites' ); ?></option>
|
333 |
-
<option value="brizy" <?php selected( $default_page_builder, 'brizy' ); ?>><?php _e( 'Brizy', 'astra-sites' ); ?></option>
|
334 |
-
</select>
|
335 |
-
</div>
|
336 |
-
<input type="hidden" name="message" value="saved" />
|
337 |
-
<?php wp_nonce_field( 'astra-sites-welcome-screen', 'astra-sites-page-builder' ); ?>
|
338 |
-
</form>
|
339 |
-
<?php
|
340 |
-
$view_actions = $this->get_view_actions();
|
341 |
-
|
342 |
-
foreach ( $view_actions as $slug => $data ) {
|
343 |
-
|
344 |
-
if ( ! $data['show'] ) {
|
345 |
-
continue;
|
346 |
-
}
|
347 |
-
|
348 |
-
$url = $this->get_page_url( $slug );
|
349 |
-
|
350 |
-
if ( 'general' === $slug ) {
|
351 |
-
update_option( 'astra_parent_page_url', $url );
|
352 |
-
}
|
353 |
-
|
354 |
-
$active = ( $slug === $action ) ? 'nav-tab-active' : '';
|
355 |
-
?>
|
356 |
-
<a class='nav-tab <?php echo esc_attr( $active ); ?>' href='<?php echo esc_url( $url ); ?>'> <?php echo esc_html( $data['label'] ); ?> </a>
|
357 |
-
<?php } ?>
|
358 |
-
</div><!-- .nav-tab-wrapper -->
|
359 |
-
<?php
|
360 |
-
}
|
361 |
-
}
|
362 |
-
|
363 |
-
/**
|
364 |
-
* Get and return page URL
|
365 |
-
*
|
366 |
-
* @param string $menu_slug Menu name.
|
367 |
-
* @since 1.0.6
|
368 |
-
* @return string page url
|
369 |
-
*/
|
370 |
-
public function get_page_url( $menu_slug ) {
|
371 |
-
|
372 |
-
$parent_page = 'themes.php';
|
373 |
-
|
374 |
-
if ( strpos( $parent_page, '?' ) !== false ) {
|
375 |
-
$query_var = '&page=astra-sites';
|
376 |
-
} else {
|
377 |
-
$query_var = '?page=astra-sites';
|
378 |
-
}
|
379 |
-
|
380 |
-
$parent_page_url = admin_url( $parent_page . $query_var );
|
381 |
-
|
382 |
-
$url = $parent_page_url . '&action=' . $menu_slug;
|
383 |
-
|
384 |
-
return esc_url( $url );
|
385 |
-
}
|
386 |
-
|
387 |
-
/**
|
388 |
-
* Add main menu
|
389 |
-
*
|
390 |
-
* @since 1.0.6
|
391 |
-
*/
|
392 |
-
public function add_admin_menu() {
|
393 |
-
$page_title = apply_filters( 'astra_sites_menu_page_title', __( 'Astra Starter Sites', 'astra-sites' ) );
|
394 |
-
|
395 |
-
$page = add_theme_page( $page_title, $page_title, 'manage_options', 'astra-sites', array( $this, 'menu_callback' ) );
|
396 |
-
}
|
397 |
-
|
398 |
-
/**
|
399 |
-
* Menu callback
|
400 |
-
*
|
401 |
-
* @since 1.0.6
|
402 |
-
*/
|
403 |
-
public function menu_callback() {
|
404 |
-
|
405 |
-
$current_slug = isset( $_GET['action'] ) ? esc_attr( $_GET['action'] ) : 'general';
|
406 |
-
|
407 |
-
$active_tab = str_replace( '_', '-', $current_slug );
|
408 |
-
$current_slug = str_replace( '-', '_', $current_slug );
|
409 |
-
|
410 |
-
?>
|
411 |
-
<div class="astra-sites-menu-page-wrapper">
|
412 |
-
<?php $this->init_nav_menu( $active_tab ); ?>
|
413 |
-
<?php do_action( 'astra_sites_menu_' . esc_attr( $current_slug ) . '_action' ); ?>
|
414 |
-
</div>
|
415 |
-
<?php
|
416 |
-
}
|
417 |
-
|
418 |
-
/**
|
419 |
-
* Include general page
|
420 |
-
*
|
421 |
-
* @since 1.0.6
|
422 |
-
*/
|
423 |
-
public function general_page() {
|
424 |
-
$default_page_builder = $this->get_setting( 'page_builder' );
|
425 |
-
if ( empty( $default_page_builder ) || isset( $_GET['change-page-builder'] ) ) {
|
426 |
-
return;
|
427 |
-
}
|
428 |
-
require_once ASTRA_SITES_DIR . 'inc/includes/admin-page.php';
|
429 |
-
}
|
430 |
-
}
|
431 |
-
|
432 |
-
Astra_Sites_Page::get_instance();
|
433 |
-
|
434 |
-
}// End if.
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Astra Sites Page
|
4 |
+
*
|
5 |
+
* @since 1.0.6
|
6 |
+
* @package Astra Sites
|
7 |
+
*/
|
8 |
+
|
9 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
10 |
+
exit;
|
11 |
+
}
|
12 |
+
|
13 |
+
if ( ! class_exists( 'Astra_Sites_Page' ) ) {
|
14 |
+
|
15 |
+
/**
|
16 |
+
* Astra Admin Settings
|
17 |
+
*/
|
18 |
+
class Astra_Sites_Page {
|
19 |
+
|
20 |
+
/**
|
21 |
+
* View all actions
|
22 |
+
*
|
23 |
+
* @since 1.0.6
|
24 |
+
* @var array $view_actions
|
25 |
+
*/
|
26 |
+
public $view_actions = array();
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Member Variable
|
30 |
+
*
|
31 |
+
* @var instance
|
32 |
+
*/
|
33 |
+
private static $instance;
|
34 |
+
|
35 |
+
/**
|
36 |
+
* Initiator
|
37 |
+
*
|
38 |
+
* @since 1.3.0
|
39 |
+
*/
|
40 |
+
public static function get_instance() {
|
41 |
+
if ( ! isset( self::$instance ) ) {
|
42 |
+
self::$instance = new self;
|
43 |
+
}
|
44 |
+
return self::$instance;
|
45 |
+
}
|
46 |
+
|
47 |
+
/**
|
48 |
+
* Constructor
|
49 |
+
*
|
50 |
+
* @since 1.3.0
|
51 |
+
*/
|
52 |
+
public function __construct() {
|
53 |
+
|
54 |
+
if ( ! is_admin() ) {
|
55 |
+
return;
|
56 |
+
}
|
57 |
+
|
58 |
+
add_action( 'after_setup_theme', array( $this, 'init_admin_settings' ), 99 );
|
59 |
+
add_action( 'admin_init', array( $this, 'save_page_builder' ) );
|
60 |
+
add_action( 'admin_notices', array( $this, 'getting_started' ) );
|
61 |
+
}
|
62 |
+
|
63 |
+
/**
|
64 |
+
* Admin notice
|
65 |
+
*
|
66 |
+
* @since 1.3.5
|
67 |
+
*
|
68 |
+
* @return void
|
69 |
+
*/
|
70 |
+
function getting_started() {
|
71 |
+
if ( 'plugins' !== get_current_screen()->base ) {
|
72 |
+
return;
|
73 |
+
}
|
74 |
+
|
75 |
+
$processed = get_user_meta( get_current_user_id(), '_astra_sites_gettings_started', true );
|
76 |
+
$product_name = Astra_Sites_White_Label::get_instance()->page_title( 'Astra' );
|
77 |
+
|
78 |
+
if ( $processed ) {
|
79 |
+
return;
|
80 |
+
}
|
81 |
+
|
82 |
+
?>
|
83 |
+
<div class="notice notice-info is-dismissible astra-sites-getting-started-notice">
|
84 |
+
<?php /* translators: %1$s is the admin page URL, %2$s is product name. */ ?>
|
85 |
+
<p><?php printf( __( 'Thank you for choosing %1$s! Check the library of <a class="astra-sites-getting-started-btn" href="%2$s">ready starter sites here »</a>', 'astra-sites' ), $product_name, admin_url( 'themes.php?page=astra-sites' ) ); ?></p>
|
86 |
+
</div>
|
87 |
+
<?php
|
88 |
+
}
|
89 |
+
|
90 |
+
/**
|
91 |
+
* Save Page Builder
|
92 |
+
*
|
93 |
+
* @return void
|
94 |
+
*/
|
95 |
+
function save_page_builder() {
|
96 |
+
|
97 |
+
// Only admins can save settings.
|
98 |
+
if ( ! current_user_can( 'manage_options' ) ) {
|
99 |
+
return;
|
100 |
+
}
|
101 |
+
|
102 |
+
// Make sure we have a valid nonce.
|
103 |
+
if ( isset( $_REQUEST['astra-sites-page-builder'] ) && wp_verify_nonce( $_REQUEST['astra-sites-page-builder'], 'astra-sites-welcome-screen' ) ) {
|
104 |
+
|
105 |
+
// Stored Settings.
|
106 |
+
$stored_data = $this->get_settings();
|
107 |
+
|
108 |
+
// New settings.
|
109 |
+
$new_data = array(
|
110 |
+
'page_builder' => ( isset( $_REQUEST['page_builder'] ) ) ? sanitize_key( $_REQUEST['page_builder'] ) : '',
|
111 |
+
);
|
112 |
+
|
113 |
+
// Merge settings.
|
114 |
+
$data = wp_parse_args( $new_data, $stored_data );
|
115 |
+
|
116 |
+
// Update settings.
|
117 |
+
update_option( 'astra_sites_settings', $data );
|
118 |
+
|
119 |
+
wp_redirect( admin_url( '/themes.php?page=astra-sites' ) );
|
120 |
+
}
|
121 |
+
}
|
122 |
+
|
123 |
+
/**
|
124 |
+
* Get single setting value
|
125 |
+
*
|
126 |
+
* @param string $key Setting key.
|
127 |
+
* @param mixed $defaults Setting value.
|
128 |
+
* @return mixed Stored setting value.
|
129 |
+
*/
|
130 |
+
function get_setting( $key = '', $defaults = '' ) {
|
131 |
+
|
132 |
+
$settings = $this->get_settings();
|
133 |
+
|
134 |
+
if ( empty( $settings ) ) {
|
135 |
+
return $defaults;
|
136 |
+
}
|
137 |
+
|
138 |
+
if ( array_key_exists( $key, $settings ) ) {
|
139 |
+
return $settings[ $key ];
|
140 |
+
}
|
141 |
+
|
142 |
+
return $defaults;
|
143 |
+
}
|
144 |
+
|
145 |
+
/**
|
146 |
+
* Get Settings
|
147 |
+
*
|
148 |
+
* @return array Stored settings.
|
149 |
+
*/
|
150 |
+
function get_settings() {
|
151 |
+
|
152 |
+
$defaults = array(
|
153 |
+
'page_builder' => '',
|
154 |
+
);
|
155 |
+
|
156 |
+
$stored_data = get_option( 'astra_sites_settings', $defaults );
|
157 |
+
|
158 |
+
return wp_parse_args( $stored_data, $defaults );
|
159 |
+
}
|
160 |
+
|
161 |
+
/**
|
162 |
+
* Admin settings init
|
163 |
+
*/
|
164 |
+
public function init_admin_settings() {
|
165 |
+
add_action( 'admin_menu', array( $this, 'add_admin_menu' ), 100 );
|
166 |
+
add_action( 'admin_notices', array( $this, 'notices' ) );
|
167 |
+
add_action( 'astra_sites_menu_general_action', array( $this, 'general_page' ) );
|
168 |
+
}
|
169 |
+
|
170 |
+
/**
|
171 |
+
* Admin notice
|
172 |
+
*
|
173 |
+
* @since 1.2.8
|
174 |
+
*/
|
175 |
+
public function notices() {
|
176 |
+
|
177 |
+
if ( 'appearance_page_astra-sites' !== get_current_screen()->id ) {
|
178 |
+
return;
|
179 |
+
}
|
180 |
+
|
181 |
+
if ( ! class_exists( 'XMLReader' ) ) {
|
182 |
+
?>
|
183 |
+
<div class="notice astra-sites-xml-notice notice-error">
|
184 |
+
<p><b><?php _e( 'Required XMLReader PHP extension is missing on your server!', 'astra-sites' ); ?></b></p>
|
185 |
+
<?php /* translators: %s is the white label name. */ ?>
|
186 |
+
<p><?php printf( __( '%s import requires XMLReader extension to be installed. Please contact your web hosting provider and ask them to install and activate the XMLReader PHP extension.', 'astra-sites' ), ASTRA_SITES_NAME ); ?></p>
|
187 |
+
</div>
|
188 |
+
<?php
|
189 |
+
}
|
190 |
+
}
|
191 |
+
|
192 |
+
/**
|
193 |
+
* Init Nav Menu
|
194 |
+
*
|
195 |
+
* @param mixed $action Action name.
|
196 |
+
* @since 1.0.6
|
197 |
+
*/
|
198 |
+
public function init_nav_menu( $action = '' ) {
|
199 |
+
|
200 |
+
if ( '' !== $action ) {
|
201 |
+
$this->render_tab_menu( $action );
|
202 |
+
}
|
203 |
+
}
|
204 |
+
|
205 |
+
/**
|
206 |
+
* Render tab menu
|
207 |
+
*
|
208 |
+
* @param mixed $action Action name.
|
209 |
+
* @since 1.0.6
|
210 |
+
*/
|
211 |
+
public function render_tab_menu( $action = '' ) {
|
212 |
+
?>
|
213 |
+
<div id="astra-sites-menu-page">
|
214 |
+
<?php $this->render( $action ); ?>
|
215 |
+
</div>
|
216 |
+
<?php
|
217 |
+
}
|
218 |
+
|
219 |
+
/**
|
220 |
+
* View actions
|
221 |
+
*
|
222 |
+
* @since 1.0.11
|
223 |
+
*/
|
224 |
+
public function get_view_actions() {
|
225 |
+
|
226 |
+
if ( empty( $this->view_actions ) ) {
|
227 |
+
|
228 |
+
$this->view_actions = apply_filters(
|
229 |
+
'astra_sites_menu_item',
|
230 |
+
array()
|
231 |
+
);
|
232 |
+
}
|
233 |
+
|
234 |
+
return $this->view_actions;
|
235 |
+
}
|
236 |
+
|
237 |
+
/**
|
238 |
+
* Prints HTML content for tabs
|
239 |
+
*
|
240 |
+
* @param mixed $action Action name.
|
241 |
+
* @since 1.0.6
|
242 |
+
*/
|
243 |
+
public function render( $action ) {
|
244 |
+
|
245 |
+
// Settings update message.
|
246 |
+
if ( isset( $_REQUEST['message'] ) && ( 'saved' === $_REQUEST['message'] || 'saved_ext' === $_REQUEST['message'] ) ) {
|
247 |
+
?>
|
248 |
+
<span id="message" class="notice notice-success is-dismissive"><p> <?php esc_html_e( 'Settings saved successfully.', 'astra-sites' ); ?> </p></span>
|
249 |
+
<?php
|
250 |
+
}
|
251 |
+
|
252 |
+
$default_page_builder = $this->get_setting( 'page_builder' );
|
253 |
+
|
254 |
+
if ( empty( $default_page_builder ) || isset( $_GET['change-page-builder'] ) ) {
|
255 |
+
|
256 |
+
$plugins = get_option( 'active_plugins', array() );
|
257 |
+
$page_builders = array();
|
258 |
+
if ( $plugins ) {
|
259 |
+
foreach ( $plugins as $key => $plugin_init ) {
|
260 |
+
if ( false !== strpos( $plugin_init, 'elementor' ) ) {
|
261 |
+
$page_builders[] = 'elementor';
|
262 |
+
}
|
263 |
+
if ( false !== strpos( $plugin_init, 'beaver-builder' ) ) {
|
264 |
+
$page_builders[] = 'beaver-builder';
|
265 |
+
}
|
266 |
+
if ( false !== strpos( $plugin_init, 'brizy' ) ) {
|
267 |
+
$page_builders[] = 'brizy';
|
268 |
+
}
|
269 |
+
}
|
270 |
+
}
|
271 |
+
$page_builders = array_unique( $page_builders );
|
272 |
+
$page_builders[] = 'gutenberg';
|
273 |
+
$page_builders = implode( ',', $page_builders );
|
274 |
+
?>
|
275 |
+
<div class="astra-sites-welcome" data-plugins="<?php echo esc_attr( $page_builders ); ?>">
|
276 |
+
<div class="inner">
|
277 |
+
<form id="astra-sites-welcome-form" enctype="multipart/form-data" method="post">
|
278 |
+
<h1><?php _e( 'Select Page Builder', 'astra-sites' ); ?></h1>
|
279 |
+
<p><?php _e( 'Astra offers starter sites that can be imported in one click. These templates are available in few different page builders. Please choose your preferred page builder from the list below.', 'astra-sites' ); ?></p>
|
280 |
+
<div class="fields">
|
281 |
+
<ul class="page-builders">
|
282 |
+
<li>
|
283 |
+
<label>
|
284 |
+
<input type="radio" name="page_builder" value="gutenberg">
|
285 |
+
<img src="<?php echo esc_url( ASTRA_SITES_URI . 'inc/assets/images/gutenberg.jpg' ); ?>" />
|
286 |
+
<div class="title"><?php _e( 'Gutenberg', 'astra-sites' ); ?></div>
|
287 |
+
</label>
|
288 |
+
</li>
|
289 |
+
<li>
|
290 |
+
<label>
|
291 |
+
<input type="radio" name="page_builder" value="elementor">
|
292 |
+
<img src="<?php echo esc_url( ASTRA_SITES_URI . 'inc/assets/images/elementor.jpg' ); ?>" />
|
293 |
+
<div class="title"><?php _e( 'Elementor', 'astra-sites' ); ?></div>
|
294 |
+
</label>
|
295 |
+
</li>
|
296 |
+
<li>
|
297 |
+
<label>
|
298 |
+
<input type="radio" name="page_builder" value="beaver-builder">
|
299 |
+
<img src="<?php echo esc_url( ASTRA_SITES_URI . 'inc/assets/images/beaver-builder.png' ); ?>" />
|
300 |
+
<div class="title"><?php _e( 'Beaver Builder', 'astra-sites' ); ?></div>
|
301 |
+
</li>
|
302 |
+
<li>
|
303 |
+
<label>
|
304 |
+
<input type="radio" name="page_builder" value="brizy">
|
305 |
+
<img src="<?php echo esc_url( ASTRA_SITES_URI . 'inc/assets/images/brizy.jpg' ); ?>" />
|
306 |
+
<div class="title"><?php _e( 'Brizy', 'astra-sites' ); ?></div>
|
307 |
+
</label>
|
308 |
+
</li>
|
309 |
+
</ul>
|
310 |
+
<div class="astra-sites-page-builder-notice" style="display: none;">
|
311 |
+
<p class="description"><?php _e( 'Please select your favorite page builder to continue..', 'astra-sites' ); ?></p>
|
312 |
+
</div>
|
313 |
+
<?php submit_button( __( 'Next', 'astra-sites' ), 'primary button-hero disabled' ); ?>
|
314 |
+
</div>
|
315 |
+
|
316 |
+
<input type="hidden" name="message" value="saved" />
|
317 |
+
<?php wp_nonce_field( 'astra-sites-welcome-screen', 'astra-sites-page-builder' ); ?>
|
318 |
+
</form>
|
319 |
+
</div>
|
320 |
+
</div>
|
321 |
+
<?php } else { ?>
|
322 |
+
<?php
|
323 |
+
$page_title = apply_filters( 'astra_sites_page_title', __( 'Astra Starter Sites - Your Library of 100+ Ready Templates!', 'astra-sites' ) );
|
324 |
+
?>
|
325 |
+
<div class="nav-tab-wrapper">
|
326 |
+
<h1 class='astra-sites-title'> <?php echo esc_html( $page_title ); ?> </h1>
|
327 |
+
<form id="astra-sites-welcome-form-inline" enctype="multipart/form-data" method="post">
|
328 |
+
<div class="fields">
|
329 |
+
<select name="page_builder" required="required">
|
330 |
+
<option value="gutenberg" <?php selected( $default_page_builder, 'gutenberg' ); ?>><?php _e( 'Block Editor (Gutenberg)', 'astra-sites' ); ?></option>
|
331 |
+
<option value="elementor" <?php selected( $default_page_builder, 'elementor' ); ?>><?php _e( 'Elementor', 'astra-sites' ); ?></option>
|
332 |
+
<option value="beaver-builder" <?php selected( $default_page_builder, 'beaver-builder' ); ?>><?php _e( 'Beaver Builder', 'astra-sites' ); ?></option>
|
333 |
+
<option value="brizy" <?php selected( $default_page_builder, 'brizy' ); ?>><?php _e( 'Brizy', 'astra-sites' ); ?></option>
|
334 |
+
</select>
|
335 |
+
</div>
|
336 |
+
<input type="hidden" name="message" value="saved" />
|
337 |
+
<?php wp_nonce_field( 'astra-sites-welcome-screen', 'astra-sites-page-builder' ); ?>
|
338 |
+
</form>
|
339 |
+
<?php
|
340 |
+
$view_actions = $this->get_view_actions();
|
341 |
+
|
342 |
+
foreach ( $view_actions as $slug => $data ) {
|
343 |
+
|
344 |
+
if ( ! $data['show'] ) {
|
345 |
+
continue;
|
346 |
+
}
|
347 |
+
|
348 |
+
$url = $this->get_page_url( $slug );
|
349 |
+
|
350 |
+
if ( 'general' === $slug ) {
|
351 |
+
update_option( 'astra_parent_page_url', $url );
|
352 |
+
}
|
353 |
+
|
354 |
+
$active = ( $slug === $action ) ? 'nav-tab-active' : '';
|
355 |
+
?>
|
356 |
+
<a class='nav-tab <?php echo esc_attr( $active ); ?>' href='<?php echo esc_url( $url ); ?>'> <?php echo esc_html( $data['label'] ); ?> </a>
|
357 |
+
<?php } ?>
|
358 |
+
</div><!-- .nav-tab-wrapper -->
|
359 |
+
<?php
|
360 |
+
}
|
361 |
+
}
|
362 |
+
|
363 |
+
/**
|
364 |
+
* Get and return page URL
|
365 |
+
*
|
366 |
+
* @param string $menu_slug Menu name.
|
367 |
+
* @since 1.0.6
|
368 |
+
* @return string page url
|
369 |
+
*/
|
370 |
+
public function get_page_url( $menu_slug ) {
|
371 |
+
|
372 |
+
$parent_page = 'themes.php';
|
373 |
+
|
374 |
+
if ( strpos( $parent_page, '?' ) !== false ) {
|
375 |
+
$query_var = '&page=astra-sites';
|
376 |
+
} else {
|
377 |
+
$query_var = '?page=astra-sites';
|
378 |
+
}
|
379 |
+
|
380 |
+
$parent_page_url = admin_url( $parent_page . $query_var );
|
381 |
+
|
382 |
+
$url = $parent_page_url . '&action=' . $menu_slug;
|
383 |
+
|
384 |
+
return esc_url( $url );
|
385 |
+
}
|
386 |
+
|
387 |
+
/**
|
388 |
+
* Add main menu
|
389 |
+
*
|
390 |
+
* @since 1.0.6
|
391 |
+
*/
|
392 |
+
public function add_admin_menu() {
|
393 |
+
$page_title = apply_filters( 'astra_sites_menu_page_title', __( 'Astra Starter Sites', 'astra-sites' ) );
|
394 |
+
|
395 |
+
$page = add_theme_page( $page_title, $page_title, 'manage_options', 'astra-sites', array( $this, 'menu_callback' ) );
|
396 |
+
}
|
397 |
+
|
398 |
+
/**
|
399 |
+
* Menu callback
|
400 |
+
*
|
401 |
+
* @since 1.0.6
|
402 |
+
*/
|
403 |
+
public function menu_callback() {
|
404 |
+
|
405 |
+
$current_slug = isset( $_GET['action'] ) ? esc_attr( $_GET['action'] ) : 'general';
|
406 |
+
|
407 |
+
$active_tab = str_replace( '_', '-', $current_slug );
|
408 |
+
$current_slug = str_replace( '-', '_', $current_slug );
|
409 |
+
|
410 |
+
?>
|
411 |
+
<div class="astra-sites-menu-page-wrapper">
|
412 |
+
<?php $this->init_nav_menu( $active_tab ); ?>
|
413 |
+
<?php do_action( 'astra_sites_menu_' . esc_attr( $current_slug ) . '_action' ); ?>
|
414 |
+
</div>
|
415 |
+
<?php
|
416 |
+
}
|
417 |
+
|
418 |
+
/**
|
419 |
+
* Include general page
|
420 |
+
*
|
421 |
+
* @since 1.0.6
|
422 |
+
*/
|
423 |
+
public function general_page() {
|
424 |
+
$default_page_builder = $this->get_setting( 'page_builder' );
|
425 |
+
if ( empty( $default_page_builder ) || isset( $_GET['change-page-builder'] ) ) {
|
426 |
+
return;
|
427 |
+
}
|
428 |
+
require_once ASTRA_SITES_DIR . 'inc/includes/admin-page.php';
|
429 |
+
}
|
430 |
+
}
|
431 |
+
|
432 |
+
Astra_Sites_Page::get_instance();
|
433 |
+
|
434 |
+
}// End if.
|
inc/classes/class-astra-sites-white-label.php
CHANGED
@@ -1,239 +1,239 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Astra Sites White Label
|
4 |
-
*
|
5 |
-
* @package Astra Sites
|
6 |
-
* @since 1.0.12
|
7 |
-
*/
|
8 |
-
|
9 |
-
if ( ! class_exists( 'Astra_Sites_White_Label' ) ) :
|
10 |
-
|
11 |
-
/**
|
12 |
-
* Astra_Sites_White_Label
|
13 |
-
*
|
14 |
-
* @since 1.0.12
|
15 |
-
*/
|
16 |
-
class Astra_Sites_White_Label {
|
17 |
-
|
18 |
-
/**
|
19 |
-
* Instance
|
20 |
-
*
|
21 |
-
* @since 1.0.12
|
22 |
-
*
|
23 |
-
* @var object Class Object.
|
24 |
-
* @access private
|
25 |
-
*/
|
26 |
-
private static $instance;
|
27 |
-
|
28 |
-
/**
|
29 |
-
* Member Variable
|
30 |
-
*
|
31 |
-
* @since 1.0.12
|
32 |
-
*
|
33 |
-
* @var array branding
|
34 |
-
* @access private
|
35 |
-
*/
|
36 |
-
private static $branding;
|
37 |
-
|
38 |
-
/**
|
39 |
-
* Settings
|
40 |
-
*
|
41 |
-
* @since 1.2.11
|
42 |
-
*
|
43 |
-
* @var array settings
|
44 |
-
*
|
45 |
-
* @access private
|
46 |
-
*/
|
47 |
-
private $settings;
|
48 |
-
|
49 |
-
/**
|
50 |
-
* Initiator
|
51 |
-
*
|
52 |
-
* @since 1.0.12
|
53 |
-
*
|
54 |
-
* @return object initialized object of class.
|
55 |
-
*/
|
56 |
-
public static function get_instance() {
|
57 |
-
if ( ! isset( self::$instance ) ) {
|
58 |
-
self::$instance = new self;
|
59 |
-
}
|
60 |
-
return self::$instance;
|
61 |
-
}
|
62 |
-
|
63 |
-
/**
|
64 |
-
* Constructor
|
65 |
-
*
|
66 |
-
* @since 1.0.12
|
67 |
-
*/
|
68 |
-
public function __construct() {
|
69 |
-
add_filter( 'all_plugins', array( $this, 'plugins_page' ) );
|
70 |
-
add_filter( 'astra_addon_branding_options', __CLASS__ . '::settings' );
|
71 |
-
add_action( 'astra_pro_white_label_add_form', __CLASS__ . '::add_white_lavel_form' );
|
72 |
-
add_filter( 'astra_sites_menu_page_title', array( $this, 'page_title' ) );
|
73 |
-
add_filter( 'astra_sites_page_title', array( $this, 'page_title' ) );
|
74 |
-
|
75 |
-
// Display the link with the plugin meta.
|
76 |
-
if ( is_admin() ) {
|
77 |
-
add_filter( 'plugin_row_meta', array( $this, 'plugin_links' ), 10, 4 );
|
78 |
-
}
|
79 |
-
}
|
80 |
-
|
81 |
-
/**
|
82 |
-
* White labels the plugins page.
|
83 |
-
*
|
84 |
-
* @since 1.0.12
|
85 |
-
*
|
86 |
-
* @param array $plugins Plugins Array.
|
87 |
-
* @return array
|
88 |
-
*/
|
89 |
-
function plugins_page( $plugins ) {
|
90 |
-
|
91 |
-
if ( ! is_callable( 'Astra_Ext_White_Label_Markup::get_whitelabel_string' ) ) {
|
92 |
-
return $plugins;
|
93 |
-
}
|
94 |
-
|
95 |
-
if ( ! isset( $plugins[ ASTRA_SITES_BASE ] ) ) {
|
96 |
-
return $plugins;
|
97 |
-
}
|
98 |
-
|
99 |
-
// Set White Labels.
|
100 |
-
$name = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-sites', 'name' );
|
101 |
-
$description = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-sites', 'description' );
|
102 |
-
$author = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-agency', 'author' );
|
103 |
-
$author_uri = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-agency', 'author_url' );
|
104 |
-
|
105 |
-
if ( ! empty( $name ) ) {
|
106 |
-
$plugins[ ASTRA_SITES_BASE ]['Name'] = $name;
|
107 |
-
|
108 |
-
// Remove Plugin URI if Agency White Label name is set.
|
109 |
-
$plugins[ ASTRA_SITES_BASE ]['PluginURI'] = '';
|
110 |
-
}
|
111 |
-
|
112 |
-
if ( ! empty( $description ) ) {
|
113 |
-
$plugins[ ASTRA_SITES_BASE ]['Description'] = $description;
|
114 |
-
}
|
115 |
-
|
116 |
-
if ( ! empty( $author ) ) {
|
117 |
-
$plugins[ ASTRA_SITES_BASE ]['Author'] = $author;
|
118 |
-
}
|
119 |
-
|
120 |
-
if ( ! empty( $author_uri ) ) {
|
121 |
-
$plugins[ ASTRA_SITES_BASE ]['AuthorURI'] = $author_uri;
|
122 |
-
}
|
123 |
-
|
124 |
-
return $plugins;
|
125 |
-
}
|
126 |
-
|
127 |
-
/**
|
128 |
-
* Remove a "view details" link from the plugin list table
|
129 |
-
*
|
130 |
-
* @since 1.0.12
|
131 |
-
*
|
132 |
-
* @param array $plugin_meta List of links.
|
133 |
-
* @param string $plugin_file Relative path to the main plugin file from the plugins directory.
|
134 |
-
* @param array $plugin_data Data from the plugin headers.
|
135 |
-
* @return array
|
136 |
-
*/
|
137 |
-
public function plugin_links( $plugin_meta, $plugin_file, $plugin_data ) {
|
138 |
-
|
139 |
-
if ( ! is_callable( 'Astra_Ext_White_Label_Markup::get_whitelabel_string' ) ) {
|
140 |
-
return $plugin_meta;
|
141 |
-
}
|
142 |
-
|
143 |
-
// Set White Labels.
|
144 |
-
if ( ASTRA_SITES_BASE === $plugin_file ) {
|
145 |
-
|
146 |
-
$name = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-sites', 'name' );
|
147 |
-
$description = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-sites', 'description' );
|
148 |
-
|
149 |
-
// Remove Plugin URI if Agency White Label name is set.
|
150 |
-
if ( ! empty( $name ) ) {
|
151 |
-
unset( $plugin_meta[2] );
|
152 |
-
}
|
153 |
-
}
|
154 |
-
|
155 |
-
return $plugin_meta;
|
156 |
-
}
|
157 |
-
|
158 |
-
/**
|
159 |
-
* Add White Label setting's
|
160 |
-
*
|
161 |
-
* @since 1.0.12
|
162 |
-
*
|
163 |
-
* @param array $settings White label setting.
|
164 |
-
* @return array
|
165 |
-
*/
|
166 |
-
public static function settings( $settings = array() ) {
|
167 |
-
|
168 |
-
$settings['astra-sites'] = array(
|
169 |
-
'name' => '',
|
170 |
-
'description' => '',
|
171 |
-
);
|
172 |
-
|
173 |
-
return $settings;
|
174 |
-
}
|
175 |
-
|
176 |
-
/**
|
177 |
-
* Add White Label form
|
178 |
-
*
|
179 |
-
* @since 1.0.12
|
180 |
-
*
|
181 |
-
* @param array $settings White label setting.
|
182 |
-
* @return void
|
183 |
-
*/
|
184 |
-
public static function add_white_lavel_form( $settings = array() ) {
|
185 |
-
|
186 |
-
/* translators: %1$s product name */
|
187 |
-
$plugin_name = sprintf( __( '%1$s Branding', 'astra-sites' ), ASTRA_SITES_NAME );
|
188 |
-
|
189 |
-
require_once ASTRA_SITES_DIR . 'inc/includes/white-label.php';
|
190 |
-
}
|
191 |
-
|
192 |
-
/**
|
193 |
-
* Page Title
|
194 |
-
*
|
195 |
-
* @since 1.0.12
|
196 |
-
*
|
197 |
-
* @param string $title Page Title.
|
198 |
-
* @return string Filtered Page Title.
|
199 |
-
*/
|
200 |
-
function page_title( $title = '' ) {
|
201 |
-
|
202 |
-
if ( is_callable( 'Astra_Ext_White_Label_Markup::get_whitelabel_string' ) ) {
|
203 |
-
$astra_sites_name = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-sites', 'name' );
|
204 |
-
if ( ! empty( $astra_sites_name ) ) {
|
205 |
-
$title = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-sites', 'name' );
|
206 |
-
}
|
207 |
-
}
|
208 |
-
|
209 |
-
return $title;
|
210 |
-
}
|
211 |
-
|
212 |
-
/**
|
213 |
-
* Is Astra sites White labeled
|
214 |
-
*
|
215 |
-
* @since 1.2.13
|
216 |
-
*
|
217 |
-
* @return string
|
218 |
-
*/
|
219 |
-
function is_white_labeled() {
|
220 |
-
if ( ! is_callable( 'Astra_Ext_White_Label_Markup::get_whitelabel_string' ) ) {
|
221 |
-
return false;
|
222 |
-
}
|
223 |
-
|
224 |
-
$astra_sites_name = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-sites', 'name' );
|
225 |
-
if ( empty( $astra_sites_name ) ) {
|
226 |
-
return false;
|
227 |
-
}
|
228 |
-
|
229 |
-
return true;
|
230 |
-
}
|
231 |
-
|
232 |
-
}
|
233 |
-
|
234 |
-
/**
|
235 |
-
* Kicking this off by calling 'get_instance()' method
|
236 |
-
*/
|
237 |
-
Astra_Sites_White_Label::get_instance();
|
238 |
-
|
239 |
-
endif;
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Astra Sites White Label
|
4 |
+
*
|
5 |
+
* @package Astra Sites
|
6 |
+
* @since 1.0.12
|
7 |
+
*/
|
8 |
+
|
9 |
+
if ( ! class_exists( 'Astra_Sites_White_Label' ) ) :
|
10 |
+
|
11 |
+
/**
|
12 |
+
* Astra_Sites_White_Label
|
13 |
+
*
|
14 |
+
* @since 1.0.12
|
15 |
+
*/
|
16 |
+
class Astra_Sites_White_Label {
|
17 |
+
|
18 |
+
/**
|
19 |
+
* Instance
|
20 |
+
*
|
21 |
+
* @since 1.0.12
|
22 |
+
*
|
23 |
+
* @var object Class Object.
|
24 |
+
* @access private
|
25 |
+
*/
|
26 |
+
private static $instance;
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Member Variable
|
30 |
+
*
|
31 |
+
* @since 1.0.12
|
32 |
+
*
|
33 |
+
* @var array branding
|
34 |
+
* @access private
|
35 |
+
*/
|
36 |
+
private static $branding;
|
37 |
+
|
38 |
+
/**
|
39 |
+
* Settings
|
40 |
+
*
|
41 |
+
* @since 1.2.11
|
42 |
+
*
|
43 |
+
* @var array settings
|
44 |
+
*
|
45 |
+
* @access private
|
46 |
+
*/
|
47 |
+
private $settings;
|
48 |
+
|
49 |
+
/**
|
50 |
+
* Initiator
|
51 |
+
*
|
52 |
+
* @since 1.0.12
|
53 |
+
*
|
54 |
+
* @return object initialized object of class.
|
55 |
+
*/
|
56 |
+
public static function get_instance() {
|
57 |
+
if ( ! isset( self::$instance ) ) {
|
58 |
+
self::$instance = new self;
|
59 |
+
}
|
60 |
+
return self::$instance;
|
61 |
+
}
|
62 |
+
|
63 |
+
/**
|
64 |
+
* Constructor
|
65 |
+
*
|
66 |
+
* @since 1.0.12
|
67 |
+
*/
|
68 |
+
public function __construct() {
|
69 |
+
add_filter( 'all_plugins', array( $this, 'plugins_page' ) );
|
70 |
+
add_filter( 'astra_addon_branding_options', __CLASS__ . '::settings' );
|
71 |
+
add_action( 'astra_pro_white_label_add_form', __CLASS__ . '::add_white_lavel_form' );
|
72 |
+
add_filter( 'astra_sites_menu_page_title', array( $this, 'page_title' ) );
|
73 |
+
add_filter( 'astra_sites_page_title', array( $this, 'page_title' ) );
|
74 |
+
|
75 |
+
// Display the link with the plugin meta.
|
76 |
+
if ( is_admin() ) {
|
77 |
+
add_filter( 'plugin_row_meta', array( $this, 'plugin_links' ), 10, 4 );
|
78 |
+
}
|
79 |
+
}
|
80 |
+
|
81 |
+
/**
|
82 |
+
* White labels the plugins page.
|
83 |
+
*
|
84 |
+
* @since 1.0.12
|
85 |
+
*
|
86 |
+
* @param array $plugins Plugins Array.
|
87 |
+
* @return array
|
88 |
+
*/
|
89 |
+
function plugins_page( $plugins ) {
|
90 |
+
|
91 |
+
if ( ! is_callable( 'Astra_Ext_White_Label_Markup::get_whitelabel_string' ) ) {
|
92 |
+
return $plugins;
|
93 |
+
}
|
94 |
+
|
95 |
+
if ( ! isset( $plugins[ ASTRA_SITES_BASE ] ) ) {
|
96 |
+
return $plugins;
|
97 |
+
}
|
98 |
+
|
99 |
+
// Set White Labels.
|
100 |
+
$name = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-sites', 'name' );
|
101 |
+
$description = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-sites', 'description' );
|
102 |
+
$author = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-agency', 'author' );
|
103 |
+
$author_uri = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-agency', 'author_url' );
|
104 |
+
|
105 |
+
if ( ! empty( $name ) ) {
|
106 |
+
$plugins[ ASTRA_SITES_BASE ]['Name'] = $name;
|
107 |
+
|
108 |
+
// Remove Plugin URI if Agency White Label name is set.
|
109 |
+
$plugins[ ASTRA_SITES_BASE ]['PluginURI'] = '';
|
110 |
+
}
|
111 |
+
|
112 |
+
if ( ! empty( $description ) ) {
|
113 |
+
$plugins[ ASTRA_SITES_BASE ]['Description'] = $description;
|
114 |
+
}
|
115 |
+
|
116 |
+
if ( ! empty( $author ) ) {
|
117 |
+
$plugins[ ASTRA_SITES_BASE ]['Author'] = $author;
|
118 |
+
}
|
119 |
+
|
120 |
+
if ( ! empty( $author_uri ) ) {
|
121 |
+
$plugins[ ASTRA_SITES_BASE ]['AuthorURI'] = $author_uri;
|
122 |
+
}
|
123 |
+
|
124 |
+
return $plugins;
|
125 |
+
}
|
126 |
+
|
127 |
+
/**
|
128 |
+
* Remove a "view details" link from the plugin list table
|
129 |
+
*
|
130 |
+
* @since 1.0.12
|
131 |
+
*
|
132 |
+
* @param array $plugin_meta List of links.
|
133 |
+
* @param string $plugin_file Relative path to the main plugin file from the plugins directory.
|
134 |
+
* @param array $plugin_data Data from the plugin headers.
|
135 |
+
* @return array
|
136 |
+
*/
|
137 |
+
public function plugin_links( $plugin_meta, $plugin_file, $plugin_data ) {
|
138 |
+
|
139 |
+
if ( ! is_callable( 'Astra_Ext_White_Label_Markup::get_whitelabel_string' ) ) {
|
140 |
+
return $plugin_meta;
|
141 |
+
}
|
142 |
+
|
143 |
+
// Set White Labels.
|
144 |
+
if ( ASTRA_SITES_BASE === $plugin_file ) {
|
145 |
+
|
146 |
+
$name = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-sites', 'name' );
|
147 |
+
$description = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-sites', 'description' );
|
148 |
+
|
149 |
+
// Remove Plugin URI if Agency White Label name is set.
|
150 |
+
if ( ! empty( $name ) ) {
|
151 |
+
unset( $plugin_meta[2] );
|
152 |
+
}
|
153 |
+
}
|
154 |
+
|
155 |
+
return $plugin_meta;
|
156 |
+
}
|
157 |
+
|
158 |
+
/**
|
159 |
+
* Add White Label setting's
|
160 |
+
*
|
161 |
+
* @since 1.0.12
|
162 |
+
*
|
163 |
+
* @param array $settings White label setting.
|
164 |
+
* @return array
|
165 |
+
*/
|
166 |
+
public static function settings( $settings = array() ) {
|
167 |
+
|
168 |
+
$settings['astra-sites'] = array(
|
169 |
+
'name' => '',
|
170 |
+
'description' => '',
|
171 |
+
);
|
172 |
+
|
173 |
+
return $settings;
|
174 |
+
}
|
175 |
+
|
176 |
+
/**
|
177 |
+
* Add White Label form
|
178 |
+
*
|
179 |
+
* @since 1.0.12
|
180 |
+
*
|
181 |
+
* @param array $settings White label setting.
|
182 |
+
* @return void
|
183 |
+
*/
|
184 |
+
public static function add_white_lavel_form( $settings = array() ) {
|
185 |
+
|
186 |
+
/* translators: %1$s product name */
|
187 |
+
$plugin_name = sprintf( __( '%1$s Branding', 'astra-sites' ), ASTRA_SITES_NAME );
|
188 |
+
|
189 |
+
require_once ASTRA_SITES_DIR . 'inc/includes/white-label.php';
|
190 |
+
}
|
191 |
+
|
192 |
+
/**
|
193 |
+
* Page Title
|
194 |
+
*
|
195 |
+
* @since 1.0.12
|
196 |
+
*
|
197 |
+
* @param string $title Page Title.
|
198 |
+
* @return string Filtered Page Title.
|
199 |
+
*/
|
200 |
+
function page_title( $title = '' ) {
|
201 |
+
|
202 |
+
if ( is_callable( 'Astra_Ext_White_Label_Markup::get_whitelabel_string' ) ) {
|
203 |
+
$astra_sites_name = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-sites', 'name' );
|
204 |
+
if ( ! empty( $astra_sites_name ) ) {
|
205 |
+
$title = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-sites', 'name' );
|
206 |
+
}
|
207 |
+
}
|
208 |
+
|
209 |
+
return $title;
|
210 |
+
}
|
211 |
+
|
212 |
+
/**
|
213 |
+
* Is Astra sites White labeled
|
214 |
+
*
|
215 |
+
* @since 1.2.13
|
216 |
+
*
|
217 |
+
* @return string
|
218 |
+
*/
|
219 |
+
function is_white_labeled() {
|
220 |
+
if ( ! is_callable( 'Astra_Ext_White_Label_Markup::get_whitelabel_string' ) ) {
|
221 |
+
return false;
|
222 |
+
}
|
223 |
+
|
224 |
+
$astra_sites_name = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-sites', 'name' );
|
225 |
+
if ( empty( $astra_sites_name ) ) {
|
226 |
+
return false;
|
227 |
+
}
|
228 |
+
|
229 |
+
return true;
|
230 |
+
}
|
231 |
+
|
232 |
+
}
|
233 |
+
|
234 |
+
/**
|
235 |
+
* Kicking this off by calling 'get_instance()' method
|
236 |
+
*/
|
237 |
+
Astra_Sites_White_Label::get_instance();
|
238 |
+
|
239 |
+
endif;
|
inc/classes/class-astra-sites.php
CHANGED
@@ -359,7 +359,7 @@ if ( ! class_exists( 'Astra_Sites' ) ) :
|
|
359 |
'btnActivating' => __( 'Activating', 'astra-sites' ) . '…',
|
360 |
'btnActive' => __( 'Active', 'astra-sites' ),
|
361 |
'importFailBtn' => __( 'Import failed.', 'astra-sites' ),
|
362 |
-
'importFailBtnLarge' => __( 'Import failed
|
363 |
'importDemo' => __( 'Import This Site', 'astra-sites' ),
|
364 |
'importingDemo' => __( 'Importing..', 'astra-sites' ),
|
365 |
'DescExpand' => __( 'Read more', 'astra-sites' ) . '…',
|
359 |
'btnActivating' => __( 'Activating', 'astra-sites' ) . '…',
|
360 |
'btnActive' => __( 'Active', 'astra-sites' ),
|
361 |
'importFailBtn' => __( 'Import failed.', 'astra-sites' ),
|
362 |
+
'importFailBtnLarge' => __( 'Import failed.', 'astra-sites' ),
|
363 |
'importDemo' => __( 'Import This Site', 'astra-sites' ),
|
364 |
'importingDemo' => __( 'Importing..', 'astra-sites' ),
|
365 |
'DescExpand' => __( 'Read more', 'astra-sites' ) . '…',
|
inc/classes/compatibility/class-astra-sites-compatibility.php
CHANGED
@@ -1,69 +1,69 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Astra Sites Compatibility for 3rd party plugins.
|
4 |
-
*
|
5 |
-
* @package Astra Sites
|
6 |
-
* @since 1.0.11
|
7 |
-
*/
|
8 |
-
|
9 |
-
if ( ! class_exists( 'Astra_Sites_Compatibility' ) ) :
|
10 |
-
|
11 |
-
/**
|
12 |
-
* Astra Sites Compatibility
|
13 |
-
*
|
14 |
-
* @since 1.0.11
|
15 |
-
*/
|
16 |
-
class Astra_Sites_Compatibility {
|
17 |
-
|
18 |
-
/**
|
19 |
-
* Instance
|
20 |
-
*
|
21 |
-
* @access private
|
22 |
-
* @var object Class object.
|
23 |
-
* @since 1.0.11
|
24 |
-
*/
|
25 |
-
private static $instance;
|
26 |
-
|
27 |
-
/**
|
28 |
-
* Initiator
|
29 |
-
*
|
30 |
-
* @since 1.0.11
|
31 |
-
* @return object initialized object of class.
|
32 |
-
*/
|
33 |
-
public static function instance() {
|
34 |
-
if ( ! isset( self::$instance ) ) {
|
35 |
-
self::$instance = new self;
|
36 |
-
}
|
37 |
-
return self::$instance;
|
38 |
-
}
|
39 |
-
|
40 |
-
/**
|
41 |
-
* Constructor
|
42 |
-
*
|
43 |
-
* @since 1.0.11
|
44 |
-
*/
|
45 |
-
public function __construct() {
|
46 |
-
|
47 |
-
// Plugin - Astra Pro.
|
48 |
-
require_once ASTRA_SITES_DIR . 'inc/classes/compatibility/astra-pro/class-astra-sites-compatibility-astra-pro.php';
|
49 |
-
|
50 |
-
// Plugin - Site Origin Widgets.
|
51 |
-
require_once ASTRA_SITES_DIR . 'inc/classes/compatibility/so-widgets-bundle/class-astra-sites-compatibility-so-widgets.php';
|
52 |
-
|
53 |
-
// Plugin - WooCommerce.
|
54 |
-
require_once ASTRA_SITES_DIR . 'inc/classes/compatibility/woocommerce/class-astra-sites-compatibility-woocommerce.php';
|
55 |
-
|
56 |
-
// Plugin - LearnDash LMS.
|
57 |
-
require_once ASTRA_SITES_DIR . 'inc/classes/compatibility/sfwd-lms/class-astra-sites-compatibility-sfwd-lms.php';
|
58 |
-
}
|
59 |
-
|
60 |
-
}
|
61 |
-
|
62 |
-
/**
|
63 |
-
* Kicking this off by calling 'instance()' method
|
64 |
-
*/
|
65 |
-
Astra_Sites_Compatibility::instance();
|
66 |
-
|
67 |
-
endif;
|
68 |
-
|
69 |
-
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Astra Sites Compatibility for 3rd party plugins.
|
4 |
+
*
|
5 |
+
* @package Astra Sites
|
6 |
+
* @since 1.0.11
|
7 |
+
*/
|
8 |
+
|
9 |
+
if ( ! class_exists( 'Astra_Sites_Compatibility' ) ) :
|
10 |
+
|
11 |
+
/**
|
12 |
+
* Astra Sites Compatibility
|
13 |
+
*
|
14 |
+
* @since 1.0.11
|
15 |
+
*/
|
16 |
+
class Astra_Sites_Compatibility {
|
17 |
+
|
18 |
+
/**
|
19 |
+
* Instance
|
20 |
+
*
|
21 |
+
* @access private
|
22 |
+
* @var object Class object.
|
23 |
+
* @since 1.0.11
|
24 |
+
*/
|
25 |
+
private static $instance;
|
26 |
+
|
27 |
+
/**
|
28 |
+
* Initiator
|
29 |
+
*
|
30 |
+
* @since 1.0.11
|
31 |
+
* @return object initialized object of class.
|
32 |
+
*/
|
33 |
+
public static function instance() {
|
34 |
+
if ( ! isset( self::$instance ) ) {
|
35 |
+
self::$instance = new self;
|
36 |
+
}
|
37 |
+
return self::$instance;
|
38 |
+
}
|
39 |
+
|
40 |
+
/**
|
41 |
+
* Constructor
|
42 |
+
*
|
43 |
+
* @since 1.0.11
|
44 |
+
*/
|
45 |
+
public function __construct() {
|
46 |
+
|
47 |
+
// Plugin - Astra Pro.
|
48 |
+
require_once ASTRA_SITES_DIR . 'inc/classes/compatibility/astra-pro/class-astra-sites-compatibility-astra-pro.php';
|
49 |
+
|
50 |
+
// Plugin - Site Origin Widgets.
|
51 |
+
require_once ASTRA_SITES_DIR . 'inc/classes/compatibility/so-widgets-bundle/class-astra-sites-compatibility-so-widgets.php';
|
52 |
+
|
53 |
+
// Plugin - WooCommerce.
|
54 |
+
require_once ASTRA_SITES_DIR . 'inc/classes/compatibility/woocommerce/class-astra-sites-compatibility-woocommerce.php';
|
55 |
+
|
56 |
+
// Plugin - LearnDash LMS.
|
57 |
+
require_once ASTRA_SITES_DIR . 'inc/classes/compatibility/sfwd-lms/class-astra-sites-compatibility-sfwd-lms.php';
|
58 |
+
}
|
59 |
+
|
60 |
+
}
|
61 |
+
|
62 |
+
/**
|
63 |
+
* Kicking this off by calling 'instance()' method
|
64 |
+
*/
|
65 |
+
Astra_Sites_Compatibility::instance();
|
66 |
+
|
67 |
+
endif;
|
68 |
+
|
69 |
+
|
inc/importers/batch-processing/class-astra-sites-batch-processing-beaver-builder.php
CHANGED
@@ -1,261 +1,261 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Batch Processing
|
4 |
-
*
|
5 |
-
* @package Astra Sites
|
6 |
-
* @since 1.0.14
|
7 |
-
*/
|
8 |
-
|
9 |
-
if ( ! class_exists( 'Astra_Sites_Batch_Processing_Beaver_Builder' ) ) :
|
10 |
-
|
11 |
-
/**
|
12 |
-
* Astra_Sites_Batch_Processing_Beaver_Builder
|
13 |
-
*
|
14 |
-
* @since 1.0.14
|
15 |
-
*/
|
16 |
-
class Astra_Sites_Batch_Processing_Beaver_Builder {
|
17 |
-
|
18 |
-
/**
|
19 |
-
* Instance
|
20 |
-
*
|
21 |
-
* @since 1.0.14
|
22 |
-
* @access private
|
23 |
-
* @var object Class object.
|
24 |
-
*/
|
25 |
-
private static $instance;
|
26 |
-
|
27 |
-
/**
|
28 |
-
* Initiator
|
29 |
-
*
|
30 |
-
* @since 1.0.14
|
31 |
-
* @return object initialized object of class.
|
32 |
-
*/
|
33 |
-
public static function get_instance() {
|
34 |
-
|
35 |
-
if ( ! isset( self::$instance ) ) {
|
36 |
-
self::$instance = new self;
|
37 |
-
}
|
38 |
-
return self::$instance;
|
39 |
-
}
|
40 |
-
|
41 |
-
/**
|
42 |
-
* Constructor
|
43 |
-
*
|
44 |
-
* @since 1.0.14
|
45 |
-
*/
|
46 |
-
public function __construct() {
|
47 |
-
}
|
48 |
-
|
49 |
-
/**
|
50 |
-
* Import
|
51 |
-
*
|
52 |
-
* @since 1.0.14
|
53 |
-
* @return void
|
54 |
-
*/
|
55 |
-
public function import() {
|
56 |
-
|
57 |
-
Astra_Sites_Importer_Log::add( '---- Processing WordPress Posts / Pages - for Beaver Builder ----' );
|
58 |
-
if ( ! is_callable( 'FLBuilderModel::get_post_types' ) ) {
|
59 |
-
return;
|
60 |
-
}
|
61 |
-
|
62 |
-
$post_types = FLBuilderModel::get_post_types( 'post-types' );
|
63 |
-
if ( empty( $post_types ) && ! is_array( $post_types ) ) {
|
64 |
-
return;
|
65 |
-
}
|
66 |
-
|
67 |
-
$post_ids = Astra_Sites_Batch_Processing::get_pages( $post_types );
|
68 |
-
if ( empty( $post_ids ) && ! is_array( $post_ids ) ) {
|
69 |
-
return;
|
70 |
-
}
|
71 |
-
|
72 |
-
foreach ( $post_ids as $post_id ) {
|
73 |
-
$is_bb_post = get_post_meta( $post_id, '_fl_builder_enabled', true );
|
74 |
-
if ( $is_bb_post ) {
|
75 |
-
$this->import_single_post( $post_id );
|
76 |
-
}
|
77 |
-
}
|
78 |
-
}
|
79 |
-
|
80 |
-
/**
|
81 |
-
* Update post meta.
|
82 |
-
*
|
83 |
-
* @param integer $post_id Post ID.
|
84 |
-
* @return void
|
85 |
-
*/
|
86 |
-
public function import_single_post( $post_id = 0 ) {
|
87 |
-
|
88 |
-
Astra_Sites_Importer_Log::add( 'Post ID: ' . $post_id );
|
89 |
-
if ( ! empty( $post_id ) ) {
|
90 |
-
|
91 |
-
// Get page builder data.
|
92 |
-
$data = get_post_meta( $post_id, '_fl_builder_data', true );
|
93 |
-
|
94 |
-
if ( ! empty( $data ) ) {
|
95 |
-
foreach ( $data as $key => $el ) {
|
96 |
-
|
97 |
-
// Update 'row' images.
|
98 |
-
if ( 'row' === $el->type ) {
|
99 |
-
$data[ $key ]->settings = self::update_row( $el->settings );
|
100 |
-
}
|
101 |
-
|
102 |
-
// Update 'module' images.
|
103 |
-
if ( 'module' === $el->type ) {
|
104 |
-
$data[ $key ]->settings = self::update_module( $el->settings );
|
105 |
-
}
|
106 |
-
|
107 |
-
// Update 'column' images.
|
108 |
-
if ( 'column' === $el->type ) {
|
109 |
-
$data[ $key ]->settings = self::update_column( $el->settings );
|
110 |
-
}
|
111 |
-
}
|
112 |
-
|
113 |
-
// Update page builder data.
|
114 |
-
update_post_meta( $post_id, '_fl_builder_data', $data );
|
115 |
-
update_post_meta( $post_id, '_fl_builder_draft', $data );
|
116 |
-
|
117 |
-
// Clear all cache.
|
118 |
-
FLBuilderModel::delete_asset_cache_for_all_posts();
|
119 |
-
}
|
120 |
-
}
|
121 |
-
|
122 |
-
}
|
123 |
-
|
124 |
-
/**
|
125 |
-
* Import Module Images.
|
126 |
-
*
|
127 |
-
* @param object $settings Module settings object.
|
128 |
-
* @return object
|
129 |
-
*/
|
130 |
-
public static function update_module( $settings ) {
|
131 |
-
|
132 |
-
// 1) Set photos.
|
133 |
-
$settings = self::import_photo( $settings );
|
134 |
-
|
135 |
-
/**
|
136 |
-
* 2) Set `$settings->data` for Only type 'image-icon'
|
137 |
-
*
|
138 |
-
* @todo Remove the condition `'image-icon' === $settings->type` if `$settings->data` is used only for the Image Icon.
|
139 |
-
*/
|
140 |
-
if (
|
141 |
-
isset( $settings->data ) &&
|
142 |
-
isset( $settings->photo ) && ! empty( $settings->photo ) &&
|
143 |
-
'image-icon' === $settings->type
|
144 |
-
) {
|
145 |
-
$settings->data = FLBuilderPhoto::get_attachment_data( $settings->photo );
|
146 |
-
}
|
147 |
-
|
148 |
-
// 3) Set `list item` module images.
|
149 |
-
if ( isset( $settings->add_list_item ) ) {
|
150 |
-
foreach ( $settings->add_list_item as $key => $value ) {
|
151 |
-
$settings->add_list_item[ $key ] = self::import_photo( $value );
|
152 |
-
}
|
153 |
-
}
|
154 |
-
|
155 |
-
// 4) Set `list item` module images.
|
156 |
-
if ( isset( $settings->text ) ) {
|
157 |
-
$ids_mapping = get_option( 'astra_sites_wpforms_ids_mapping', array() );
|
158 |
-
if ( $ids_mapping ) {
|
159 |
-
|
160 |
-
// Keep old data in temp.
|
161 |
-
$updated_data = $settings->text;
|
162 |
-
|
163 |
-
// Update WP form IDs.
|
164 |
-
foreach ( $ids_mapping as $old_id => $new_id ) {
|
165 |
-
$updated_data = str_replace( '[wpforms id="' . $old_id, '[wpforms id="' . $new_id, $updated_data );
|
166 |
-
}
|
167 |
-
|
168 |
-
// Update modified data.
|
169 |
-
$settings->text = $updated_data;
|
170 |
-
}
|
171 |
-
}
|
172 |
-
|
173 |
-
return $settings;
|
174 |
-
}
|
175 |
-
|
176 |
-
/**
|
177 |
-
* Import Column Images.
|
178 |
-
*
|
179 |
-
* @param object $settings Column settings object.
|
180 |
-
* @return object
|
181 |
-
*/
|
182 |
-
public static function update_column( $settings ) {
|
183 |
-
|
184 |
-
// 1) Set BG Images.
|
185 |
-
$settings = self::import_bg_image( $settings );
|
186 |
-
|
187 |
-
return $settings;
|
188 |
-
}
|
189 |
-
|
190 |
-
/**
|
191 |
-
* Import Row Images.
|
192 |
-
*
|
193 |
-
* @param object $settings Row settings object.
|
194 |
-
* @return object
|
195 |
-
*/
|
196 |
-
public static function update_row( $settings ) {
|
197 |
-
|
198 |
-
// 1) Set BG Images.
|
199 |
-
$settings = self::import_bg_image( $settings );
|
200 |
-
|
201 |
-
return $settings;
|
202 |
-
}
|
203 |
-
|
204 |
-
/**
|
205 |
-
* Helper: Import BG Images.
|
206 |
-
*
|
207 |
-
* @param object $settings Row settings object.
|
208 |
-
* @return object
|
209 |
-
*/
|
210 |
-
public static function import_bg_image( $settings ) {
|
211 |
-
|
212 |
-
if (
|
213 |
-
( ! empty( $settings->bg_image ) && ! empty( $settings->bg_image_src ) )
|
214 |
-
) {
|
215 |
-
$image = array(
|
216 |
-
'url' => $settings->bg_image_src,
|
217 |
-
'id' => $settings->bg_image,
|
218 |
-
);
|
219 |
-
|
220 |
-
$downloaded_image = Astra_Sites_Image_Importer::get_instance()->import( $image );
|
221 |
-
|
222 |
-
$settings->bg_image_src = $downloaded_image['url'];
|
223 |
-
$settings->bg_image = $downloaded_image['id'];
|
224 |
-
}
|
225 |
-
|
226 |
-
return $settings;
|
227 |
-
}
|
228 |
-
|
229 |
-
/**
|
230 |
-
* Helper: Import Photo.
|
231 |
-
*
|
232 |
-
* @param object $settings Row settings object.
|
233 |
-
* @return object
|
234 |
-
*/
|
235 |
-
public static function import_photo( $settings ) {
|
236 |
-
|
237 |
-
if ( ! empty( $settings->photo ) && ! empty( $settings->photo_src ) ) {
|
238 |
-
|
239 |
-
$image = array(
|
240 |
-
'url' => $settings->photo_src,
|
241 |
-
'id' => $settings->photo,
|
242 |
|