| 1 |
<?php |
| 2 |
|
| 3 |
namespace Elementor\App\Modules\ImportExportCustomization\Compatibility; |
| 4 |
|
| 5 |
use Elementor\App\Modules\ImportExportCustomization\Module; |
| 6 |
|
| 7 |
if ( ! defined( 'ABSPATH' ) ) { |
| 8 |
exit; // Exit if accessed directly. |
| 9 |
} |
| 10 |
|
| 11 |
/** |
| 12 |
* Handles conversion from manifest format v2.0 to v3.0 |
| 13 |
* Main change: site-settings changed from array of tab keys to object with boolean values |
| 14 |
*/ |
| 15 |
class Customization extends Base_Adapter { |
| 16 |
|
| 17 |
/** |
| 18 |
* Check if compatibility is needed based on manifest version |
| 19 |
* |
| 20 |
* @param array $manifest_data |
| 21 |
* @param array $meta |
| 22 |
* @return bool |
| 23 |
*/ |
| 24 |
public static function is_compatibility_needed( array $manifest_data, array $meta ) { |
| 25 |
// Check if we have an old version (2.0 or lower) |
| 26 |
$version = $manifest_data['version'] ?? '1.0'; |
| 27 |
return version_compare( $version, '3.0', '<' ); |
| 28 |
} |
| 29 |
|
| 30 |
/** |
| 31 |
* Adapt the manifest from old format to new format |
| 32 |
* |
| 33 |
* @param array $manifest_data |
| 34 |
* @return array |
| 35 |
*/ |
| 36 |
public function adapt_manifest( array $manifest_data ) { |
| 37 |
// Check if site-settings needs adaptation |
| 38 |
if ( isset( $manifest_data['site-settings'] ) && is_array( $manifest_data['site-settings'] ) ) { |
| 39 |
// Old format: array of tab keys |
| 40 |
// New format: object with boolean values for each setting type |
| 41 |
|
| 42 |
$old_site_settings = $manifest_data['site-settings']; |
| 43 |
|
| 44 |
// Initialize new format with all settings as false |
| 45 |
$new_site_settings = [ |
| 46 |
'theme' => false, |
| 47 |
'globalColors' => false, |
| 48 |
'globalFonts' => false, |
| 49 |
'themeStyleSettings' => false, |
| 50 |
'generalSettings' => false, |
| 51 |
'experiments' => false, |
| 52 |
]; |
| 53 |
|
| 54 |
// Map old tab keys to new setting types |
| 55 |
$tab_mapping = [ |
| 56 |
'settings-global-colors' => 'globalColors', |
| 57 |
'settings-global-typography' => 'globalFonts', |
| 58 |
'theme-style-typography' => 'themeStyleSettings', |
| 59 |
'settings-general' => 'generalSettings', |
| 60 |
]; |
| 61 |
|
| 62 |
// If we have tab keys, assume all were exported (true) |
| 63 |
if ( ! empty( $old_site_settings ) ) { |
| 64 |
// In the old format, if site-settings was included, all settings were exported |
| 65 |
$new_site_settings = [ |
| 66 |
'theme' => true, |
| 67 |
'globalColors' => true, |
| 68 |
'globalFonts' => true, |
| 69 |
'themeStyleSettings' => true, |
| 70 |
'generalSettings' => true, |
| 71 |
'experiments' => true, |
| 72 |
]; |
| 73 |
} |
| 74 |
|
| 75 |
$manifest_data['site-settings'] = $new_site_settings; |
| 76 |
} |
| 77 |
|
| 78 |
return $manifest_data; |
| 79 |
} |
| 80 |
} |
| 81 |
|