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

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