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

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