sanitize_text_field( (string) ( $config['server_api_token'] ?? '' ) ), 'message_stream' => sanitize_text_field( (string) ( $config['message_stream'] ?? '' ) ), ]; if ( $sanitized_config['server_api_token'] === '' ) { return null; } return $sanitized_config; } /** * Run the check. * * @since 4.10.0 * * @param array $config Mailer options. * * @return Findings */ protected function probe( $config ) { $findings = Findings::none(); $stream = $config['message_stream']; $response = $this->request( self::API_MESSAGE_STREAM . rawurlencode( $stream === '' ? self::DEFAULT_STREAM : $stream ), [ 'headers' => [ 'X-Postmark-Server-Token' => $config['server_api_token'] ] ] ); $body = $this->json( $response ); // The code carries the verdict and the status carries none of its own, a missing stream being a // 422. The published table is incomplete, so an unrecognised code concludes nothing. $code = isset( $body['ErrorCode'] ) ? (int) $body['ErrorCode'] : 0; if ( $code === self::ERROR_TOKEN_REJECTED ) { $findings->add( $this->error( Code::AUTH_FAILED, 'server_api_token' ) ); return $findings; } if ( $code === self::ERROR_STREAM_NOT_FOUND && $stream !== '' ) { $findings->add( $this->error( self::STREAM_NOT_FOUND, 'message_stream' ) ); } return $findings; } }