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