PluginProbe
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz / 2.8.1
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz v2.8.1
2.12.6 2.12.5 2.12.4 2.12.3 2.12.2 2.12.1 2.12.0 2.11.1 2.11.0 2.10.1 2.10.0 2.9.1 2.9.0 2.8.2 2.8.1 2.7.0 2.7.1 2.8.0 trunk 0.0.10 0.0.11 0.0.12 0.0.13 0.0.2 0.0.3 All 96 releases
← All changes | plugin-loader.php +133 -96 0.0.132.8.1 View file →
@@ -7,35 +7,43 @@
7 7 */
8 8
9 9 namespace SRFM;
10 10
11 -use SRFM\Inc\Post_Types;
12 -use SRFM\Inc\Form_Submit;
13 -use SRFM\Inc\Gutenberg_Hooks;
14 -use SRFM\API\Block_Patterns;
15 -use SRFM\Inc\Forms_Data;
16 11 use SRFM\Admin\Admin;
17 -use SRFM\Inc\Blocks\Register;
18 -use SRFM\Inc\Frontend_Assets;
19 -use SRFM\Inc\Helper;
12 +use SRFM\Admin\Analytics;
13 +use SRFM\Admin\Notice_Manager;
14 +use SRFM\Inc\Abilities\Abilities_Registrar;
20 15 use SRFM\Inc\Activator;
21 16 use SRFM\Inc\Admin_Ajax;
17 +use SRFM\Inc\AI_Form_Builder\AI_Auth;
18 +use SRFM\Inc\AI_Form_Builder\AI_Form_Builder;
19 +use SRFM\Inc\AI_Form_Builder\AI_Helper;
20 +use SRFM\Inc\AI_Form_Builder\Field_Mapping;
21 +use SRFM\Inc\Background_Process;
22 +use SRFM\Inc\Blocks\Register;
23 +use SRFM\Inc\Compatibility\Themes\Astra;
24 +use SRFM\Inc\Create_New_Form;
25 +use SRFM\Inc\Database\Register as DatabaseRegister;
26 +use SRFM\Inc\Duplicate_Form;
27 +use SRFM\Inc\Events_Scheduler;
22 28 use SRFM\Inc\Export;
23 -use SRFM\Inc\Smart_Tags;
29 +use SRFM\Inc\Form_Restriction;
30 +use SRFM\Inc\Form_Submit;
31 +use SRFM\Inc\Forms_Data;
32 +use SRFM\Inc\Frontend_Assets;
24 33 use SRFM\Inc\Generate_Form_Markup;
25 -use SRFM\Inc\Create_New_Form;
34 +use SRFM\Inc\Global_Settings\Email_Summary;
26 35 use SRFM\Inc\Global_Settings\Global_Settings;
27 -use SRFM\Inc\Global_Settings\Email_Summary;
28 -use SRFM\Inc\Single_Form_Settings\Compliance_Settings;
29 -use SRFM\Inc\Events_Scheduler;
30 -use SRFM\Inc\AI_Form_Builder\AI_Form_Builder;
31 -use SRFM\Inc\AI_Form_Builder\Field_Mapping;
32 -use SRFM\Inc\Background_Process;
36 +use SRFM\Inc\Gutenberg_Hooks;
37 +use SRFM\Inc\Helper;
38 +use SRFM\Inc\Learn;
39 +use SRFM\Inc\Onboarding;
33 40 use SRFM\Inc\Page_Builders\Page_Builders;
41 +use SRFM\Inc\Payments\Payments;
42 +use SRFM\Inc\Post_Types;
34 43 use SRFM\Inc\Rest_Api;
35 -use SRFM\Inc\AI_Form_Builder\AI_Helper;
36 -use SRFM\Inc\AI_Form_Builder\AI_Auth;
37 -use SRFM\Inc\Database\Register as DatabaseRegister;
44 +use SRFM\Inc\Single_Form_Settings\Compliance_Settings;
45 +use SRFM\Inc\Smart_Tags;
38 46 use SRFM\Inc\Updater;
39 47
40 48 if ( ! defined( 'ABSPATH' ) ) {
41 49 exit; // Exit if accessed directly.
@@ -46,9 +54,8 @@
46 54 *
47 55 * @since 0.0.1
48 56 */
49 57 class Plugin_Loader {
50 -
51 58 /**
52 59 * Instance
53 60 *
54 61 * @access private
@@ -57,8 +64,47 @@
57 64 */
58 65 private static $instance = null;
59 66
60 67 /**
68 + * Constructor
69 + *
70 + * @since 0.0.1
71 + */
72 + public function __construct() {
73 + if ( ! defined( 'SRFM_DIR' ) || ! defined( 'SRFM_FILE' ) ) {
74 + return;
75 + }
76 + // Load the action scheduler before plugin loads.
77 + require_once SRFM_DIR . 'inc/lib/action-scheduler/action-scheduler.php';
78 +
79 + spl_autoload_register( [ $this, 'autoload' ] );
80 +
81 + add_action( 'plugins_loaded', [ $this, 'load_textdomain' ] );
82 + add_action( 'plugins_loaded', [ $this, 'load_plugin' ], 99 );
83 + add_action( 'init', [ $this, 'load_classes' ] );
84 + add_action( 'admin_init', [ $this, 'activation_redirect' ] );
85 + Analytics::get_instance();
86 + /**
87 + * The code that runs during plugin activation
88 + */
89 + register_activation_hook(
90 + SRFM_FILE,
91 + static function () {
92 + Activator::activate();
93 + }
94 + );
95 +
96 + register_deactivation_hook(
97 + SRFM_FILE,
98 + static function () {
99 + update_option( '__sureforms_do_redirect', false );
100 + Events_Scheduler::unschedule_events( 'srfm_weekly_scheduled_events' );
101 + Events_Scheduler::unschedule_events( 'srfm_daily_scheduled_action' );
102 + }
103 + );
104 + }
105 +
106 + /**
61 107 * Initiator
62 108 *
63 109 * @since 0.0.1
64 110 * @return object initialized object of class.
@@ -95,84 +141,25 @@
95 141 [ '', '$1-$2', '-', DIRECTORY_SEPARATOR ],
96 142 $class
97 143 );
98 144
99 - if ( is_string( $filename ) ) {
145 + if ( ! is_string( $filename ) ) {
146 + return;
147 + }
100 148
101 - $filename = strtolower( $filename );
102 -
103 - $file = SRFM_DIR . $filename . '.php';
104 -
105 - // if the file is readable, include it.
106 - if ( is_readable( $file ) ) {
107 - require_once $file;
108 - }
149 + // Check for directory traversal.
150 + if ( strpos( $filename, '..' ) !== false ) {
151 + return;
109 152 }
110 153
111 - }
154 + $filename = strtolower( $filename );
112 155
113 - /**
114 - * Constructor
115 - *
116 - * @since 0.0.1
117 - */
118 - public function __construct() {
119 - // Load the action scheduler before plugin loads.
120 - require_once SRFM_DIR . 'inc/lib/action-scheduler/action-scheduler.php';
156 + $file = SRFM_DIR . $filename . '.php';
121 157
122 - spl_autoload_register( [ $this, 'autoload' ] );
123 -
124 - add_action( 'plugins_loaded', [ $this, 'load_textdomain' ] );
125 - add_action( 'plugins_loaded', [ $this, 'load_plugin' ], 99 );
126 - add_action( 'init', [ $this, 'load_classes' ] );
127 - add_action( 'admin_init', [ $this, 'activation_redirect' ] );
128 - Post_Types::get_instance();
129 - Form_Submit::get_instance();
130 - Block_Patterns::get_instance();
131 - Gutenberg_Hooks::get_instance();
132 - Register::get_instance();
133 - Frontend_Assets::get_instance();
134 - Helper::get_instance();
135 - Activator::get_instance();
136 - Admin_Ajax::get_instance();
137 - Forms_Data::get_instance();
138 - Export::get_instance();
139 - Smart_Tags::get_instance();
140 - Generate_Form_Markup::get_instance();
141 - Create_New_Form::get_instance();
142 - Global_Settings::get_instance();
143 - Email_Summary::get_instance();
144 - Compliance_Settings::get_instance();
145 - Events_Scheduler::get_instance();
146 - AI_Form_Builder::get_instance();
147 - Field_Mapping::get_instance();
148 - Background_Process::get_instance();
149 - Page_Builders::get_instance();
150 - Rest_Api::get_instance();
151 - AI_Helper::get_instance();
152 - AI_Auth::get_instance();
153 - Updater::get_instance();
154 -
155 - DatabaseRegister::init();
156 -
157 - /**
158 - * The code that runs during plugin activation
159 - */
160 - register_activation_hook(
161 - SRFM_FILE,
162 - function () {
163 - Activator::activate();
164 - }
165 - );
166 -
167 - register_deactivation_hook(
168 - SRFM_FILE,
169 - function () {
170 - update_option( '__sureforms_do_redirect', false );
171 - Events_Scheduler::unschedule_events( 'srfm_weekly_scheduled_events' );
172 - Events_Scheduler::unschedule_events( 'srfm_daily_scheduled_action' );
173 - }
174 - );
158 + // if the file is readable, include it.
159 + if ( is_readable( $file ) ) {
160 + require_once $file;
161 + }
175 162 }
176 163
177 164 /**
178 165 * Activation Reset
@@ -180,9 +167,18 @@
180 167 * @return void
181 168 * @since 0.0.1
182 169 */
183 170 public function activation_redirect() {
171 + // Avoid redirection in case of WP_CLI calls.
172 + if ( defined( 'WP_CLI' ) && \WP_CLI ) {
173 + return;
174 + }
184 175
176 + // Avoid redirection in case of ajax calls.
177 + if ( wp_doing_ajax() ) {
178 + return;
179 + }
180 +
185 181 $do_redirect = apply_filters( 'srfm_enable_redirect_activation', get_option( '__srfm_do_redirect' ) );
186 182
187 183 if ( $do_redirect ) {
188 184
@@ -197,9 +193,9 @@
197 193 ],
198 194 admin_url( 'admin.php' )
199 195 )
200 196 );
201 - exit();
197 + exit;
202 198 }
203 199 }
204 200 }
205 201
@@ -209,11 +205,18 @@
209 205 * @return void
210 206 * @since 0.0.1
211 207 */
212 208 public function load_classes() {
209 +
210 + Register::get_instance();
213 211 if ( is_admin() ) {
214 212 Admin::get_instance();
213 + // phpcs:ignore /** @phpstan-ignore-next-line */ -- Class is loaded dynamically in WordPress
214 + Notice_Manager::get_instance();
215 215 }
216 + Payments::get_instance();
217 + Duplicate_Form::get_instance();
218 + Learn::get_instance();
216 219 }
217 220
218 221 /**
219 222 * Load Plugin Text Domain.
@@ -246,9 +249,8 @@
246 249
247 250 /**
248 251 * Language Locale for plugin
249 252 *
250 - * @var string $get_locale The locale to use.
251 253 * Uses get_user_locale()` in WordPress 4.7 or greater,
252 254 * otherwise uses `get_locale()`.
253 255 */
254 256 $locale = apply_filters( 'plugin_locale', $get_locale, 'sureforms' );//phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- wordpress hook
@@ -269,9 +271,8 @@
269 271 load_plugin_textdomain( 'sureforms', false, $lang_dir );
270 272 }
271 273 }
272 274
273 -
274 275 /**
275 276 * Loads plugin files.
276 277 *
277 278 * @since 0.0.1
@@ -278,8 +279,46 @@
278 279 *
279 280 * @return void
280 281 */
281 282 public function load_plugin() {
283 + Post_Types::get_instance();
284 + Form_Submit::get_instance();
285 + Gutenberg_Hooks::get_instance();
286 + Frontend_Assets::get_instance();
287 + Helper::get_instance();
288 + Activator::get_instance();
289 + Admin_Ajax::get_instance();
290 + Forms_Data::get_instance();
291 + Export::get_instance();
292 + Smart_Tags::get_instance();
293 + Generate_Form_Markup::get_instance();
294 + Create_New_Form::get_instance();
295 + Global_Settings::get_instance();
296 + Email_Summary::get_instance();
297 + Compliance_Settings::get_instance();
298 + Events_Scheduler::get_instance();
299 + AI_Form_Builder::get_instance();
300 + Field_Mapping::get_instance();
301 + Background_Process::get_instance();
302 + Page_Builders::get_instance();
303 + Rest_Api::get_instance();
304 + AI_Helper::get_instance();
305 + AI_Auth::get_instance();
306 + Updater::get_instance();
307 + Onboarding::get_instance();
308 + DatabaseRegister::init();
309 + Form_Restriction::get_instance();
310 + Abilities_Registrar::get_instance();
311 + // Initializing Compatibilities.
312 + Astra::get_instance();
313 +
314 + /**
315 + * Load core files necessary for the Spectra block.
316 + * This method is called in the Spectra block loader to ensure core files are loaded during the 'plugins_loaded' action.
317 + *
318 + * Note: This code is added at the bottom to ensure the form block is loaded first,
319 + * followed by the Spectra blocks such as heading, image, and icon blocks.
320 + */
282 321 $this->load_core_files();
283 322 }
284 323
285 324 /**
@@ -292,10 +331,8 @@
292 331 public function load_core_files() {
293 332 include_once SRFM_DIR . 'modules/gutenberg/classes/class-spec-block-loader.php';
294 333 }
295 334 }
296 -
297 -
298 335
299 336 /**
300 337 * Kicking this off by calling 'get_instance()' method
301 338 */