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