| 1 |
<?php |
| 2 |
|
| 3 |
namespace Elementor\Modules\DefaultStyles\ImportExportCustomization\Runners; |
| 4 |
|
| 5 |
use Elementor\App\Modules\ImportExportCustomization\Runners\Export\Export_Runner_Base; |
| 6 |
use Elementor\Modules\AtomicWidgets\Module as Atomic_Widgets_Module; |
| 7 |
use Elementor\Modules\DefaultStyles\Default_Styles_Repository; |
| 8 |
use Elementor\Modules\DefaultStyles\ImportExportCustomization\Import_Export_Customization; |
| 9 |
use Elementor\Plugin; |
| 10 |
|
| 11 |
if ( ! defined( 'ABSPATH' ) ) { |
| 12 |
exit; |
| 13 |
} |
| 14 |
|
| 15 |
class Export extends Export_Runner_Base { |
| 16 |
public static function get_name(): string { |
| 17 |
return 'default-styles'; |
| 18 |
} |
| 19 |
|
| 20 |
public function should_export( array $data ): bool { |
| 21 |
return ( |
| 22 |
isset( $data['include'] ) && |
| 23 |
in_array( 'settings', $data['include'], true ) && |
| 24 |
$this->is_feature_active() |
| 25 |
); |
| 26 |
} |
| 27 |
|
| 28 |
private function is_feature_active(): bool { |
| 29 |
return Plugin::$instance->experiments->is_feature_active( Atomic_Widgets_Module::EXPERIMENT_NAME ); |
| 30 |
} |
| 31 |
|
| 32 |
public function export( array $data ): array { |
| 33 |
$kit = Plugin::$instance->kits_manager->get_active_kit(); |
| 34 |
|
| 35 |
if ( ! $kit ) { |
| 36 |
return $this->empty_result(); |
| 37 |
} |
| 38 |
|
| 39 |
$files = []; |
| 40 |
$skip_migration = true; |
| 41 |
|
| 42 |
Default_Styles_Repository::make( $kit )->each_item( |
| 43 |
static function ( array $style_data ) use ( &$files ) { |
| 44 |
if ( empty( $style_data['id'] ) || ! is_string( $style_data['id'] ) ) { |
| 45 |
return; |
| 46 |
} |
| 47 |
|
| 48 |
$tag = $style_data['id']; |
| 49 |
|
| 50 |
$files[] = [ |
| 51 |
'path' => Import_Export_Customization::DIRECTORY_NAME . '/' . $tag . '.json', |
| 52 |
'data' => wp_json_encode( $style_data ), |
| 53 |
]; |
| 54 |
}, |
| 55 |
$skip_migration |
| 56 |
); |
| 57 |
|
| 58 |
if ( empty( $files ) ) { |
| 59 |
return $this->empty_result(); |
| 60 |
} |
| 61 |
|
| 62 |
return [ |
| 63 |
'files' => $files, |
| 64 |
'manifest' => [], |
| 65 |
]; |
| 66 |
} |
| 67 |
|
| 68 |
private function empty_result(): array { |
| 69 |
return [ |
| 70 |
'manifest' => [], |
| 71 |
'files' => [], |
| 72 |
]; |
| 73 |
} |
| 74 |
} |
| 75 |
|