PluginProbe
SureMail – SMTP and Email Logs Plugin with Amazon SES, Postmark, and Other Providers / 1.8.0
SureMail – SMTP and Email Logs Plugin with Amazon SES, Postmark, and Other Providers v1.8.0
2.0.2 2.0.1 2.0.0 1.9.5 trunk 0.0.4 0.0.5 0.0.6 1.0.0 1.0.1 1.1.0 1.2.0 1.3.0 1.4.0 1.4.1 1.4.2 1.5.0 1.6.0 1.6.1 1.6.2 1.7.0 1.7.1 1.7.2 1.8.0 1.8.1 All 31 releases
suremails / loader.php

loader.php in SureMail – SMTP and Email Logs Plugin with Amazon SES, Postmark, and Other Providers 1.8.0, at loader.php

288 lines 7.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Loader Class
4 *
5 * This file is responsible for initializing the SureMails plugin components.
6 *
7 * @package SureMails
8 */
9
10 namespace SureMails;
11
12 use SureMails\Inc\Admin\Activator;
13 use SureMails\Inc\Admin\Crons;
14 use SureMails\Inc\Admin\Plugin;
15 use SureMails\Inc\Admin\Update;
16 use SureMails\Inc\Ajax\Ajax;
17 use SureMails\Inc\Analytics\Analytics;
18 use SureMails\Inc\API\Api_Init;
19 use SureMails\Inc\Controller\ContentGuard;
20 use SureMails\Inc\Controller\WeeklySummary;
21 use SureMails\Inc\Lib\Suremails_Nps_Survey;
22 use SureMails\Inc\Nps_Notice;
23
24 /**
25 * Class Loader
26 *
27 * The Loader class is responsible for loading the SureMails plugin, handling translations,
28 * autoloading, and initializing components like email settings, connections, and activation hooks.
29 *
30 * @package SureMails
31 */
32 class Loader {
33 /**
34 * Singleton instance of the Loader class.
35 *
36 * @var Loader|null
37 */
38 private static $instance = null;
39
40 /**
41 * Loader constructor.
42 * Private to enforce singleton pattern.
43 */
44 private function __construct() {
45
46 if ( ! defined( 'SUREMAILS_CONTENT_GUARD_MIDDLEWARE' ) ) {
47 define( 'SUREMAILS_CONTENT_GUARD_MIDDLEWARE', 'https://credits.startertemplates.com/suremails/' );
48 }
49
50 /**
51 * Register the autoloader.
52 */
53 $this->register_autoload();
54
55 /**
56 * Load the plugin textdomain for translations.
57 */
58 add_action( 'plugins_loaded', [ $this, 'load_textdomain' ] );
59 add_action( 'plugins_loaded', [ $this, 'setup' ] );
60 add_action( 'plugin_loaded', [ $this, 'setup_ajax_instance' ] );
61
62 /**
63 * The code that runs during plugin activation.
64 */
65 register_activation_hook( SUREMAILS_FILE, [ $this, 'activate' ] );
66
67 /**
68 * The code that runs during plugin deactivation.
69 */
70 register_deactivation_hook( SUREMAILS_FILE, [ $this, 'deactivate' ] );
71 }
72
73 /**
74 * Setup the plugin, register hooks, and initialize components.
75 *
76 * @return void
77 */
78 public function setup(): void {
79 $this->load_libraries();
80
81 // Bail if doing AJAX.
82 if ( wp_doing_ajax() ) {
83 return;
84 }
85 // Admin loaders.
86 if ( is_admin() ) {
87 Plugin::instance();
88 }
89 Update::instance();
90 ContentGuard::instance();
91 Crons::instance();
92 Api_Init::instance();
93 Analytics::instance();
94 WeeklySummary::instance();
95 }
96
97 /**
98 * Load libraries.
99 *
100 * @return void
101 */
102 public function load_libraries() {
103
104 if ( ! class_exists( 'Astra_Notices' ) ) {
105 require_once SUREMAILS_DIR . 'inc/lib/astra-notices/class-astra-notices.php';
106 }
107
108 if ( ! class_exists( 'BSF_Analytics_Loader' ) ) {
109 require_once SUREMAILS_DIR . 'inc/lib/bsf-analytics/class-bsf-analytics-loader.php';
110 }
111
112 if ( ! class_exists( '\BSF_UTM_Analytics' ) ) {
113 $utm_path = SUREMAILS_DIR . 'inc/lib/bsf-analytics/modules/utm-analytics.php';
114 if ( file_exists( $utm_path ) ) {
115 require_once $utm_path;
116 }
117 }
118
119 $srml_bsf_analytics = \BSF_Analytics_Loader::get_instance();
120
121 $srml_bsf_analytics->set_entity(
122 [
123 'suremails' => [
124 'product_name' => 'SureMail',
125 'path' => SUREMAILS_DIR . 'inc/lib/bsf-analytics',
126 'author' => 'SureMail',
127 'time_to_display' => '+24 hours',
128 'hide_optin_checkbox' => true,
129 ],
130 ]
131 );
132
133 // load nps survey.
134 if ( class_exists( 'SureMails\Inc\Lib\Suremails_Nps_Survey' ) && ! apply_filters( 'suremails_disable_nps_survey', false ) ) {
135 Suremails_Nps_Survey::instance();
136 Nps_Notice::instance();
137 }
138 }
139
140 /**
141 * Setup the Ajax instance.
142 *
143 * @return void
144 */
145 public function setup_ajax_instance() {
146 if ( ! wp_doing_ajax() ) {
147 return;
148 }
149 Ajax::instance();
150 }
151
152 /**
153 * Get the singleton instance of the Loader class.
154 *
155 * @return Loader Singleton instance of the Loader class.
156 */
157 public static function instance(): Loader {
158 if ( self::$instance === null ) {
159 self::$instance = new self();
160 }
161
162 return self::$instance;
163 }
164
165 /**
166 * Activate the plugin.
167 *
168 * @return void
169 */
170 public function activate(): void {
171 Activator::instance()->activate();
172 }
173
174 /**
175 * Deactivate the plugin.
176 *
177 * @return void
178 */
179 public function deactivate(): void {
180 // On Deactivation of the plugin.
181 }
182
183 /**
184 * Autoload classes based on their namespace and path.
185 *
186 * @param string $class The fully-qualified class name.
187 * @return void
188 */
189 public function autoload( string $class ): void {
190 // Define namespace and base directory for your project.
191 $namespace = 'SureMails\\Inc\\';
192 $base_directory = SUREMAILS_DIR . 'inc/';
193
194 // Ensure the class belongs to the current namespace.
195 if ( strpos( $class, $namespace ) !== 0 ) {
196 return;
197 }
198
199 // Strip the namespace prefix from the class.
200 $relative_class = substr( $class, strlen( $namespace ) );
201
202 // Convert namespace separators to directory separators.
203 // and handle CamelCase to kebab-case conversion for filenames.
204 $filename = preg_replace(
205 [ '/^' . preg_quote( $namespace, '/' ) . '/', '/([a-z])([A-Z])/', '/_/', '/\\\/' ],
206 [ '', '$1-$2', '-', DIRECTORY_SEPARATOR ],
207 $relative_class
208 );
209
210 // Ensure the filename is in lowercase.
211 if ( is_string( $filename ) ) {
212
213 $filename = strtolower( $filename );
214
215 // Construct the full file path.
216 $file = $base_directory . $filename . '.php';
217
218 // Include the file if it exists and is readable.
219 if ( is_readable( $file ) ) {
220 require_once $file;
221 }
222 }
223 }
224
225 /**
226 * Load Plugin Text Domain.
227 * This will load the translation textdomain depending on the file priorities.
228 * 1. Global Languages /wp-content/languages/suremails/ folder
229 * 2. Local directory /wp-content/plugins/suremails/languages/ folder
230 *
231 * @since 0.0.1
232 * @return void
233 */
234 public function load_textdomain(): void {
235 // Default languages directory.
236 $lang_dir = SUREMAILS_DIR . 'languages/';
237
238 /**
239 * Filters the languages directory path to use for plugin.
240 *
241 * @param string $lang_dir The languages directory path.
242 */
243 $lang_dir = apply_filters( 'suremails_languages_directory', $lang_dir );
244
245 // Traditional WordPress plugin locale filter.
246 global $wp_version;
247
248 $get_locale = get_locale();
249
250 if ( $wp_version >= 4.7 ) {
251 $get_locale = get_user_locale();
252 }
253
254 /**
255 * Language Locale for plugin
256 *
257 * Uses get_user_locale()` in WordPress 4.7 or greater,
258 * otherwise uses `get_locale()`.
259 */
260 $locale = apply_filters( 'plugin_locale', $get_locale, 'suremails' );//phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- wordpress hook
261 $mofile = sprintf( '%1$s-%2$s.mo', 'suremails', $locale );
262
263 // Setup paths to current locale file.
264 $mofile_global = WP_LANG_DIR . '/plugins/' . $mofile;
265 $mofile_local = $lang_dir . $mofile;
266
267 if ( file_exists( $mofile_global ) ) {
268 // Look in global /wp-content/languages/suremails/ folder.
269 load_textdomain( 'suremails', $mofile_global );
270 } elseif ( file_exists( $mofile_local ) ) {
271 // Look in local /wp-content/plugins/suremails/languages/ folder.
272 load_textdomain( 'suremails', $mofile_local );
273 }
274 }
275
276 /**
277 * Register the autoloader.
278 *
279 * @return void
280 */
281 private function register_autoload(): void {
282 spl_autoload_register( [ $this, 'autoload' ] );
283 }
284 }
285
286 // Initialize the loader singleton.
287 Loader::instance();
288