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