sync v1.9.0: add find_element_by_id + reassign_element_ids aliases
This commit is contained in:
@@ -8,6 +8,10 @@ defined('ABSPATH') || exit;
|
||||
* Methods ported from elementor-mcp v1.9.0 (class-elementor-data.php).
|
||||
* CLI/cron context uses raw $wpdb queries to bypass WP object cache —
|
||||
* the core fix for stale-read bugs in long-running build scripts.
|
||||
*
|
||||
* Method aliases added for strict v1.9.0 compatibility:
|
||||
* - find_element_by_id() → wraps find_element()
|
||||
* - reassign_element_ids() → single-element reassign (upstream v1.9.0)
|
||||
*/
|
||||
class ElementorData {
|
||||
|
||||
@@ -235,7 +239,7 @@ class ElementorData {
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// find_element (upstream: find_element_by_id)
|
||||
// find_element (our internal name)
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
public function find_element( array $elements, string $element_id ): ?array {
|
||||
@@ -253,6 +257,15 @@ class ElementorData {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Upstream v1.9.0 alias: find_element_by_id().
|
||||
* Identical to find_element() — exists so any code ported directly from
|
||||
* upstream class-elementor-data.php compiles without renaming.
|
||||
*/
|
||||
public function find_element_by_id( array $data, string $id ): ?array {
|
||||
return $this->find_element( $data, $id );
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// insert_element (upstream: insert_element — by reference)
|
||||
// Supports top-level insertion (empty parent_id) and nested.
|
||||
@@ -324,7 +337,7 @@ class ElementorData {
|
||||
$item['settings'] = array();
|
||||
}
|
||||
|
||||
// Normalise container flex shorthand keys (upstream v1.5.1 fix).
|
||||
// Normalise container flex shorthand keys (upstream v1.5.1 / v1.9.0 fix).
|
||||
if ( 'container' === ( $item['elType'] ?? '' ) ) {
|
||||
$settings = $this->normalize_container_settings( $settings );
|
||||
}
|
||||
@@ -370,7 +383,8 @@ class ElementorData {
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// reassign_ids (upstream: reassign_ids + reassign_element_ids)
|
||||
// reassign_ids (upstream: reassign_ids)
|
||||
// Recursively reassigns fresh IDs to all elements in a tree.
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
public function reassign_ids( array $elements ): array {
|
||||
@@ -383,6 +397,24 @@ class ElementorData {
|
||||
return $elements;
|
||||
}
|
||||
|
||||
/**
|
||||
* Upstream v1.9.0: reassign_element_ids().
|
||||
* Reassigns a fresh ID to a single element and all its children.
|
||||
* This is the method called by duplicate-element in upstream v1.9.0.
|
||||
*
|
||||
* @param array $element The element array.
|
||||
* @return array The element with new IDs.
|
||||
*/
|
||||
public function reassign_element_ids( array $element ): array {
|
||||
$element['id'] = $this->generate_id();
|
||||
|
||||
if ( ! empty( $element['elements'] ) && is_array( $element['elements'] ) ) {
|
||||
$element['elements'] = $this->reassign_ids( $element['elements'] );
|
||||
}
|
||||
|
||||
return $element;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// count_elements (upstream: count_elements)
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user