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