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