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

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