| 1 |
<?php |
| 2 |
|
| 3 |
namespace Elementor\App\Modules\ImportExport\Runners\Import; |
| 4 |
|
| 5 |
use Elementor\Plugin; |
| 6 |
use Elementor\Core\Settings\Page\Manager as PageManager; |
| 7 |
use Elementor\App\Modules\ImportExport\Utils; |
| 8 |
|
| 9 |
class Site_Settings extends Import_Runner_Base { |
| 10 |
|
| 11 |
/** |
| 12 |
* @var int |
| 13 |
*/ |
| 14 |
private $previous_kit_id; |
| 15 |
|
| 16 |
/** |
| 17 |
* @var int |
| 18 |
*/ |
| 19 |
private $active_kit_id; |
| 20 |
|
| 21 |
/** |
| 22 |
* @var int |
| 23 |
*/ |
| 24 |
private $imported_kit_id; |
| 25 |
|
| 26 |
public static function get_name(): string { |
| 27 |
return 'site-settings'; |
| 28 |
} |
| 29 |
|
| 30 |
public function should_import( array $data ) { |
| 31 |
return ( |
| 32 |
isset( $data['include'] ) && |
| 33 |
in_array( 'settings', $data['include'], true ) && |
| 34 |
! empty( $data['site_settings']['settings'] ) |
| 35 |
); |
| 36 |
} |
| 37 |
|
| 38 |
public function import( array $data, array $imported_data ) { |
| 39 |
$new_site_settings = $data['site_settings']['settings']; |
| 40 |
$title = $data['manifest']['title'] ?? 'Imported Kit'; |
| 41 |
|
| 42 |
$active_kit = Plugin::$instance->kits_manager->get_active_kit(); |
| 43 |
|
| 44 |
$this->active_kit_id = (int) $active_kit->get_id(); |
| 45 |
$this->previous_kit_id = (int) Plugin::$instance->kits_manager->get_previous_id(); |
| 46 |
|
| 47 |
$result = []; |
| 48 |
|
| 49 |
$old_settings = $active_kit->get_meta( PageManager::META_KEY ); |
| 50 |
|
| 51 |
if ( ! $old_settings ) { |
| 52 |
$old_settings = []; |
| 53 |
} |
| 54 |
|
| 55 |
if ( ! empty( $old_settings['custom_colors'] ) ) { |
| 56 |
$new_site_settings['custom_colors'] = array_merge( $old_settings['custom_colors'], $new_site_settings['custom_colors'] ); |
| 57 |
} |
| 58 |
|
| 59 |
if ( ! empty( $old_settings['custom_typography'] ) ) { |
| 60 |
$new_site_settings['custom_typography'] = array_merge( $old_settings['custom_typography'], $new_site_settings['custom_typography'] ); |
| 61 |
} |
| 62 |
|
| 63 |
if ( ! empty( $new_site_settings['space_between_widgets'] ) ) { |
| 64 |
$new_site_settings['space_between_widgets'] = Utils::update_space_between_widgets_values( $new_site_settings['space_between_widgets'] ); |
| 65 |
} |
| 66 |
|
| 67 |
$new_site_settings = array_replace_recursive( $old_settings, $new_site_settings ); |
| 68 |
|
| 69 |
$new_kit = Plugin::$instance->kits_manager->create_new_kit( $title, $new_site_settings ); |
| 70 |
|
| 71 |
$this->imported_kit_id = (int) $new_kit; |
| 72 |
|
| 73 |
$result['site-settings'] = (bool) $new_kit; |
| 74 |
|
| 75 |
return $result; |
| 76 |
} |
| 77 |
|
| 78 |
public function get_import_session_metadata(): array { |
| 79 |
return [ |
| 80 |
'previous_kit_id' => $this->previous_kit_id, |
| 81 |
'active_kit_id' => $this->active_kit_id, |
| 82 |
'imported_kit_id' => $this->imported_kit_id, |
| 83 |
]; |
| 84 |
} |
| 85 |
} |
| 86 |
|