### Setup command __invoke method Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/api-reference/wp-cli.md Handles the setup command: checks for --force, resolves and validates flags, writes settings, and reports success. Errors occur if already configured without --force, no flags provided, validation fails, or all flags are shadowed by wp-config constants. ```php public function __invoke( $args, $assoc_args ) { $force = isset( $assoc_args['force'] ); unset( $assoc_args['force'] ); $writer = new Writer( new Registry() ); $current_mailer = Options::init()->get( 'mail', 'mailer' ); if ( ! $force && $current_mailer !== '' && $current_mailer !== 'mail' ) { WP_CLI::error( /* "WP Mail SMTP is already configured (mailer: %s).\nUse `wp wp-mail-smtp option set ...` ... --force" */ ); } $resolved = $writer->resolve( $assoc_args ); if ( empty( $resolved ) ) { WP_CLI::error( /* "No configuration flags provided..." */ ); } $writer->validate( $resolved ); $result = $writer->write( $resolved ); if ( empty( $result['written'] ) ) { WP_CLI::error( /* "No settings were stored — every flag passed was shadowed by a wp-config constant..." */ ); } update_option( 'wp_mail_smtp_activation_prevent_redirect', true ); $mailer = $resolved['mail.mailer'] ?? Options::init()->get( 'mail', 'mailer' ); WP_CLI::success( /* "Configured WP Mail SMTP (mailer: %s). Run `wp wp-mail-smtp test ` to verify." */ ); } ``` -------------------------------- ### WPMailSMTP\Core::init() Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/api-reference/core.md Loads plugin translations, setup checklist, upgrade/conflict detection (admin only), Admin\Area, Site Health, Debug Events hooks, and admin notices. ```APIDOC ## WPMailSMTP\Core::init() ### Description Loads plugin translations, setup checklist, upgrade/conflict detection (admin only), Admin\Area, Site Health, Debug Events hooks, and admin notices. ### Method Public method ### Signature ```php public function init() ``` ### Parameters None. ### Return Value None. ``` -------------------------------- ### Install dependencies and build WP Mail SMTP Lite Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/README.md Run in the root of the cloned repository to prepare the plugin for development. ```bash npm install ``` ```bash composer build-lite ``` -------------------------------- ### wp_mail_smtp_setup_wizard_start Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/endpoints.md Starts the hosted wizard and returns a signed REST session. Requires admin area access and capability. ```APIDOC ## [POST] admin-ajax.php?action=wp_mail_smtp_setup_wizard_start ### Description Starts the hosted wizard and returns a signed REST session. Requires admin area access and capability. ### Method POST ### Endpoint admin-ajax.php?action=wp_mail_smtp_setup_wizard_start ### Parameters No parameters documented. ### Response #### Success Response (200) - **session** (string) - Signed REST session #### Response Example { "success": true, "data": { "session": "signed-session-token" } } ``` -------------------------------- ### Usage example: Override initiator resolution Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/api-reference/wp-mail-initiator.md Filters the backtrace used by set_initiator(). The filter receives an array with 'file', 'line', and 'backtrace' keys. Useful for wrapper functions. ```php add_filter( 'wp_mail_smtp_wp_mail_initiator_set_initiator', function ( $backtrace ) { // $backtrace: [ 'file' => ..., 'line' => ..., 'backtrace' => [...] ] return $backtrace; } ); ``` -------------------------------- ### RestApi constructor with settings class filter Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/api-reference/setup-wizard-rest-api.md Constructor for the RestApi class. It applies a filter to allow overriding the settings class, then stores the setup wizard instance and creates a settings object. ```php public function __construct( Hosted $setup_wizard ) { $settings_class = apply_filters( 'wp_mail_smtp_admin_setup_wizard_rest_api_settings_class', Settings::class ); $this->setup_wizard = $setup_wizard; $this->settings = new $settings_class(); } ``` -------------------------------- ### POST /install-plugin Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/endpoints.md Installs and activates a partner plugin from WordPress.org. Requires additional capabilities beyond the route gate. ```APIDOC ## [POST] /install-plugin ### Description Installs and activates a partner plugin from WordPress.org. Requires additional capabilities beyond the route gate. ### Method POST ### Endpoint /install-plugin ### Parameters #### Request Body - **slug** (string) - Required - WordPress.org slug of an offered partner plugin. ### Response #### Success Response (200) - **slug** (string) - The wporg slug. - **is_installed** (bool) - Always `true`. - **is_activated** (bool) - Whether the plugin was activated. #### Response Example ```json { "slug": "...", "is_installed": true, "is_activated": true } ``` ### Error Handling Errors are returned in a 200 envelope: missing permission / missing slug / `WP_Error('wp_mail_smtp_partner_not_offered')`. ### Notes Required capabilities: `install_plugins` + `activate_plugins`. ``` -------------------------------- ### Basic Core Access and Usage Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/api-reference/core.md Shows how to retrieve the singleton Core instance and use it to check if sending is blocked, get the current mailer slug, and render a plugin template. This is the standard bootstrap for every subsystem. ```php // Retrieve the singleton Core and interrogate it. if ( wp_mail_smtp()->is_blocked() ) { // the "Do Not Send" option is on — emails are being dropped. } // Resolve the current mailer slug through the primary connection. $mailer = wp_mail_smtp()->get_connections_manager() ->get_mail_connection()->get_mailer_slug(); // Render a plugin template from a third-party context. $html = wp_mail_smtp_render( 'dashboard/summary', [ 'title' => 'Summary' ], true ); ``` -------------------------------- ### WPMailSMTP\Core::hooks() Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/api-reference/core.md Registers activation hook, DB migrations, Pro loader, Processor/MailCatcher replacement, notifications, tasks, usage tracking, admin bar menu, Connect, Compatibility, dashboard widget, reports, DB repair, connections manager, wp_mail initiator, queue, OptimizedEmailSending, Outlook provider, WPCode library, Setup Wizard launcher, Abilities registrar, SendLayer Quick Connect, email-sending errors handler, and the WP-CLI bootstrap. ```APIDOC ## WPMailSMTP\Core::hooks() ### Description Registers activation hook, DB migrations, Pro loader, Processor/MailCatcher replacement, notifications, tasks, usage tracking, admin bar menu, Connect, Compatibility, dashboard widget, reports, DB repair, connections manager, wp_mail initiator, queue, OptimizedEmailSending, Outlook provider, WPCode library, Setup Wizard launcher, Abilities registrar, SendLayer Quick Connect, email-sending errors handler, and the WP-CLI bootstrap. ### Method Public method ### Signature ```php public function hooks() ``` ### Parameters None. ### Return Value None. ``` -------------------------------- ### Usage example: Parse captured mail args Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/api-reference/wp-mail-initiator.md Uses WPMailArgs to parse the filtered wp_mail args without re-implementing header logic. Retrieves to, subject, from email, and cc header. ```php use WPMailSMTP\WPMailArgs; $args = new WPMailArgs( wp_mail_smtp()->get_processor()->get_filtered_wp_mail_args() ); $to = $args->get_to_email(); $subj = $args->get_subject(); $from = $args->get_from_email(); $cc = $args->get_header( 'cc' ); ``` -------------------------------- ### Full headless configuration with SendGrid Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/api-reference/wp-cli.md Configures the plugin headlessly using the `wp wp-mail-smtp setup` command with the SendGrid mailer. The API key is passed via the `--sendgrid.api_key` flag, which can be set from an environment variable. ```bash wp wp-mail-smtp setup --mail.from_email=noreply@example.com --mail.from_name="Example" \ --mail.mailer=sendgrid --sendgrid.api_key=$SG_KEY ``` -------------------------------- ### Query recorded events with EventsCollection Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/api-reference/debug-events.md Instantiate EventsCollection with filters like type and pagination, then use get_count() for total and get() to iterate rows. Each row is wrapped in an Event object to access methods like get_title(), get_content(), get_created_at_formatted(), and get_initiator(). ```php use WPMailSMTP\Admin\DebugEvents\EventsCollection; use WPMailSMTP\Admin\DebugEvents\Event; $collection = new EventsCollection( [ 'type' => Event::TYPE_ERROR, 'per_page' => 20, 'offset' => 0, ] ); $total = $collection->get_count(); foreach ( $collection->get() as $row ) { $event = new Event( $row ); // $event->get_title(), $event->get_content(), // $event->get_created_at_formatted(), $event->get_initiator() ... } ``` -------------------------------- ### Usage example: Identify email sender at send time Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/api-reference/wp-mail-initiator.md Uses WPMailInitiator to log the initiator name, type, file, and line when wp_mail is called. The closure is hooked to 'wp_mail_smtp_processor_capture_wp_mail_call'. ```php use WPMailSMTP\WPMailInitiator; $initiator = wp_mail_smtp()->get_wp_mail_initiator(); add_action( 'wp_mail_smtp_processor_capture_wp_mail_call', function () { error_log( sprintf( '%s (%s) called wp_mail at %s:%d', $initiator->get_name(), $initiator->get_type(), $initiator->get_file(), $initiator->get_line() ) ); } ); ``` -------------------------------- ### Full headless configuration with SMTP Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/api-reference/wp-cli.md Configures the plugin headlessly using the `wp wp-mail-smtp setup` command with SMTP mailer and all required options. Uses `--smtp.pass-file` to read the password from a file instead of passing it inline. ```bash wp wp-mail-smtp setup --mail.from_email=noreply@example.com --mail.from_name="Example" \ --mail.mailer=smtp --smtp.host=mail.example.com --smtp.port=587 \ --smtp.encryption=tls --smtp.auth=1 --smtp.user=foo --smtp.pass-file=/run/secret/smtp_pass ``` -------------------------------- ### get() - Retrieve a single option with constant priority Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/api-reference/options.md Public method that retrieves an option value. Constants take precedence over database values, which take precedence over defaults. Strips slashes unless the value comes from a constant. Applies the 'wp_mail_smtp_options_get' filter for main options. ```php public function get( $group, $key, $strip_slashes = true ) { $group = sanitize_key( $group ); $key = sanitize_key( $key ); $value = $this->get_const_value( $group, $key, $value ); // constants win if ( $value === null ) { // DB value, else postprocessed default } if ( $strip_slashes && is_string( $value ) && ! $this->is_const_defined( $group, $key ) ) { $value = stripslashes( $value ); } return $this->is_main_options() ? apply_filters( 'wp_mail_smtp_options_get', $value, $group, $key ) : $value; } ``` -------------------------------- ### Register WP-CLI commands with WP_CLI::add_command Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/api-reference/wp-cli.md Registers the wp-mail-smtp command namespace and its subcommands (test, setup, option) on the init hook when WP_CLI is defined. The setup command receives additional arguments for configuration. ```php WP_CLI::add_command( 'wp-mail-smtp', Commands\Manage::class ); WP_CLI::add_command( 'wp-mail-smtp test', Commands\Test::class ); WP_CLI::add_command( 'wp-mail-smtp setup', Commands\Setup::class, $setup ); WP_CLI::add_command( 'wp-mail-smtp option', Commands\Option::class, $option ); ``` -------------------------------- ### WPMailSMTP\Core::get_setup_checklist() Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/api-reference/core.md Returns the SetupChecklist instance, cached and filtered, with init called. ```APIDOC ## WPMailSMTP\Core::get_setup_checklist() ### Description Returns the SetupChecklist instance, cached and filtered, with init called. ### Method Public method ### Signature ```php public function get_setup_checklist() ``` ### Parameters None. ### Return Value - **WPMailSMTP\SetupChecklist\SetupChecklist** - The setup checklist instance. ``` -------------------------------- ### OptionsAbstract constructor Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/api-reference/options-abstract.md Initializes the provider options with required params (slug, title) and optional settings. Falls back to the primary connection when none is provided. Sanitizes slug and title, and applies kses to description. ```php public function __construct( $params, $connection = null ) { if ( ! is_null( $connection ) ) { $this->connection = $connection; } else { $this->connection = wp_mail_smtp()->get_connections_manager()->get_primary_connection(); } $this->connection_options = $this->connection->get_options(); if ( empty( $params['slug'] ) || empty( $params['title'] ) ) { return; } $this->slug = sanitize_key( $params['slug'] ); $this->title = sanitize_text_field( $params['title'] ); if ( ! empty( $params['description'] ) ) { $this->description = wp_kses_post( $params['description'] ); } // notices: kses-whitelisted map (br, strong, em, a[href|rel|target]) // recommended / disabled: (bool) // php: sanitize_text_field (default WPMS_PHP_VER) // logo_url: esc_url_raw $this->supports = ( ! empty( $params['supports'] ) ) ? $params['supports'] : $this->get_supports_defaults(); $this->options = Options::init(); } ``` -------------------------------- ### Get mailer bound to primary connection Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/api-reference/connections.md Retrieves the mailer instance for the primary connection and checks if it's complete. ```php $connection = wp_mail_smtp()->get_connections_manager()->get_primary_connection(); $mailer = $connection->get_mailer(); // Providers\MailerAbstract|null if ( $mailer ) { $is_complete = $mailer->is_mailer_complete(); } ``` -------------------------------- ### Options::init() singleton accessor Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/api-reference/options.md Returns the single Options instance, creating it if necessary. ```php public static function init() { static $instance; if ( ! $instance ) { $instance = new self(); } return $instance; } ``` -------------------------------- ### POST /get-partner-plugins-info Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/endpoints.md Retrieves information about partner plugins and whether a contact form plugin is already installed. ```APIDOC ## [POST] /get-partner-plugins-info ### Description Retrieves information about partner plugins and whether a contact form plugin is already installed. ### Method POST ### Endpoint /get-partner-plugins-info ### Parameters No body. ### Response #### Success Response (200) - **plugins** (array) - Array of objects with `slug`, `name`, `is_activated`, `is_installed`. - **contact_form_plugin_already_installed** (bool) - Whether a contact form plugin is already installed. #### Response Example ```json { "plugins": [ { "slug": "...", "name": "...", "is_activated": true, "is_installed": true } ], "contact_form_plugin_already_installed": false } ``` ``` -------------------------------- ### Run a preflight probe and shape results for the wizard client Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/api-reference/preflight.md Shows how to obtain a PreflightInterface instance for a mailer (e.g., 'smtp'), run the probe with a config array, and convert findings to an array. Handles the case where the mailer has nothing to probe by returning an empty findings array with 'checked' => false. Also demonstrates catching TransportFailure, which is only thrown by ApiPreflightAbstract::request(). ```php use WPMailSMTP\Providers\Preflight\PreflightInterface; use WPMailSMTP\Providers\Preflight\Finding; use WPMailSMTP\Providers\Preflight\Code; $preflight = wp_mail_smtp()->get_providers()->get_preflight( 'smtp' ); if ( ! $preflight instanceof PreflightInterface ) { // mailer has nothing to probe return [ 'findings' => [], 'checked' => false ]; } try { $findings = $preflight->run( $config ); // $config = mailer options group $wire = $findings->to_array(); // [ { code, field, severity }, ... ] if ( $findings->has_blocking() ) { // gate the wizard Continue action } } catch ( \WPMailSMTP\Providers\Preflight\TransportFailure $failure ) { // only thrown by ApiPreflightAbstract::request() $finding = $failure->get_finding(); } ``` -------------------------------- ### WP::get_initiator() Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/api-reference/wp.md Returns an array with 'name', 'type', and 'slug' for a given file path. The type can be 'plugin', 'mu-plugin', 'theme', 'wp-core', or 'unknown'. ```APIDOC ## WP::get_initiator() ### Description Returns an array with 'name', 'type', and 'slug' for a given file path. The type can be 'plugin', 'mu-plugin', 'theme', 'wp-core', or 'unknown'. ### Method `public static function get_initiator( $file_path )` ### Parameters - **$file_path** (string) - Required - The file path. ### Returns - **array** - Associative array with keys: 'name', 'type', 'slug'. ``` -------------------------------- ### Control enqueueing per-email with wp_mail_smtp_mail_catcher_send_enqueue_email filter Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/api-reference/queue.md This filter receives the filtered wp_mail args. The example delays only newsletter-sized sends by checking the subject. ```php add_filter( 'wp_mail_smtp_mail_catcher_send_enqueue_email', function ( $should_enqueue, $wp_mail_args ) { $subject = $wp_mail_args[1] ?? ''; // Delay only newsletter-sized sends. return $should_enqueue || strpos( strtolower( $subject ), 'newsletter' ) !== false; } ); ``` -------------------------------- ### run() method - final Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/api-reference/preflight.md Final method that sanitizes config, returns incomplete config if invalid, otherwise probes and unwinds TransportFailure into a single-finding result. No other exception is caught. ```php final public function run( $config ) { $sanitized_config = $this->sanitize_config( $config ); if ( $sanitized_config === null ) { return $this->incomplete_config(); } try { return $this->probe( $sanitized_config ); } catch ( TransportFailure $failure ) { $findings = Findings::none(); $findings->add( $failure->get_finding() ); return $findings; } } ``` -------------------------------- ### Opt into the queue via plugin code Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/api-reference/queue.md Use this in a boot-time callback before plugins_loaded finishes to enable the queue. Alternatively, set the option that the OptimizedEmailSending module reads. ```php // In a boot-time callback (before plugins_loaded finishes): add_filter( 'wp_mail_smtp_queue_is_enabled', function () { return true; } ); // Or set the option the OptimizedEmailSending module reads: \WPMailSMTP\Options::init()->set( [ 'general' => [ \WPMailSMTP\OptimizedEmailSending::SETTINGS_SLUG => true ] ] ); ``` -------------------------------- ### AbstractConnection::get_title() implementation Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/api-reference/connections.md Returns the connection title as ' ()', e.g., 'Primary (SendLayer)'. Uses the provider options to get the title. ```php public function get_title() { return sprintf( '%s (%s)', $this->get_name(), wp_mail_smtp()->get_providers()->get_options( $this->get_mailer_slug(), $this )->get_title() ); } ``` -------------------------------- ### Core constructor __construct() Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/api-reference/core.md Initializes plugin URLs and paths, checks loadability, and loads hooks and early initializations. Registers admin notice if PHP version is insecure. ```php public function __construct() { $this->plugin_url = rtrim( plugin_dir_url( __DIR__ ), '/\\' ); $this->assets_url = $this->plugin_url . '/assets'; $this->plugin_path = rtrim( plugin_dir_path( __DIR__ ), '/\\' ); if ( $this->is_not_loadable() ) { add_action( 'admin_notices', 'wp_mail_smtp_insecure_php_version_notice' ); /* ... */ return; } // Finally, load all the plugin. $this->hooks(); $this->init_early(); } ``` -------------------------------- ### get( $group, $key ) → mixed Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/api-reference/options.md Retrieves a single option value. Decrypts 'smtp.pass' on read and falls back to raw ciphertext on decryption failure. ```APIDOC ## get( $group, $key ) → mixed ### Description Returns the value of a specific option. If the option is 'smtp.pass', it is decrypted on read; if decryption fails, the raw ciphertext is returned. ### Method Function call ### Endpoint `WPMailSMTP\Options::get( $group, $key )` ### Parameters - **$group** (string) - Required - The option group (e.g., 'mail', 'smtp'). - **$key** (string) - Required - The option key (e.g., 'mailer', 'host'). ### Response - **mixed** - The option value. For 'smtp.pass', the decrypted password or raw ciphertext on failure. ``` -------------------------------- ### WPMailSMTP\Core::init_early() Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/api-reference/core.md Fires after muplugins_loaded, before WordPress includes wp-includes/pluggable.php; loads Action Scheduler and Pro PLUGGABLE_FILES. ```APIDOC ## WPMailSMTP\Core::init_early() ### Description Fires after muplugins_loaded, before WordPress includes wp-includes/pluggable.php; loads Action Scheduler and Pro PLUGGABLE_FILES. ### Method Protected method ### Signature ```php protected function init_early() ``` ### Parameters None. ### Return Value None. ``` -------------------------------- ### Resolve the connection driving the next email Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/api-reference/connections.md Gets the active connection and checks if it's primary. Shows how to access mailer slug, title, and from email option. ```php use WPMailSMTP\ConnectionInterface; $connection = wp_mail_smtp()->get_connections_manager()->get_mail_connection(); if ( $connection->get_id() === 'primary' ) { $mailer = $connection->get_mailer_slug(); // e.g. 'sendlayer' $title = $connection->get_title(); // "Primary (SendLayer)" $from = $connection->get_options()->get( 'mail', 'from_email' ); } ``` -------------------------------- ### Building admin error log with EmailSendingErrors Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/api-reference/email-sending-debug.md Instantiates EmailSendingErrors and uses build_error_log() to get an HTML debug bundle and get_local_failure_info() for remediation steps. ```php use WPMailSMTP\Admin\EmailSendingErrors\EmailSendingErrors; $errors = new EmailSendingErrors(); $record = \WPMailSMTP\EmailSendingDebug::get( 'primary' ); $bundle = $errors->build_error_log( $record ); // HTML debug bundle $info = $errors->get_local_failure_info( $record ); // ['steps' => [...], ...] ``` -------------------------------- ### get_group() - Retrieve a group of options Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/api-reference/options.md Public method that returns a sanitized group of options. Each mapped key is re-fetched through get(). Applies the 'wp_mail_smtp_options_get_group' filter only for main options. ```php public function get_group( $group ) { // ...sanitized; each mapped key is re-fetched through get() return $this->is_main_options() ? apply_filters( 'wp_mail_smtp_options_get_group', $options, $group ) : $options; } ``` -------------------------------- ### Event constructor Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/api-reference/debug-events.md Initializes an Event instance. Accepts an event ID or an object with id, content, initiator, event_type, and created_at properties. ```php public function __construct( $id_or_row = null ) { $this->populate_event( $id_or_row ); } ``` -------------------------------- ### WP-CLI command hierarchy Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/api-reference/wp-cli.md Shows the available wp-mail-smtp subcommands: setup for configuring a mailer, option for reading/writing settings, and test for sending a test email. ```text wp wp-mail-smtp setup --force --mail.* --smtp.* --sendgrid.* ... configure a mailer from the CLI option get|set|list read/write individual settings test [--plain] send a test email ``` -------------------------------- ### request() method - protected Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/api-reference/preflight.md Protected method that performs a wp_remote_request with default GET method, timeout, and user-agent. Merges headers if array, throws TransportFailure on transport finding. ```php protected function request( $url, $args = [] ) { $headers = isset( $args['headers'] ) ? $args['headers'] : []; $args['headers'] = is_array( $headers ) ? $this->merge_headers( $headers ) : $headers; $response = wp_remote_request( $url, array_merge( [ 'method' => 'GET', 'timeout' => self::TIMEOUT, 'user-agent' => Helpers::get_default_user_agent(), ], $args ) ); $finding = $this->transport_finding( $response ); if ( $finding !== null ) { throw new TransportFailure( $finding ); } return $response; } ``` -------------------------------- ### Helpers\Helpers::include_mbstring_polyfill() Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/api-reference/helpers.md Loads the polyfill-mbstring library if needed. Returns void. ```APIDOC ## Helpers\Helpers::include_mbstring_polyfill() ### Description Loads the polyfill-mbstring library. ### Method `include_mbstring_polyfill()` ### Returns - **void** - Loads `polyfill-mbstring`. ``` -------------------------------- ### WPMailSMTP\Core::init_notifications() Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/api-reference/core.md No-op in Lite. ```APIDOC ## WPMailSMTP\Core::init_notifications() ### Description No-op in Lite. ### Method Public method ### Signature ```php public function init_notifications() ``` ### Parameters None. ### Return Value None. ``` -------------------------------- ### WPMailSMTP\Core::init_migrations() Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/api-reference/core.md Deprecated 4.0.0. Initializes migrations via Migrations::init_migrations_on_request(). ```APIDOC ## WPMailSMTP\Core::init_migrations() ### Description Deprecated 4.0.0. Initializes migrations via Migrations::init_migrations_on_request(). ### Method Public method ### Signature ```php public function init_migrations() ``` ### Parameters None. ### Return Value None. ``` -------------------------------- ### WP::get_initiator_name() Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/api-reference/wp.md Returns the name of the file that initiated the current request. ```APIDOC ## WP::get_initiator_name() ### Description Returns the name of the file that initiated the current request. ### Method `public static function get_initiator_name( $file_path )` ### Parameters - **$file_path** (string) - Required - The file path. ### Returns - **string** - The initiator name. ``` -------------------------------- ### Catching InvalidArgumentException for Finding severity Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/errors.md Example of catching InvalidArgumentException when creating a Finding with an invalid severity. The severity must be one of Finding::ERROR, WARNING, or INCONCLUSIVE. ```php use InvalidArgumentException; try { $finding = new Finding( 'auth_failed', 'api_key', 'bogus' ); } catch ( InvalidArgumentException $e ) { // severity must be one of Finding::ERROR / WARNING / INCONCLUSIVE } ``` -------------------------------- ### Switch Composer to v1.x Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/README.md Required for development. Use this command if you are currently using Composer v2.x. ```bash composer self-update --1 ``` -------------------------------- ### prepare_loader() method signature Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/api-reference/core.md Returns an loader SVG. $color can be '' (orange), 'blue', or 'white'; $size can be 'lg', 'md', or 'sm'. ```php public function prepare_loader( $color = '', $size = 'md' ) ``` -------------------------------- ### Catching TransportFailure Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/errors.md Example of catching TransportFailure when calling the preflight run() method directly. Note that ApiPreflightAbstract::run() catches this exception internally and converts it to a single-finding result. ```php use WPMailSMTP\Providers\Preflight\TransportFailure; try { $findings = $preflight->run( $config ); } catch ( TransportFailure $failure ) { $finding = $failure->get_finding(); // Finding with code/field/severity } ``` -------------------------------- ### REST API Success Envelope (RestApiResponse::response()) Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/endpoints.md Standard JSON envelope returned by all Setup Wizard REST API routes on success. The data field contains route-specific response data. ```json { "success": true, "data": { ... } } ``` -------------------------------- ### Read a single option Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/api-reference/options.md Initializes the Options class and retrieves individual option values. Shows how to check if a constant defines a value, which overrides the database value. ```php use WPMailSMTP\Options; $options = Options::init(); $mailer = $options->get( 'mail', 'mailer' ); // 'sendlayer', 'smtp', 'mail', ... $host = $options->get( 'smtp', 'host' ); // '' when unset $pass = $options->get( 'smtp', 'pass' ); // decrypted on read if ( $options->is_const_defined( 'smtp', 'host' ) ) { // host comes from the WPMS_SMTP_HOST constant, the DB value is ignored. } ``` -------------------------------- ### Force-run migrations on plugins_loaded Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/api-reference/migrations.md Bootstraps the migration dispatcher and runs pending migrations when enabled. Mirrors the plugin's own boot sequence; checks `Migration::is_enabled()` before invoking `init_migrations_on_request()`. ```php use WPMailSMTP\Migrations; add_action( 'plugins_loaded', function () { $migrations = new Migrations(); $migrations->hooks(); if ( \WPMailSMTP\Migration::is_enabled() ) { $migrations->init_migrations_on_request(); } } ); ``` -------------------------------- ### get_options( $provider, $connection = null ) Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/api-reference/providers-loader.md Instantiates the Options object for a given provider, passing the connection as the first constructor argument. Returns an OptionsAbstract instance or null. ```APIDOC ## get_options( $provider, $connection = null ) ### Description Instantiates the Options object for a given provider, passing the connection as the first constructor argument. Returns an OptionsAbstract instance or null. ### Method PHP method ### Endpoint `get_options( $provider, $connection = null )` ### Parameters - **$provider** (string) - Required - Provider slug. - **$connection** (mixed) - Optional - Connection object to pass to the constructor. ### Return Value - **OptionsAbstract|null** - Options instance or null. ``` -------------------------------- ### Throttle class rate-limiting methods Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/api-reference/preflight.md Rate-limits outbound provider probes per bucket key using WordPress transients. The LIMIT constant is 20 and the window is one minute (MINUTE_IN_SECONDS). The allows() method checks if the current count is below the limit, record() increments the count, and transient() builds the transient key with an md5 hash of the provided key. ```php const LIMIT = 20; private const WINDOW = MINUTE_IN_SECONDS; public function allows( $key ) { return (int) get_transient( $this->transient( $key ) ) < self::LIMIT; } public function record( $key ) { $name = $this->transient( $key ); $count = (int) get_transient( $name ); set_transient( $name, $count + 1, self::WINDOW ); } private function transient( $key ) { return 'wp_mail_smtp_preflight_' . md5( $key ); } ``` -------------------------------- ### Options constructor Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/api-reference/options.md Registers the instance as an update observer and caches current options. Called via Options::init() since 3.3.0. ```php public function __construct() { // Store all class instances that will be notified about options update. static::$update_observers[] = $this; $this->populate_options(); } ``` -------------------------------- ### Extend MailerAbstract to create a custom mailer Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/api-reference/mailer-abstract.md Concrete mailers extend this class and override $url, the set_* builders, get_body(), process_response(), get_response_error(), get_debug_info() and is_mailer_complete(). The example shows a custom API mailer that sets the endpoint URL, builds the from parameters, checks for an API key, processes the response to add a custom header, and formats error messages. ```php use WPMailSMTP\Providers\MailerAbstract; class CustomApiMailer extends MailerAbstract { protected $url = 'https://example.com/v1/email'; public function set_from( $email, $name ) { $this->set_body_param( [ 'from' => $email, 'from_name' => $name ] ); } public function is_mailer_complete() { return ! empty( $this->connection_options->get( $this->mailer, 'api_key' ) ); } protected function process_response( $response ) { parent::process_response( $response ); if ( parent::is_email_sent() && ! empty( $this->response['body']->message_id ) ) { $this->phpmailer->addCustomHeader( 'X-Msg-ID', $this->response['body']->message_id ); } } public function get_response_error() { $text = [ $this->error_message ]; if ( ! empty( $this->response ) ) { $text[] = Helpers::format_error_message( wp_remote_retrieve_body( $this->response ), $this->get_response_error_code() ); } return implode( WP::EOL, array_filter( $text ) ); } } ``` -------------------------------- ### Capability-Based Gating for Admin Notices Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/api-reference/core.md Demonstrates how to gate admin notices using the plugin's capability check. Only users with the 'manage options' capability will see the notice. ```php add_action( 'admin_notices', function () { if ( current_user_can( wp_mail_smtp()->get_capability_manage_options() ) ) { // Only show for users that can manage the plugin. } } ); ``` -------------------------------- ### AbstractAbility::get_description() Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/api-reference/abilities.md Returns a description of the ability, explaining its purpose. This method must be implemented by subclasses. ```APIDOC ## AbstractAbility::get_description() ### Description Returns a description of the ability, explaining its purpose. This method must be implemented by subclasses. ### Method PHP method ### Endpoint `WPMailSMTP\Abilities\AbstractAbility::get_description()` ### Parameters None ### Return Value - **string** - The description (e.g., 'Read-only access to custom plugin data.'). ### Example ```php public function get_description() { return esc_html__( 'Read-only access to custom plugin data.', 'wp-mail-smtp' ); } ``` ``` -------------------------------- ### Event::get_initiator_file_path Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/api-reference/debug-events.md Returns the file path of the initiator. ```APIDOC ## Event::get_initiator_file_path ### Description Returns the file path of the initiator. ### Method `get_initiator_file_path()` ### Returns - `string` - File path. ``` -------------------------------- ### Finding::get_code Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/api-reference/preflight.md Returns the code of the finding as a string. ```APIDOC ## Finding::get_code ### Description Returns the code of the finding as a string. ### Method Getter ### Returns - **string** - The code of the finding. ### Example ```php $code = $finding->get_code(); ``` ``` -------------------------------- ### Constructor with dependency injection Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/api-reference/processor.md Constructor for the Processor class. Accepts an optional ConnectionsManager instance; defaults to the plugin's connections manager if not provided. ```php public function __construct( $connections_manager = null ) { if ( is_null( $connections_manager ) ) { $this->connections_manager = wp_mail_smtp()->get_connections_manager(); } else { $this->connections_manager = $connections_manager; } } ``` -------------------------------- ### WPMailSMTP\Core::get_upgrade() Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/api-reference/core.md Returns the Upgrade instance, cached and with run called. ```APIDOC ## WPMailSMTP\Core::get_upgrade() ### Description Returns the Upgrade instance, cached and with run called. ### Method Public method ### Signature ```php public function get_upgrade() ``` ### Parameters None. ### Return Value - **WPMailSMTP\Upgrade** - The upgrade instance. ``` -------------------------------- ### Finding::__construct Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/api-reference/preflight.md Creates a new Finding instance with a code, field, and severity. Throws InvalidArgumentException if the severity is not one of the three constants. ```APIDOC ## Finding::__construct ### Description Creates a new Finding instance with a code, field, and severity. Throws InvalidArgumentException if the severity is not one of the three constants. ### Method Constructor ### Signature ```php public function __construct( $code, $field, $severity ) ``` ### Parameters - **$code** (mixed) - Required - The code for the finding. - **$field** (mixed) - Required - The field associated with the finding. - **$severity** (string) - Required - Must be one of `Finding::ERROR`, `Finding::WARNING`, or `Finding::INCONCLUSIVE`. ### Throws - `InvalidArgumentException` - If `$severity` is not one of the three constants. ### Example ```php $finding = new Finding( 'code', 'field', Finding::ERROR ); ``` ``` -------------------------------- ### api_send() method implementation Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/api-reference/mailcatcher.md Private method that prepares the mailer, runs preSend(), obtains the mailer via Providers\Loader, and sends. Throws exceptions for missing or incompatible mailers, and handles failure with DebugEvent and actions. ```php if ( ! $mailer ) { $this->throw_exception( 'The selected mailer not found.' ); } if ( ! $mailer->is_php_compatible() ) { $this->throw_exception( 'The selected mailer is not compatible with your PHP version.' ); } do_action( 'wp_mail_smtp_mailcatcher_send_before', $mailer ); $mailer->send(); $is_sent = $mailer->is_email_sent(); do_action( 'wp_mail_smtp_mailcatcher_send_after', $mailer, $this ); if ( $is_sent !== true ) { $this->throw_exception( $mailer->get_response_error() ); } return true; ``` -------------------------------- ### Event::get_initiator_raw Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/api-reference/debug-events.md Returns the raw JSON initiator string. ```APIDOC ## Event::get_initiator_raw ### Description Returns the raw JSON initiator string. ### Method `get_initiator_raw()` ### Returns - `string` - JSON initiator string. ``` -------------------------------- ### Helpers\Helpers::include_plugin_upgrader() Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/api-reference/helpers.md Includes the plugin upgrader file. Returns void. ```APIDOC ## Helpers\Helpers::include_plugin_upgrader() ### Description Includes the plugin upgrader file. ### Method `include_plugin_upgrader()` ### Returns - **void** ``` -------------------------------- ### Event::set_initiator Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/api-reference/debug-events.md Snapshots the current wp_mail initiator (WPMailInitiator). ```APIDOC ## Event::set_initiator ### Description Snapshots the current wp_mail initiator (WPMailInitiator). ### Method `set_initiator()` ### Returns - `self` - Returns the instance for chaining. ``` -------------------------------- ### Compose a provider probe by extending ApiPreflightAbstract Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/api-reference/preflight.md Pattern used by each provider's Preflight class. Extend ApiPreflightAbstract, implement sanitize_config() to validate the config (return null if invalid) and probe() to make an API request and add findings based on the response status. Uses Code::AUTH_FAILED for a 401 response. ```php use WPMailSMTP\Providers\Preflight\ApiPreflightAbstract; use WPMailSMTP\Providers\Preflight\Findings; use WPMailSMTP\Providers\Preflight\Code; class MyMailerPreflight extends ApiPreflightAbstract { protected function sanitize_config( $config ) { return ! empty( $config['api_key'] ) ? $config : null; } protected function probe( $config ) { $response = $this->request( 'https://api.example.com/v1/account', [ 'headers' => [ 'Authorization' => 'Bearer ' . $config['api_key'] ], ] ); $findings = Findings::none(); if ( $this->status( $response ) === 401 ) { $findings->add( $this->error( Code::AUTH_FAILED, 'api_key' ) ); } return $findings; } } ``` -------------------------------- ### Read and verify configuration Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/api-reference/wp-cli.md Commands to read the current mailer setting, list all options (sensitive flags are masked), send a test email, and force overwrite an existing configuration. The `--force` flag is required to overwrite an already-configured instance. ```bash wp wp-mail-smtp option get mail.mailer ``` ```bash wp wp-mail-smtp option list --fields=flag,value # sensitive flags masked ``` ```bash wp wp-mail-smtp test you@example.com --plain ``` ```bash wp wp-mail-smtp setup --force # overwrite an already-configured instance ``` -------------------------------- ### Event::get_initiator_file_line Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/api-reference/debug-events.md Returns the line number of the initiator file. ```APIDOC ## Event::get_initiator_file_line ### Description Returns the line number of the initiator file. ### Method `get_initiator_file_line()` ### Returns - `int` - Line number. ``` -------------------------------- ### with_context( $context ) Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/api-reference/test-email.md Sets the context for the test email, which becomes the X-Mailer-Type header. Must be one of the CONTEXT_* constants. ```APIDOC ## with_context( $context ) ### Description Sets the context for the test email, which becomes the X-Mailer-Type header. Must be one of the CONTEXT_* constants. ### Method Fluent configuration method ### Parameters - **$context** (string) - Required - One of the CONTEXT_* constants (e.g., CONTEXT_ADMIN_TEST, CONTEXT_SETUP_WIZARD). ### Returns - **self** - The instance for chaining. ``` -------------------------------- ### PreflightAbstract class with timeout and helper methods Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/api-reference/preflight.md Abstract base class for preflight implementations. Sets a 10-second timeout per operation and provides error, warning, and inconclusive finding helpers, plus an incomplete_config method that adds an inconclusive finding. ```php abstract class PreflightAbstract implements PreflightInterface { /** * Seconds per operation. */ const TIMEOUT = 10; protected function error( $code, $field = null ) { /* new Finding( $code, $field, Finding::ERROR ) */ } protected function warning( $code, $field = null ) { /* new Finding( $code, $field, Finding::WARNING ) */ } protected function inconclusive( $code, $field = null ) { /* new Finding( $code, $field, Finding::INCONCLUSIVE ) */ } protected function incomplete_config() { $findings = Findings::none(); $findings->add( $this->inconclusive( Code::CONFIG_INCOMPLETE ) ); return $findings; } abstract protected function sanitize_config( $config ); } ``` -------------------------------- ### display_options() Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/api-reference/options-abstract.md Renders the provider settings form. Emits SMTP-style form controls bound to wp-mail-smtp[$slug][...] inputs, as used by admin tabs. ```APIDOC ## display_options() ### Description Renders the provider settings form. Emits SMTP-style form controls bound to wp-mail-smtp[$slug][...] inputs, as used by admin tabs. ### Method `display_options()` ### Parameters None. ### Return Value - **void** - Outputs the form HTML directly. ### Usage Example ```php // Emits the SMTP-style form controls bound to wp-mail-smtp[$slug][...] inputs. wp_mail_smtp()->get_providers()->get_options( 'smtp' )->display_options(); ``` ``` -------------------------------- ### Server-side write following the same allowlist Source: https://github.com/awesomemotive/wp-mail-smtp/blob/master/_autodocs/api-reference/setup-wizard-rest-api.md Use this PHP snippet to update wizard settings server-side, respecting the same allowlist as the REST API. The update method expects slashed data, which are stripped on read. ```php use WPMailSMTP\Admin\SetupWizard\Settings; $settings = new Settings(); $tree = $settings->filter_allowed( [ 'mail' => [ 'from_name' => 'Support' ] ] ); $settings->update( wp_slash( $tree ) ); // slashes are stripped back on read ```