# elementor/4.3.0-beta3/modules/components/utils/remap-component-instance-ids.php

Elementor Website Builder – more than just a page builder, version 4.3.0-beta3. 59 lines.

- Page: https://pluginprobe.com/plugins/elementor/4.3.0-beta3/code/modules/components/utils/remap-component-instance-ids.php
- Raw: https://pluginprobe.com/plugins/elementor/4.3.0-beta3/raw/modules/components/utils/remap-component-instance-ids.php
- Modified: 2026-09-08T11:16:58+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/elementor/4.3.0-beta3/code/modules/components/utils/remap-component-instance-ids.php#L10-L20`.

```php
<?php

namespace Elementor\Modules\Components\Utils;

use Elementor\Modules\Components\PropTypes\Component_Instance_Prop_Type;

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}

/**
 * Rewrites `component_id` inside every `e-component` widget in an elements tree
 * so it points at the component post recreated on the destination site instead
 * of the source-site post id that was serialized in the exported template.
 *
 * Used by both website-template (customization) and legacy kit import runners
 * before documents are saved.
 */
class Remap_Component_Instance_Ids {
	public static function apply( array $elements, array $post_ids_map ): array {
		if ( empty( $post_ids_map ) ) {
			return $elements;
		}

		return array_map(
			function ( $element ) use ( $post_ids_map ) {
				return self::remap_element( $element, $post_ids_map );
			},
			$elements
		);
	}

	private static function remap_element( $element, array $post_ids_map ) {
		if ( ! is_array( $element ) ) {
			return $element;
		}

		if ( Component_Instance_Prop_Type::is_instance_element( $element ) ) {
			$element['settings'] = self::remap_component_id( $element['settings'] ?? [], $post_ids_map );
		}

		if ( ! empty( $element['elements'] ) && is_array( $element['elements'] ) ) {
			$element['elements'] = self::apply( $element['elements'], $post_ids_map );
		}

		return $element;
	}

	private static function remap_component_id( array $settings, array $post_ids_map ): array {
		$source_id = Component_Instance_Prop_Type::extract_component_id( $settings );

		if ( ! is_numeric( $source_id ) || ! isset( $post_ids_map[ (int) $source_id ] ) ) {
			return $settings;
		}

		return Component_Instance_Prop_Type::set_component_id( $settings, (int) $post_ids_map[ (int) $source_id ] );
	}
}

```
