wp-mail-smtp
Last commit date
assets
6 months ago
src
6 months ago
vendor
6 months ago
vendor_prefixed
6 months ago
readme.txt
6 months ago
uninstall.php
6 months ago
wp-mail-smtp.php
6 months ago
wp_mail_smtp.php
6 months ago
wp-mail-smtp.php
65 lines
| 1 | <?php |
| 2 | |
| 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | exit; // Exit if accessed directly. |
| 5 | } |
| 6 | |
| 7 | /** |
| 8 | * Autoloader. We need it being separate and not using Composer autoloader because of the Gmail libs, |
| 9 | * which are huge and not needed for most users. |
| 10 | * Inspired by PSR-4 examples: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader-examples.md |
| 11 | * |
| 12 | * @since 1.0.0 |
| 13 | * |
| 14 | * @param string $class The fully-qualified class name. |
| 15 | */ |
| 16 | spl_autoload_register( function ( $class ) { |
| 17 | |
| 18 | list( $plugin_space ) = explode( '\\', $class ); |
| 19 | if ( $plugin_space !== 'WPMailSMTP' ) { |
| 20 | return; |
| 21 | } |
| 22 | |
| 23 | /* |
| 24 | * This folder can be both "wp-mail-smtp" and "wp-mail-smtp-pro". |
| 25 | */ |
| 26 | $plugin_dir = basename( __DIR__ ); |
| 27 | |
| 28 | // Default directory for all code is plugin's /src/. |
| 29 | $base_dir = plugin_dir_path( __DIR__ ) . '/' . $plugin_dir . '/src/'; |
| 30 | |
| 31 | // Get the relative class name. |
| 32 | $relative_class = substr( $class, strlen( $plugin_space ) + 1 ); |
| 33 | |
| 34 | // Prepare a path to a file. |
| 35 | $file = wp_normalize_path( $base_dir . $relative_class . '.php' ); |
| 36 | |
| 37 | // If the file exists, require it. |
| 38 | if ( is_readable( $file ) ) { |
| 39 | /** @noinspection PhpIncludeInspection */ |
| 40 | require_once $file; |
| 41 | } |
| 42 | } ); |
| 43 | |
| 44 | /** |
| 45 | * Global function-holder. Works similar to a singleton's instance(). |
| 46 | * |
| 47 | * @since 1.0.0 |
| 48 | * |
| 49 | * @return WPMailSMTP\Core |
| 50 | */ |
| 51 | function wp_mail_smtp() { |
| 52 | /** |
| 53 | * @var \WPMailSMTP\Core |
| 54 | */ |
| 55 | static $core; |
| 56 | |
| 57 | if ( ! isset( $core ) ) { |
| 58 | $core = new \WPMailSMTP\Core(); |
| 59 | } |
| 60 | |
| 61 | return $core; |
| 62 | } |
| 63 | |
| 64 | wp_mail_smtp(); |
| 65 |