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

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