apped_field = [ 'id' => $field['custom_id'], 'type' => $field['field_type'], 'label' => $field['field_label'], ]; if ( isset( $field['field_options'] ) ) { $mapped_field['options'] = preg_split( '/(\r\n|\n|\r)/', $field['field_options'] ); } if ( isset( $field['allow_multiple'] ) ) { $mapped_field['is_multiple'] = 'true' === $field['allow_multiple']; } return $mapped_field; }, $fields, array_keys( $fields ) ), ] ); } /** * It listen for all the form actions and log the result into the database. * * @param Action_Base $action Should be class based on ActionBase (do not type hint to support third party plugins) * @param \Exception|null $exception */ private function save_action_log( $action, \Exception $exception = null ) { if ( ! $this->submission_id || $action->get_name() === $this->get_name() ) { return; } $query = Query::get_instance(); $error_message = null; if ( $exception ) { $error_message = $exception->getMessage(); $status = Query::ACTIONS_LOG_STATUS_FAILED; } else { $this->actions_succeeded_count += 1; $query->update_submission( $this->submission_id, [ 'actions_succeeded_count' => $this->actions_succeeded_count, ] ); $status = Query::ACTIONS_LOG_STATUS_SUCCESS; } $query->add_action_log( $this->submission_id, $action, $status, $error_message ); } /** * Save_To_Database constructor. */ public function __construct() { add_action( 'elementor_pro/forms/actions/after_run', function ( Action_Base $action, \Exception $exception = null ) { $this->save_action_log( $action, $exception ); }, 10, 2 ); } }