Geen omschrijving

wp-mail-smtp.php 1.4KB

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