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