wp-mail-smtp
Last commit date
assets
8 years ago
languages
8 years ago
src
8 years ago
vendor
8 years ago
class-wpms-am-notification.php
8 years ago
readme.txt
8 years ago
wp-mail-smtp.php
8 years ago
wp_mail_smtp.php
8 years ago
wp-mail-smtp.php
81 lines
| 1 | <?php |
| 2 | |
| 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | exit; // Exit if accessed directly. |
| 5 | } |
| 6 | |
| 7 | /** |
| 8 | * Autoloader. Inspired by PSR-4 examples: |
| 9 | * |
| 10 | * @link 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 | $plugin_folder = 'wp-mail-smtp'; |
| 24 | |
| 25 | // Default directory for all code is plugin's /src/. |
| 26 | $base_dir = WP_PLUGIN_DIR . '/' . $plugin_folder . '/src/'; |
| 27 | |
| 28 | // Get the relative class name. |
| 29 | $relative_class = substr( $class, strlen( $plugin_space ) + 1 ); |
| 30 | |
| 31 | /** |
| 32 | * Normalize a filesystem path. |
| 33 | * Copy of the `wp_normalize_path()` from WordPress 3.9. |
| 34 | * |
| 35 | * @since 1.2.0 |
| 36 | * |
| 37 | * @param string $path |
| 38 | * |
| 39 | * @return string |
| 40 | */ |
| 41 | $normalize = function( $path ) { |
| 42 | $path = str_replace( '\\', '/', $path ); |
| 43 | $path = preg_replace( '|(?<=.)/+|', '/', $path ); |
| 44 | if ( ':' === substr( $path, 1, 1 ) ) { |
| 45 | $path = ucfirst( $path ); |
| 46 | } |
| 47 | return $path; |
| 48 | }; |
| 49 | |
| 50 | // Prepare a path to a file. |
| 51 | $file = $normalize( $base_dir . $relative_class . '.php' ); |
| 52 | |
| 53 | // If the file exists, require it. |
| 54 | if ( is_readable( $file ) ) { |
| 55 | /** @noinspection PhpIncludeInspection */ |
| 56 | require_once $file; |
| 57 | } |
| 58 | } ); |
| 59 | |
| 60 | /** |
| 61 | * Global function-holder. Works similar to a singleton's instance(). |
| 62 | * |
| 63 | * @since 1.0.0 |
| 64 | * |
| 65 | * @return WPMailSMTP\Core |
| 66 | */ |
| 67 | function wp_mail_smtp() { |
| 68 | /** |
| 69 | * @var \WPMailSMTP\Core |
| 70 | */ |
| 71 | static $core; |
| 72 | |
| 73 | if ( ! isset( $core ) ) { |
| 74 | $core = new \WPMailSMTP\Core(); |
| 75 | } |
| 76 | |
| 77 | return $core; |
| 78 | } |
| 79 | |
| 80 | wp_mail_smtp(); |
| 81 |