| @@ -15,8 +15,10 @@ | ||
| 15 | 15 | use Elementor\Modules\Components\Transformers\Overridable_Transformer; |
| 16 | 16 | use Elementor\Core\Base\Document; |
| 17 | 17 | use Elementor\Modules\Components\PropTypes\Override_Prop_Type; |
| 18 | 18 | use Elementor\Modules\Components\Transformers\Override_Transformer; |
| 19 | +use Elementor\Modules\Components\Utils\Remap_Component_Instance_Ids; | |
| 20 | +use Elementor\Modules\Components\Utils\Strip_Component_Instances; | |
| 19 | 21 | use Elementor\Modules\Components\Variants\Component_Variant_Class_Collector; |
| 20 | 22 | use Elementor\Modules\Components\Widgets\Component_Instance; |
| 21 | 23 | use Elementor\Modules\Components\Schema\Overridable_LLM_Filter; |
| 22 | 24 | |
| @@ -29,8 +31,24 @@ | ||
| 29 | 31 | const EXPERIMENT_VARIANTS_NAME = 'e_component_variants'; |
| 30 | 32 | const PACKAGES = [ 'editor-components' ]; |
| 31 | 33 | |
| 32 | 34 | /** |
| 35 | + * Local kill switch for components import/export. Off by default: on export the | |
| 36 | + * `elementor_component` post type is excluded, on import any `e-component` widgets | |
| 37 | + * that survived from a foreign zip are stripped. Flip to `true` in the source | |
| 38 | + * to unblock the flag-on branch when working on the real feature (`Remap_Component_Instance_Ids` | |
| 39 | + * and its test cover that path today). | |
| 40 | + * | |
| 41 | + * Not an experiment on purpose: experiments are serialized into exported kits by | |
| 42 | + * `Site_Settings::export_experiments()` and rehydrated on import, so a hidden experiment | |
| 43 | + * here would let a source-site override silently turn the guard off on every destination site. | |
| 44 | + * | |
| 45 | + * Remove this constant, `is_import_export_supported()` and every `! is_import_export_supported()` | |
| 46 | + * branch once components are a first-class part of import/export. | |
| 47 | + */ | |
| 48 | + const IS_IMPORT_EXPORT_SUPPORTED = false; | |
| 49 | + | |
| 50 | + /** | |
| 33 | 51 | * Variants meta must be persisted before `Global_Classes_Relations::on_document_save()` |
| 34 | 52 | * (default priority 10) reads it via the `extract_class_ids_from_post` filter. |
| 35 | 53 | */ |
| 36 | 54 | const SAVE_VARIANTS_PRIORITY = 9; |
| @@ -64,8 +82,9 @@ | ||
| 64 | 82 | 10, |
| 65 | 83 | 2 |
| 66 | 84 | ); |
| 67 | 85 | } |
| 86 | + | |
| 68 | 87 | add_filter( 'elementor/global_classes/additional_post_types', fn( $post_types ) => array_merge( $post_types, [ Component_Document::TYPE ] ) ); |
| 69 | 88 | add_filter( 'elementor/utils/find_element_recursive/inner_elements', fn( array $inner_elements, array $element_data ) => $this->get_inner_elements_for_search( $inner_elements, $element_data ), 10, 2 ); |
| 70 | 89 | |
| 71 | 90 | add_action( 'elementor/atomic-widgets/settings/transformers/register', fn ( $transformers ) => $this->register_settings_transformers( $transformers ) ); |
| @@ -86,8 +105,36 @@ | ||
| 86 | 105 | } |
| 87 | 106 | |
| 88 | 107 | public static function is_variants_experiment_active(): bool { |
| 89 | 108 | return Plugin::$instance->experiments->is_feature_active( self::EXPERIMENT_VARIANTS_NAME ); |
| 109 | + } | |
| 110 | + | |
| 111 | + public static function is_import_export_supported(): bool { | |
| 112 | + return self::IS_IMPORT_EXPORT_SUPPORTED; | |
| 113 | + } | |
| 114 | + | |
| 115 | + /** | |
| 116 | + * Single entry point for import runners to normalize the elements tree of an imported | |
| 117 | + * document with respect to component instances. When components round-trip is enabled | |
| 118 | + * (flag on) it rewrites source-site component ids to their destination-site equivalents; | |
| 119 | + * when disabled (flag off) it strips any `e-component` widget that survived from a | |
| 120 | + * legacy zip so the destination editor never opens a document with dangling instances. | |
| 121 | + * | |
| 122 | + * Kept as a static helper on the module so both `import-export-customization` and legacy | |
| 123 | + * `import-export` import paths stay in sync when `IS_IMPORT_EXPORT_SUPPORTED` flips. | |
| 124 | + */ | |
| 125 | + public static function prepare_imported_elements( array $elements, array $post_ids_map ): array { | |
| 126 | + return self::is_import_export_supported() | |
| 127 | + ? Remap_Component_Instance_Ids::apply( $elements, $post_ids_map ) | |
| 128 | + : Strip_Component_Instances::apply( $elements ); | |
| 129 | + } | |
| 130 | + | |
| 131 | + /** | |
| 132 | + * Post types that must be excluded from the import/export runners when components | |
| 133 | + * round-trip is disabled. Same gating as `prepare_imported_elements()`. | |
| 134 | + */ | |
| 135 | + public static function excluded_import_export_post_types(): array { | |
| 136 | + return self::is_import_export_supported() ? [] : [ Component_Document::TYPE ]; | |
| 90 | 137 | } |
| 91 | 138 | |
| 92 | 139 | /** |
| 93 | 140 | * Dev-only gate that keeps per-instance Component Variants off trunk while the feature ships |