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