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