PluginProbe
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz / 0.0.12
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz v0.0.12
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 in SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz 0.0.12, at plugin-loader.php

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