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