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