| 1 |
<?php |
| 2 |
|
| 3 |
namespace Elementor\Modules\Components\Utils; |
| 4 |
|
| 5 |
use Elementor\Modules\Components\PropTypes\Component_Instance_Prop_Type; |
| 6 |
|
| 7 |
if ( ! defined( 'ABSPATH' ) ) { |
| 8 |
exit; // Exit if accessed directly. |
| 9 |
} |
| 10 |
|
| 11 |
/** |
| 12 |
* Removes every `e-component` widget from an elements tree. |
| 13 |
* |
| 14 |
* Used at import time when components round-trip is disabled, to clean up any dangling |
| 15 |
* `e-component` widgets that survived from a zip exported before the flag or by an |
| 16 |
* external site. Dangling instances would point at nonexistent component posts and |
| 17 |
* either render empty or throw in the editor panel. |
| 18 |
*/ |
| 19 |
class Strip_Component_Instances { |
| 20 |
public static function apply( array $elements ): array { |
| 21 |
$result = []; |
| 22 |
|
| 23 |
foreach ( $elements as $element ) { |
| 24 |
if ( ! is_array( $element ) ) { |
| 25 |
$result[] = $element; |
| 26 |
continue; |
| 27 |
} |
| 28 |
|
| 29 |
if ( Component_Instance_Prop_Type::is_instance_element( $element ) ) { |
| 30 |
continue; |
| 31 |
} |
| 32 |
|
| 33 |
if ( ! empty( $element['elements'] ) && is_array( $element['elements'] ) ) { |
| 34 |
$element['elements'] = self::apply( $element['elements'] ); |
| 35 |
} |
| 36 |
|
| 37 |
$result[] = $element; |
| 38 |
} |
| 39 |
|
| 40 |
return $result; |
| 41 |
} |
| 42 |
} |
| 43 |
|