PluginProbe
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz / 2.8.2
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz v2.8.2
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 in SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz 2.8.2, at plugin-loader.php

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