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