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