gin::elementor()->db->switch_to_post( $post_id ); try { return Plugin::elementor()->dynamic_tags->get_tag_data_content( null, $tag_name, $tag_settings ); } finally { Plugin::elementor()->db->restore_current_post(); } } return array_map( function ( $item ) use ( $post_id ) { return $this->resolve_dynamic_tags_in_settings( $item, $post_id ); }, $value ); } private function build_cssid_map( array $form_element, int $post_id ): array { $map = []; $this->collect_cssid_mappings( $form_element['elements'] ?? [], $map, $post_id ); return $map; } private function collect_cssid_mappings( array $elements, array &$map, int $post_id ): void { foreach ( $elements as $element ) { if ( ! empty( $element['elements'] ) ) { $this->collect_cssid_mappings( $element['elements'], $map, $post_id ); } if ( ! $this->is_atomic_form_field_element( $element ) ) { continue; } $element_id = $element['id'] ?? ''; $cssid = $this->get_field_cssid( $element, $post_id ); if ( $element_id && '' !== $cssid && ! isset( $map[ $cssid ] ) ) { $map[ $cssid ] = $element_id; } } } private function is_atomic_form_field_element( array $element ): bool { if ( 'widget' !== ( $element['elType'] ?? '' ) ) { return false; } $widget_type = $element['widgetType'] ?? ''; return in_array( $widget_type, self::FORM_FIELD_WIDGET_TYPES, true ); } private function get_field_cssid( array $element, int $post_id ): string { $resolved = $this->resolve_raw_settings( $element, $post_id ); $cssid = $resolved['_cssid'] ?? ''; if ( ! is_string( $cssid ) || '' === $cssid ) { return ''; } return sanitize_text_field( $cssid ); } private function send_invalid_form_response(): void { wp_send_json_error( [ 'message' => Ajax_Handler::get_default_message( Ajax_Handler::INVALID_FORM, [] ), ] ); } private function send_error_response( string $message = '' ): void { wp_send_json_error( [ 'message' => '' !== $message ? $message : Ajax_Handler::get_default_message( Ajax_Handler::ERROR, [] ), ] ); } private function send_response( array $action_results, bool $all_actions_succeeded, array $failed_actions ): void { $response_data = [ 'actionResults' => $action_results, 'allActionsSucceeded' => $all_actions_succeeded, 'failedActions' => $failed_actions, ]; if ( $all_actions_succeeded ) { wp_send_json_success( [ 'message' => Ajax_Handler::get_default_message( Ajax_Handler::SUCCESS, [] ), 'data' => $response_data, ] ); } else { $has_success = ! empty( $action_results ) && count( $failed_actions ) < count( $action_results ); if ( $has_success ) { wp_send_json_success( [ 'message' => Ajax_Handler::get_default_message( Ajax_Handler::SUCCESS, [] ), 'data' => $response_data, ] ); } else { wp_send_json_error( [ 'message' => Ajax_Handler::get_default_message( Ajax_Handler::ERROR, [] ), 'data' => $response_data, ] ); } } } public function __construct() { add_action( 'wp_ajax_elementor_pro_atomic_forms_send_form', [ $this, 'ajax_send_form' ] ); add_action( 'wp_ajax_nopriv_elementor_pro_atomic_forms_send_form', [ $this, 'ajax_send_form' ] ); } }