class-form-access-control.php
1 week ago
class-form-captcha-handler.php
1 week ago
class-form-controller.php
1 week ago
class-form-email-config-check.php
1 week ago
class-form-email-handler.php
1 week ago
class-form-encryption.php
1 week ago
class-form-exporter.php
1 week ago
class-form-field-validator.php
1 week ago
class-form-file-handler.php
1 week ago
class-form-google-auth.php
1 week ago
class-form-integration-handler.php
1 week ago
class-form-math-parser.php
1 week ago
class-form-permissions.php
1 week ago
class-form-registry.php
1 week ago
class-form-settings.php
1 week ago
class-form-submission-cpt.php
1 week ago
class-form-submission-handler.php
1 week ago
class-form-email-config-check.php
122 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SuperbAddons\Gutenberg\Form; |
| 4 | |
| 5 | defined('ABSPATH') || exit(); |
| 6 | |
| 7 | class FormEmailConfigCheck |
| 8 | { |
| 9 | /** |
| 10 | * Known SMTP plugin directory prefixes. |
| 11 | */ |
| 12 | private static $known_smtp_plugins = array( |
| 13 | 'wp-mail-smtp/', |
| 14 | 'post-smtp/', |
| 15 | 'fluent-smtp/', |
| 16 | 'easy-wp-smtp/', |
| 17 | 'smtp-mailer/', |
| 18 | 'wp-smtp/', |
| 19 | 'mailgun/', |
| 20 | 'sparkpost/', |
| 21 | 'sendgrid-email-delivery-simplified/', |
| 22 | 'amazon-ses/', |
| 23 | 'offload-ses/', |
| 24 | 'wp-ses/', |
| 25 | 'smtp2go/', |
| 26 | 'postmark-approved-wordpress-plugin/', |
| 27 | 'mailpoet/', |
| 28 | ); |
| 29 | |
| 30 | /** |
| 31 | * Check if the site appears to have email sending configured. |
| 32 | * |
| 33 | * Returns true if email is likely working, false if it almost certainly is not. |
| 34 | * Only returns false when PHP mail() is disabled AND no SMTP plugin/override is detected. |
| 35 | * |
| 36 | * @return bool |
| 37 | */ |
| 38 | public static function IsConfigured() |
| 39 | { |
| 40 | // If an SMTP plugin is active, email is configured |
| 41 | if (self::HasSmtpPlugin()) { |
| 42 | return true; |
| 43 | } |
| 44 | |
| 45 | // If wp_mail has been overridden by a plugin, email is configured |
| 46 | if (self::IsWpMailOverridden()) { |
| 47 | return true; |
| 48 | } |
| 49 | |
| 50 | // If phpmailer_init has listeners, a plugin is configuring the mailer |
| 51 | if (has_action('phpmailer_init')) { |
| 52 | return true; |
| 53 | } |
| 54 | |
| 55 | // If PHP mail() function is available, default sending should work |
| 56 | if (function_exists('mail')) { |
| 57 | return true; |
| 58 | } |
| 59 | |
| 60 | // PHP mail() is disabled and no SMTP plugin/override detected |
| 61 | return false; |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Check if a known SMTP plugin is active. |
| 66 | * |
| 67 | * @return bool |
| 68 | */ |
| 69 | private static function HasSmtpPlugin() |
| 70 | { |
| 71 | $active_plugins = get_option('active_plugins', array()); |
| 72 | if (!is_array($active_plugins)) { |
| 73 | return false; |
| 74 | } |
| 75 | |
| 76 | foreach ($active_plugins as $plugin) { |
| 77 | foreach (self::$known_smtp_plugins as $prefix) { |
| 78 | if (strpos($plugin, $prefix) === 0) { |
| 79 | return true; |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | // Check network-active plugins on multisite |
| 85 | if (is_multisite()) { |
| 86 | $network_plugins = get_site_option('active_sitewide_plugins', array()); |
| 87 | if (is_array($network_plugins)) { |
| 88 | foreach (array_keys($network_plugins) as $plugin) { |
| 89 | foreach (self::$known_smtp_plugins as $prefix) { |
| 90 | if (strpos($plugin, $prefix) === 0) { |
| 91 | return true; |
| 92 | } |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | return false; |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Check if the wp_mail function has been overridden by a plugin. |
| 103 | * |
| 104 | * WordPress defines wp_mail in pluggable.php using function_exists(), |
| 105 | * so plugins can provide their own implementation. |
| 106 | * |
| 107 | * @return bool |
| 108 | */ |
| 109 | private static function IsWpMailOverridden() |
| 110 | { |
| 111 | if (!function_exists('wp_mail')) { |
| 112 | return false; |
| 113 | } |
| 114 | |
| 115 | $ref = new \ReflectionFunction('wp_mail'); |
| 116 | $file = $ref->getFileName(); |
| 117 | |
| 118 | // If wp_mail is NOT defined in pluggable.php, it has been overridden |
| 119 | return strpos($file, 'pluggable.php') === false; |
| 120 | } |
| 121 | } |
| 122 |