-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathplugin-loader.php
More file actions
361 lines (324 loc) · 9.18 KB
/
Copy pathplugin-loader.php
File metadata and controls
361 lines (324 loc) · 9.18 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
<?php
/**
* Plugin Loader.
*
* @package sureforms
* @since 0.0.1
*/
namespace SRFM;
use SRFM\Admin\Admin;
use SRFM\Admin\Analytics;
use SRFM\Admin\Notice_Manager;
use SRFM\Inc\Abilities\Abilities_Registrar;
use SRFM\Inc\Activator;
use SRFM\Inc\Admin\Editor_Nudge;
use SRFM\Inc\Admin\Html_Form_Detector;
use SRFM\Inc\Admin_Ajax;
use SRFM\Inc\AI_Form_Builder\AI_Auth;
use SRFM\Inc\AI_Form_Builder\AI_Form_Builder;
use SRFM\Inc\AI_Form_Builder\AI_Helper;
use SRFM\Inc\AI_Form_Builder\Field_Mapping;
use SRFM\Inc\Background_Process;
use SRFM\Inc\Blocks\Register;
use SRFM\Inc\Compatibility\Multilingual\Multilingual_Manager;
use SRFM\Inc\Compatibility\Multilingual\String_Collector;
use SRFM\Inc\Compatibility\Themes\Astra;
use SRFM\Inc\Create_New_Form;
use SRFM\Inc\Database\Register as DatabaseRegister;
use SRFM\Inc\Duplicate_Form;
use SRFM\Inc\Events_Scheduler;
use SRFM\Inc\Export;
use SRFM\Inc\Form_Restriction;
use SRFM\Inc\Form_Submit;
use SRFM\Inc\Forms_Data;
use SRFM\Inc\Frontend_Assets;
use SRFM\Inc\Generate_Form_Markup;
use SRFM\Inc\Global_Settings\Email_Summary;
use SRFM\Inc\Global_Settings\Global_Settings;
use SRFM\Inc\Global_Settings\Global_Settings_Defaults;
use SRFM\Inc\Gutenberg_Hooks;
use SRFM\Inc\Helper;
use SRFM\Inc\Learn;
// region: form-migration — Phase P1 foundation.
use SRFM\Inc\Migrator\Bootstrap as Migrator_Bootstrap;
// endregion: form-migration.
use SRFM\Inc\Onboarding;
use SRFM\Inc\Page_Builders\Page_Builders;
use SRFM\Inc\Payments\Payments;
use SRFM\Inc\Post_Types;
use SRFM\Inc\Rest_Api;
use SRFM\Inc\Single_Form_Settings\Compliance_Settings;
use SRFM\Inc\Single_Form_Settings\Form_Settings_Api;
use SRFM\Inc\Smart_Tags;
use SRFM\Inc\Updater;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
/**
* Plugin_Loader
*
* @since 0.0.1
*/
class Plugin_Loader {
/**
* Instance
*
* @access private
* @var object Class Instance.
* @since 0.0.1
*/
private static $instance = null;
/**
* Constructor
*
* @since 0.0.1
*/
public function __construct() {
if ( ! defined( 'SRFM_DIR' ) || ! defined( 'SRFM_FILE' ) ) {
return;
}
// Load the action scheduler before plugin loads.
require_once SRFM_DIR . 'inc/lib/action-scheduler/action-scheduler.php';
spl_autoload_register( [ $this, 'autoload' ] );
add_action( 'plugins_loaded', [ $this, 'load_textdomain' ] );
add_action( 'plugins_loaded', [ $this, 'load_plugin' ], 99 );
add_action( 'init', [ $this, 'load_classes' ] );
add_action( 'admin_init', [ $this, 'activation_redirect' ] );
Analytics::get_instance();
/**
* The code that runs during plugin activation
*/
register_activation_hook(
SRFM_FILE,
static function () {
Activator::activate();
}
);
register_deactivation_hook(
SRFM_FILE,
static function () {
update_option( '__sureforms_do_redirect', false );
Events_Scheduler::unschedule_events( 'srfm_weekly_scheduled_events' );
Events_Scheduler::unschedule_events( 'srfm_daily_scheduled_action' );
}
);
}
/**
* Initiator
*
* @since 0.0.1
* @return object initialized object of class.
*/
public static function get_instance() {
if ( null === self::$instance ) {
self::$instance = new self();
/**
* SureForms loaded.
*
* Fires when SureForms was fully loaded and instantiated.
*
* @since 0.0.1
*/
do_action( 'srfm_core_loaded' );
}
return self::$instance;
}
/**
* Autoload classes.
*
* @param string $class class name.
* @return void
*/
public function autoload( $class ) {
if ( 0 !== strpos( $class, __NAMESPACE__ ) ) {
return;
}
$filename = preg_replace(
[ '/^' . __NAMESPACE__ . '\\\/', '/([a-z])([A-Z])/', '/_/', '/\\\/' ],
[ '', '$1-$2', '-', DIRECTORY_SEPARATOR ],
$class
);
if ( ! is_string( $filename ) ) {
return;
}
// Check for directory traversal.
if ( strpos( $filename, '..' ) !== false ) {
return;
}
$filename = strtolower( $filename );
$file = SRFM_DIR . $filename . '.php';
// if the file is readable, include it.
if ( is_readable( $file ) ) {
require_once $file;
}
}
/**
* Activation Reset
*
* @return void
* @since 0.0.1
*/
public function activation_redirect() {
// Avoid redirection in case of WP_CLI calls.
if ( defined( 'WP_CLI' ) && \WP_CLI ) {
return;
}
// Avoid redirection in case of ajax calls.
if ( wp_doing_ajax() ) {
return;
}
$do_redirect = apply_filters( 'srfm_enable_redirect_activation', get_option( '__srfm_do_redirect' ) );
if ( $do_redirect ) {
update_option( '__srfm_do_redirect', false );
if ( ! is_multisite() ) {
wp_safe_redirect(
add_query_arg(
[
'page' => 'sureforms_menu',
'srfm-activation-redirect' => true,
],
admin_url( 'admin.php' )
)
);
exit;
}
}
}
/**
* Load Classes.
*
* @return void
* @since 0.0.1
*/
public function load_classes() {
Register::get_instance();
if ( is_admin() ) {
Admin::get_instance();
// phpcs:ignore /** @phpstan-ignore-next-line */ -- Class is loaded dynamically in WordPress
Notice_Manager::get_instance();
Editor_Nudge::get_instance();
}
// Always instantiate — script enqueue is self-gated by `allow_load()`,
// while the REST endpoint for converting HTML forms must register
// outside the admin context (REST dispatch runs with `is_admin()` ===
// false, so admin-only instantiation would 404 the endpoint).
Html_Form_Detector::get_instance();
Payments::get_instance();
Duplicate_Form::get_instance();
Learn::get_instance();
}
/**
* Load Plugin Text Domain.
* This will load the translation textdomain depending on the file priorities.
* 1. Global Languages /wp-content/languages/sureforms/ folder
* 2. Local directory /wp-content/plugins/sureforms/languages/ folder
*
* @since 0.0.1
* @return void
*/
public function load_textdomain() {
// Default languages directory.
$lang_dir = SRFM_DIR . 'languages/';
/**
* Filters the languages directory path to use for plugin.
*
* @param string $lang_dir The languages directory path.
*/
$lang_dir = apply_filters( 'srfm_languages_directory', $lang_dir );
// Traditional WordPress plugin locale filter.
global $wp_version;
$get_locale = get_locale();
if ( $wp_version >= 4.7 ) {
$get_locale = get_user_locale();
}
/**
* Language Locale for plugin
*
* Uses get_user_locale()` in WordPress 4.7 or greater,
* otherwise uses `get_locale()`.
*/
$locale = apply_filters( 'plugin_locale', $get_locale, 'sureforms' );//phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- wordpress hook
$mofile = sprintf( '%1$s-%2$s.mo', 'sureforms', $locale );
// Setup paths to current locale file.
$mofile_global = WP_LANG_DIR . '/plugins/' . $mofile;
$mofile_local = $lang_dir . $mofile;
if ( file_exists( $mofile_global ) ) {
// Look in global /wp-content/languages/sureforms/ folder.
load_textdomain( 'sureforms', $mofile_global );
} elseif ( file_exists( $mofile_local ) ) {
// Look in local /wp-content/plugins/sureforms/languages/ folder.
load_textdomain( 'sureforms', $mofile_local );
} else {
// Load the default language files.
load_plugin_textdomain( 'sureforms', false, $lang_dir );
}
}
/**
* Loads plugin files.
*
* @since 0.0.1
*
* @return void
*/
public function load_plugin() {
Post_Types::get_instance();
Form_Submit::get_instance();
Gutenberg_Hooks::get_instance();
Frontend_Assets::get_instance();
Helper::get_instance();
Activator::get_instance();
Admin_Ajax::get_instance();
Forms_Data::get_instance();
Export::get_instance();
Smart_Tags::get_instance();
Generate_Form_Markup::get_instance();
Create_New_Form::get_instance();
Global_Settings::get_instance();
Global_Settings_Defaults::get_instance();
Email_Summary::get_instance();
Compliance_Settings::get_instance();
Form_Settings_Api::get_instance();
Events_Scheduler::get_instance();
AI_Form_Builder::get_instance();
Field_Mapping::get_instance();
Background_Process::get_instance();
Page_Builders::get_instance();
Rest_Api::get_instance();
// region: form-migration — Phase P1 foundation.
Migrator_Bootstrap::get_instance();
// endregion: form-migration.
AI_Helper::get_instance();
AI_Auth::get_instance();
Updater::get_instance();
Onboarding::get_instance();
DatabaseRegister::init();
Form_Restriction::get_instance();
Abilities_Registrar::get_instance();
// Initializing Compatibilities.
Astra::get_instance();
Multilingual_Manager::get_instance();
String_Collector::get_instance();
/**
* Load core files necessary for the Spectra block.
* This method is called in the Spectra block loader to ensure core files are loaded during the 'plugins_loaded' action.
*
* Note: This code is added at the bottom to ensure the form block is loaded first,
* followed by the Spectra blocks such as heading, image, and icon blocks.
*/
$this->load_core_files();
}
/**
* Load Core Files.
*
* @since 0.0.1
*
* @return void
*/
public function load_core_files() {
include_once SRFM_DIR . 'modules/gutenberg/classes/class-spec-block-loader.php';
}
}
/**
* Kicking this off by calling 'get_instance()' method
*/
Plugin_Loader::get_instance();