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

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