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