/** * Process smart routing. * * @since 3.7.0 * * @param array $args Array of the `wp_mail` function arguments. */ public function process_smart_routing( $args ) { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.TooHigh $connections_manager = wp_mail_smtp()->get_connections_manager(); // Bail if email connection was already set. if ( ! empty( $connections_manager->get_mail_connection( false ) ) ) { return; } $wp_mail_args = new WPMailArgs( $args ); // Bail if it's a test email. if ( $wp_mail_args->get_header( 'X-Mailer-Type' ) === 'WPMailSMTP/Admin/Test' || $wp_mail_args->get_header( 'X-Mailer-Type' ) === 'WPMailSMTP/Admin/SetupWizard/Test' ) { return; } $conditional_logic = new ConditionalLogic( $wp_mail_args ); $routes = Options::init()->get( 'smart_routing', 'routes' ); // Define o limite de envios por conexão por dia $max_envios_por_dia = apply_filters( 'wp_mail_smtp_smart_routing_max_daily_emails', 100 ); if ( ! empty( $routes ) ) { foreach ( $routes as $route ) { $connection_id = isset( $route['connection_id'] ) ? $route['connection_id'] : false; $conditionals = isset( $route['conditionals'] ) ? $route['conditionals'] : false; $connection = $connections_manager->get_connection( $connection_id, false ); if ( empty( $connection ) || empty( $conditionals ) ) { continue; } if ( $conditional_logic->process( $conditionals ) ) { // Verifica limite de envio para esta conexão $chave_limite = 'wp_mail_smtp_route_limit_' . $connection_id; $contador = get_transient( $chave_limite ); if ( $contador >= $max_envios_por_dia ) { error_log( "Limite de envios atingido para a conexão ID: $connection_id" ); return; // Não enviará o e-mail } // Incrementa o contador $contador = $contador ? $contador + 1 : 1; set_transient( $chave_limite, $contador, DAY_IN_SECONDS ); // Define a conexão SMTP $connections_manager->set_mail_connection( $connection ); break; } } } }