Server : LiteSpeed
System : Linux quebec.us.hostns.io 5.14.0-687.42.1.el9_8.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Aug 27 11:55:12 EDT 2026 x86_64
User : gazetufm ( 1431)
PHP Version : 8.1.35
Disable Function : NONE
Directory :  /home2/gazetufm/dumoshi.com/wp-content/plugins/wp-mail-smtp/src/Providers/Sendlayer/

📁 Create New:
⬆️ Upload File:
Current Dir [ Writable ] Root [ Writable ]


OR Upload from URL:
URL: Save as:

📄 File: Preflight.php

Path: //home2/gazetufm/dumoshi.com/wp-content/plugins/wp-mail-smtp/src/Providers/Sendlayer/Preflight.php

Size: 2.65 KB

Permissions: 0644

<?php

namespace WPMailSMTP\Providers\Sendlayer;

use WPMailSMTP\Providers\Preflight\ApiPreflightAbstract;
use WPMailSMTP\Providers\Preflight\Code;
use WPMailSMTP\Providers\Preflight\Findings;

/**
 * Reads the account's webhook list to establish whether the API key works.
 *
 * @since 4.10.0
 */
class Preflight extends ApiPreflightAbstract {

	/**
	 * Webhook list. The only other read returns recipient addresses and message subjects.
	 *
	 * @since 4.10.0
	 *
	 * @var string
	 */
	private const API_WEBHOOKS = 'https://console.sendlayer.com/api/v1/webhooks';

	/**
	 * The key was not recognised.
	 *
	 * @since 4.10.0
	 *
	 * @var int
	 */
	private const CODE_INVALID_KEY = 13;

	/**
	 * Read the fields this check sends.
	 *
	 * @since 4.10.0
	 *
	 * @param array $config Mailer options as submitted.
	 *
	 * @return array|null
	 */
	protected function sanitize_config( $config ) {

		$sanitized_config = [
			'api_key' => sanitize_text_field( (string) ( $config['api_key'] ?? '' ) ),
		];

		if ( $sanitized_config['api_key'] === '' ) {
			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();
		$response = $this->request(
			self::API_WEBHOOKS,
			[ 'headers' => [ 'Authorization' => 'Bearer ' . $config['api_key'] ] ]
		);
		$body     = $this->json( $response );

		// Routing is resolved before authentication, so an unknown path answers 200 with an `Errors`
		// array and no code, with any credential or none. The edge's own 403 also carries a field named
		// `error_code`, so the code inside SendLayer's envelope is the only verdict.
		$errors = isset( $body['Errors'] ) && is_array( $body['Errors'] ) ? $body['Errors'] : [];

		if ( $this->verdict_code( $errors ) === self::CODE_INVALID_KEY ) {
			$findings->add( $this->error( Code::AUTH_FAILED, 'api_key' ) );
		}

		return $findings;
	}

	/**
	 * Find the one enumerated code in the envelope.
	 *
	 * `Errors` is typed as a list, so the entry carrying the code need not be the first.
	 *
	 * @since 4.10.0
	 *
	 * @param array $errors SendLayer's error list.
	 *
	 * @return int Zero when the envelope carries no single enumerated code.
	 */
	private function verdict_code( $errors ) {

		$enumerated = [ self::CODE_INVALID_KEY ];
		$found      = [];

		foreach ( $errors as $entry ) {
			$code = is_array( $entry ) && isset( $entry['Code'] ) ? (int) $entry['Code'] : 0;

			if ( in_array( $code, $enumerated, true ) ) {
				$found[ $code ] = true;
			}
		}

		$codes = array_keys( $found );

		return count( $codes ) === 1 ? (int) $codes[0] : 0;
	}
}

← Back to Directory Edit File 🔒 Chmod

WP File Manager