mailer = $mailer; $this->from_email = $email; $this->sending_domain = $sending_domain; $this->connection = $connection ?? wp_mail_smtp()->get_connections_manager()->get_primary_connection(); $params = [ 'mailer' => $mailer, 'email' => base64_encode( $email ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode 'domain' => $sending_domain, ]; $response = wp_remote_get( add_query_arg( $params, self::ENDPOINT ), [ 'user-agent' => Helpers::get_default_user_agent(), ] ); if ( is_wp_error( $response ) ) { $this->results = [ 'success' => false, 'message' => method_exists( $response, 'get_error_message' ) ? $response->get_error_message() : esc_html__( 'Something went wrong. Please try again later.', 'wp-mail-smtp' ), 'checks' => [], ]; } else { $this->results = json_decode( wp_remote_retrieve_body( $response ), true ); } DomainCheckState::record( $this, $this->connection ); } /** * Simple getter for the API results. * * @since 2.6.0 * * @return array */ public function get_results() { return $this->results; } /** * Simple getter for the checked mailer. * * @since 4.10.1 * * @return string */ public function get_mailer() { return $this->mailer; } /** * Simple getter for the checked From email address. * * @since 4.10.1 * * @return string */ public function get_from_email() { return $this->from_email; } /** * Simple getter for the checked sending domain. * * @since 4.10.1 * * @return string */ public function get_sending_domain() { return $this->sending_domain; } /** * Simple getter for the checked connection. * * @since 4.10.0 * * @return ConnectionInterface */ public function get_connection() { return $this->connection; } /** * Check if the domain checker has found any errors. * * @since 2.6.0 * * @return bool */ public function has_errors() { if ( empty( $this->results['success'] ) ) { return true; } if ( empty( $this->results['checks'] ) ) { return false; } $has_error = false; foreach ( $this->results['checks'] as $check ) { if ( $check['state'] === 'error' ) { $has_error = true; break; } } return $has_error; } /** * Check if the domain checker has not found any errors or warnings. * * @since 2.6.0 * * @return bool */ public function no_issues() { if ( empty( $this->results['success'] ) ) { return false; } $no_issues = true; foreach ( $this->results['checks'] as $check ) { if ( in_array( $check['state'], [ 'error', 'warning' ], true ) ) { $no_issues = false; break; } } return $no_issues; } /** * Check if the domain checker support mailer. * * @since 2.7.0 * * @return bool */ public function is_supported_mailer() { return self::is_mailer_supported( $this->mailer ); } /** * Check if the domain checker supports a mailer. * * @since 4.10.1 * * @param string $mailer The plugin mailer slug. * * @return bool */ private static function is_mailer_supported( $mailer ) { return ! in_array( $mailer, [ 'mail', 'pepipostapi' ], true ); } /** * Get the domain checker results html. * * @since 2.8.0 * * @return string */ public function get_results_html() { return self::render_results( $this->get_results(), $this->mailer ); } /** * Get the HTML for domain check results. * * @since 4.10.1 * * @param array $results Domain check API results. * @param string $mailer The plugin mailer slug the check ran for. * * @return string */ public static function render_results( $results, $mailer ) { $allowed_html = [ 'b' => [], 'i' => [], 'a' => [ 'href' => [], 'target' => [], 'rel' => [], ], ]; ob_start(); ?>