tring[] $actions * @return string[] */ private static function normalize_actions_order( array $actions ): array { if ( ! in_array( Action_Type::COLLECT_SUBMISSIONS, $actions, true ) ) { return $actions; } $rest = array_values( array_filter( $actions, function ( $type ) { return Action_Type::COLLECT_SUBMISSIONS !== $type; } ) ); return array_merge( [ Action_Type::COLLECT_SUBMISSIONS ], $rest ); } /** * @param string[] $actions */ private static function count_non_collect_actions( array $actions ): int { $n = 0; foreach ( $actions as $type ) { if ( Action_Type::COLLECT_SUBMISSIONS !== $type ) { $n++; } } return $n; } /** * Log outcomes for actions other than collect; updates `actions_succeeded_count` on success. * * @param array $context * @param int $actions_succeeded_count */ private static function persist_action_log( array $context, string $action_type, bool $success, ?string $error_message, int &$actions_succeeded_count ): void { if ( Action_Type::COLLECT_SUBMISSIONS === $action_type ) { return; } $submission_id = isset( $context['submission_id'] ) ? (int) $context['submission_id'] : 0; if ( $submission_id <= 0 ) { return; } $query = Query::get_instance(); $presenter = new Action_Log_Presenter( $action_type, self::resolve_action_label( $action_type ) ); if ( $success ) { $actions_succeeded_count++; $query->update_submission( $submission_id, [ 'actions_succeeded_count' => $actions_succeeded_count ] ); $query->add_action_log( $submission_id, $presenter, Query::ACTIONS_LOG_STATUS_SUCCESS, null ); } else { $query->add_action_log( $submission_id, $presenter, Query::ACTIONS_LOG_STATUS_FAILED, $error_message ); } } private static function resolve_action_label( string $action_type ): string { $labels = [ Action_Type::EMAIL => esc_html__( 'Email', 'elementor-pro' ), Action_Type::WEBHOOK => esc_html__( 'Webhook', 'elementor-pro' ), ]; if ( isset( $labels[ $action_type ] ) ) { return $labels[ $action_type ]; } $default_label = ucwords( str_replace( '-', ' ', $action_type ) ); /** * Filters the admin label for an atomic form action in the submissions action log. * First argument: default label string. Second: action type slug. */ return (string) apply_filters( 'elementor_pro/atomic_forms/action_log_label', $default_label, $action_type ); } /** * Initialize default actions. * * @return void */ public static function init(): void { self::register_action( new Email_Action() ); self::register_action( new Collect_Submissions_Action() ); self::register_action( new Webhook_Action() ); /** * Allow registering custom actions. * * @param Action_Factory $factory The action factory instance. */ do_action( 'elementor_pro/atomic_forms/actions/register', __CLASS__ ); } }