modules/kit-elements-defaults/import-export/runners
export.php
1.7 KB
3 years ago
import.php
2.1 KB
3 years ago
export.php in Elementor Website Builder – more than just a page builder 3.26.2, at modules/kit-elements-defaults/import-export/runners/export.php
| 1 | <?php |
| 2 | namespace Elementor\Modules\KitElementsDefaults\ImportExport\Runners; |
| 3 | |
| 4 | use Elementor\Modules\KitElementsDefaults\ImportExport\Import_Export; |
| 5 | use Elementor\Plugin; |
| 6 | use Elementor\Core\Utils\Collection; |
| 7 | use Elementor\Modules\KitElementsDefaults\Module; |
| 8 | use Elementor\Modules\KitElementsDefaults\Utils\Settings_Sanitizer; |
| 9 | use Elementor\App\Modules\ImportExport\Runners\Export\Export_Runner_Base; |
| 10 | |
| 11 | if ( ! defined( 'ABSPATH' ) ) { |
| 12 | exit; // Exit if accessed directly. |
| 13 | } |
| 14 | |
| 15 | class Export extends Export_Runner_Base { |
| 16 | public static function get_name() : string { |
| 17 | return 'elements-default-values'; |
| 18 | } |
| 19 | |
| 20 | public function should_export( array $data ) { |
| 21 | // Together with site-settings. |
| 22 | return ( |
| 23 | isset( $data['include'] ) && |
| 24 | in_array( 'settings', $data['include'], true ) |
| 25 | ); |
| 26 | } |
| 27 | |
| 28 | public function export( array $data ) { |
| 29 | $kit = Plugin::$instance->kits_manager->get_active_kit(); |
| 30 | |
| 31 | if ( ! $kit ) { |
| 32 | return [ |
| 33 | 'manifest' => [], |
| 34 | 'files' => [], |
| 35 | ]; |
| 36 | } |
| 37 | |
| 38 | $default_values = $kit->get_json_meta( Module::META_KEY ); |
| 39 | |
| 40 | if ( ! $default_values ) { |
| 41 | return [ |
| 42 | 'manifest' => [], |
| 43 | 'files' => [], |
| 44 | ]; |
| 45 | } |
| 46 | |
| 47 | $sanitizer = new Settings_Sanitizer( |
| 48 | Plugin::$instance->elements_manager, |
| 49 | array_keys( Plugin::$instance->widgets_manager->get_widget_types() ) |
| 50 | ); |
| 51 | |
| 52 | $default_values = ( new Collection( $default_values ) ) |
| 53 | ->map( function ( $settings, $type ) use ( $sanitizer, $kit ) { |
| 54 | return $sanitizer |
| 55 | ->for( $type ) |
| 56 | ->using( $settings ) |
| 57 | ->remove_invalid_settings() |
| 58 | ->kses_deep() |
| 59 | ->prepare_for_export( $kit ) |
| 60 | ->get(); |
| 61 | } ) |
| 62 | ->all(); |
| 63 | |
| 64 | return [ |
| 65 | 'files' => [ |
| 66 | 'path' => Import_Export::FILE_NAME, |
| 67 | 'data' => $default_values, |
| 68 | ], |
| 69 | ]; |
| 70 | } |
| 71 | } |
| 72 |