| @@ -49,37 +49,18 @@ | ||
| 49 | 49 | return []; |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | foreach ( $interactions['items'] as &$interaction ) { |
| 53 | - if ( ! isset( $interaction['$$type'] ) || 'interaction-item' !== $interaction['$$type'] ) { | |
| 54 | - continue; | |
| 55 | - } | |
| 56 | - | |
| 57 | - $existing_id = null; | |
| 58 | - if ( isset( $interaction['value']['interaction_id']['value'] ) ) { | |
| 59 | - $existing_id = $interaction['value']['interaction_id']['value']; | |
| 60 | - } | |
| 61 | - | |
| 62 | - if ( $existing_id && $this->is_temp_id( $existing_id ) ) { | |
| 63 | - $interaction['value']['interaction_id'] = [ | |
| 64 | - '$$type' => 'string', | |
| 65 | - 'value' => $this->get_next_interaction_id( $element_id ), | |
| 66 | - ]; | |
| 67 | - } elseif ( $existing_id ) { | |
| 68 | - $this->ids_lookup[] = $existing_id; | |
| 53 | + if ( array_key_exists( 'interaction_id', $interaction ) ) { | |
| 54 | + $this->ids_lookup[] = $interaction['interaction_id']; | |
| 69 | 55 | } else { |
| 70 | - $interaction['value']['interaction_id'] = [ | |
| 71 | - '$$type' => 'string', | |
| 72 | - 'value' => $this->get_next_interaction_id( $element_id ), | |
| 73 | - ]; | |
| 56 | + $interaction = array_merge( [ | |
| 57 | + 'interaction_id' => $this->get_next_interaction_id( $element_id ), | |
| 58 | + ], $interaction ); | |
| 74 | 59 | } |
| 75 | 60 | } |
| 76 | 61 | |
| 77 | 62 | return wp_json_encode( $interactions ); |
| 78 | - } | |
| 79 | - | |
| 80 | - private function is_temp_id( $id ) { | |
| 81 | - return is_string( $id ) && strpos( $id, 'temp-' ) === 0; | |
| 82 | 63 | } |
| 83 | 64 | |
| 84 | 65 | private function decode_interactions( $interactions ) { |
| 85 | 66 | if ( is_array( $interactions ) ) { |