> $steps Steps. * @return array> */ public static function normalize_list( array $steps ): array { $out = array(); foreach ( $steps as $step ) { if ( ! is_array( $step ) ) { continue; } $out[] = self::normalize_step( $step ); } return array_values( $out ); } /** * @param array $step Step. * @return array */ public static function normalize_step( array $step ): array { $type = isset( $step['type'] ) ? sanitize_key( (string) $step['type'] ) : 'unknown'; $normalized = $step; $normalized['type'] = $type; $conditions = ConditionEvaluator::get_step_conditions( $step ); if ( ! empty( $conditions ) && empty( $normalized['condition'] ) ) { $normalized['condition'] = $conditions[0]; } if ( 'wait' === $type && ! isset( $normalized['duration_seconds'] ) ) { $wait = new WaitAction(); $normalized['duration_seconds'] = $wait->computeDelayInSeconds( $step ); } if ( in_array( $type, array( 'send_email', 'send_sms', 'send_whatsapp' ), true ) ) { $actions = Actions::getActions(); if ( isset( $actions[ $type ]['action_class'] ) ) { $class = $actions[ $type ]['action_class']; $action = new $class(); if ( method_exists( $action, 'getTo' ) && empty( $normalized['to'] ) ) { $normalized['to'] = (string) $action->getTo( $step ); } if ( method_exists( $action, 'getMessage' ) && empty( $normalized['message'] ) ) { $normalized['message'] = (string) $action->getMessage( $step ); } if ( method_exists( $action, 'getMetadata' ) && empty( $normalized['metadata'] ) ) { $normalized['metadata'] = $action->getMetadata( $step ); } } if ( 'send_email' === $type && empty( $normalized['template_id'] ) && ! empty( $normalized['email_template_id'] ) ) { $normalized['template_id'] = $normalized['email_template_id']; } } if ( 'branch' === $type ) { $true_steps = isset( $step['true_steps'] ) && is_array( $step['true_steps'] ) ? $step['true_steps'] : array(); $false_steps = isset( $step['false_steps'] ) && is_array( $step['false_steps'] ) ? $step['false_steps'] : array(); $normalized['true_steps'] = self::normalize_list( $true_steps ); $normalized['false_steps'] = self::normalize_list( $false_steps ); } return $normalized; } }