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

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