| @@ -7,34 +7,40 @@ | ||
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | namespace SRFM; |
| 10 | 10 | |
| 11 | -use SRFM\Inc\Post_Types; | |
| 12 | -use SRFM\Inc\Form_Submit; | |
| 13 | -use SRFM\Inc\Gutenberg_Hooks; | |
| 11 | +use SRFM\Admin\Admin; | |
| 12 | +use SRFM\Admin\Analytics; | |
| 14 | 13 | 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 | 14 | use SRFM\Inc\Activator; |
| 21 | 15 | use SRFM\Inc\Admin_Ajax; |
| 16 | +use SRFM\Inc\AI_Form_Builder\AI_Auth; | |
| 17 | +use SRFM\Inc\AI_Form_Builder\AI_Form_Builder; | |
| 18 | +use SRFM\Inc\AI_Form_Builder\AI_Helper; | |
| 19 | +use SRFM\Inc\AI_Form_Builder\Field_Mapping; | |
| 20 | +use SRFM\Inc\Background_Process; | |
| 21 | +use SRFM\Inc\Blocks\Register; | |
| 22 | +use SRFM\Inc\Compatibility\Themes\Astra; | |
| 23 | +use SRFM\Inc\Create_New_Form; | |
| 24 | +use SRFM\Inc\Database\Register as DatabaseRegister; | |
| 25 | +use SRFM\Inc\Events_Scheduler; | |
| 22 | 26 | use SRFM\Inc\Export; |
| 23 | -use SRFM\Inc\Smart_Tags; | |
| 27 | +use SRFM\Inc\Form_Submit; | |
| 28 | +use SRFM\Inc\Forms_Data; | |
| 29 | +use SRFM\Inc\Frontend_Assets; | |
| 24 | 30 | use SRFM\Inc\Generate_Form_Markup; |
| 25 | -use SRFM\Inc\Create_New_Form; | |
| 31 | +use SRFM\Inc\Global_Settings\Email_Summary; | |
| 26 | 32 | 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\AI_Form_Builder\AI_Form_Builder; | |
| 31 | -use SRFM\Inc\AI_Form_Builder\Field_Mapping; | |
| 32 | -use SRFM\Inc\Background_Process; | |
| 33 | +use SRFM\Inc\Gutenberg_Hooks; | |
| 34 | +use SRFM\Inc\Helper; | |
| 35 | +use SRFM\Inc\Lib\SRFM_Nps_Survey; | |
| 36 | +use SRFM\Inc\Nps_Notice; | |
| 33 | 37 | use SRFM\Inc\Page_Builders\Page_Builders; |
| 38 | +use SRFM\Inc\Post_Types; | |
| 34 | 39 | use SRFM\Inc\Rest_Api; |
| 35 | -use SRFM\Inc\AI_Form_Builder\AI_Helper; | |
| 36 | -use SRFM\Inc\AI_Form_Builder\AI_Auth; | |
| 40 | +use SRFM\Inc\Single_Form_Settings\Compliance_Settings; | |
| 41 | +use SRFM\Inc\Smart_Tags; | |
| 42 | +use SRFM\Inc\Updater; | |
| 37 | 43 | |
| 38 | 44 | if ( ! defined( 'ABSPATH' ) ) { |
| 39 | 45 | exit; // Exit if accessed directly. |
| 40 | 46 | } |
| @@ -44,9 +50,8 @@ | ||
| 44 | 50 | * |
| 45 | 51 | * @since 0.0.1 |
| 46 | 52 | */ |
| 47 | 53 | class Plugin_Loader { |
| 48 | - | |
| 49 | 54 | /** |
| 50 | 55 | * Instance |
| 51 | 56 | * |
| 52 | 57 | * @access private |
| @@ -55,8 +60,47 @@ | ||
| 55 | 60 | */ |
| 56 | 61 | private static $instance = null; |
| 57 | 62 | |
| 58 | 63 | /** |
| 64 | + * Constructor | |
| 65 | + * | |
| 66 | + * @since 0.0.1 | |
| 67 | + */ | |
| 68 | + public function __construct() { | |
| 69 | + if ( ! defined( 'SRFM_DIR' ) || ! defined( 'SRFM_FILE' ) ) { | |
| 70 | + return; | |
| 71 | + } | |
| 72 | + // Load the action scheduler before plugin loads. | |
| 73 | + require_once SRFM_DIR . 'inc/lib/action-scheduler/action-scheduler.php'; | |
| 74 | + | |
| 75 | + spl_autoload_register( [ $this, 'autoload' ] ); | |
| 76 | + | |
| 77 | + add_action( 'plugins_loaded', [ $this, 'load_textdomain' ] ); | |
| 78 | + add_action( 'plugins_loaded', [ $this, 'load_plugin' ], 99 ); | |
| 79 | + add_action( 'init', [ $this, 'load_classes' ] ); | |
| 80 | + add_action( 'admin_init', [ $this, 'activation_redirect' ] ); | |
| 81 | + Analytics::get_instance(); | |
| 82 | + /** | |
| 83 | + * The code that runs during plugin activation | |
| 84 | + */ | |
| 85 | + register_activation_hook( | |
| 86 | + SRFM_FILE, | |
| 87 | + static function () { | |
| 88 | + Activator::activate(); | |
| 89 | + } | |
| 90 | + ); | |
| 91 | + | |
| 92 | + register_deactivation_hook( | |
| 93 | + SRFM_FILE, | |
| 94 | + static function () { | |
| 95 | + update_option( '__sureforms_do_redirect', false ); | |
| 96 | + Events_Scheduler::unschedule_events( 'srfm_weekly_scheduled_events' ); | |
| 97 | + Events_Scheduler::unschedule_events( 'srfm_daily_scheduled_action' ); | |
| 98 | + } | |
| 99 | + ); | |
| 100 | + } | |
| 101 | + | |
| 102 | + /** | |
| 59 | 103 | * Initiator |
| 60 | 104 | * |
| 61 | 105 | * @since 0.0.1 |
| 62 | 106 | * @return object initialized object of class. |
| @@ -104,73 +148,11 @@ | ||
| 104 | 148 | if ( is_readable( $file ) ) { |
| 105 | 149 | require_once $file; |
| 106 | 150 | } |
| 107 | 151 | } |
| 108 | - | |
| 109 | 152 | } |
| 110 | 153 | |
| 111 | 154 | /** |
| 112 | - * Constructor | |
| 113 | - * | |
| 114 | - * @since 0.0.1 | |
| 115 | - */ | |
| 116 | - public function __construct() { | |
| 117 | - // Load the action scheduler before plugin loads. | |
| 118 | - require_once SRFM_DIR . 'inc/lib/action-scheduler/action-scheduler.php'; | |
| 119 | - | |
| 120 | - spl_autoload_register( [ $this, 'autoload' ] ); | |
| 121 | - | |
| 122 | - add_action( 'plugins_loaded', [ $this, 'load_textdomain' ] ); | |
| 123 | - add_action( 'plugins_loaded', [ $this, 'load_plugin' ], 99 ); | |
| 124 | - add_action( 'init', [ $this, 'load_classes' ] ); | |
| 125 | - add_action( 'admin_init', [ $this, 'activation_redirect' ] ); | |
| 126 | - Post_Types::get_instance(); | |
| 127 | - Form_Submit::get_instance(); | |
| 128 | - Block_Patterns::get_instance(); | |
| 129 | - Gutenberg_Hooks::get_instance(); | |
| 130 | - Register::get_instance(); | |
| 131 | - Frontend_Assets::get_instance(); | |
| 132 | - Helper::get_instance(); | |
| 133 | - Activator::get_instance(); | |
| 134 | - Admin_Ajax::get_instance(); | |
| 135 | - Forms_Data::get_instance(); | |
| 136 | - Export::get_instance(); | |
| 137 | - Smart_Tags::get_instance(); | |
| 138 | - Generate_Form_Markup::get_instance(); | |
| 139 | - Create_New_Form::get_instance(); | |
| 140 | - Global_Settings::get_instance(); | |
| 141 | - Email_Summary::get_instance(); | |
| 142 | - Compliance_Settings::get_instance(); | |
| 143 | - Events_Scheduler::get_instance(); | |
| 144 | - AI_Form_Builder::get_instance(); | |
| 145 | - Field_Mapping::get_instance(); | |
| 146 | - Background_Process::get_instance(); | |
| 147 | - Page_Builders::get_instance(); | |
| 148 | - Rest_Api::get_instance(); | |
| 149 | - AI_Helper::get_instance(); | |
| 150 | - AI_Auth::get_instance(); | |
| 151 | - | |
| 152 | - /** | |
| 153 | - * The code that runs during plugin activation | |
| 154 | - */ | |
| 155 | - register_activation_hook( | |
| 156 | - SRFM_FILE, | |
| 157 | - function () { | |
| 158 | - Activator::activate(); | |
| 159 | - } | |
| 160 | - ); | |
| 161 | - | |
| 162 | - register_deactivation_hook( | |
| 163 | - SRFM_FILE, | |
| 164 | - function () { | |
| 165 | - update_option( '__sureforms_do_redirect', false ); | |
| 166 | - Events_Scheduler::unschedule_events( 'srfm_weekly_scheduled_events' ); | |
| 167 | - Events_Scheduler::unschedule_events( 'srfm_daily_scheduled_action' ); | |
| 168 | - } | |
| 169 | - ); | |
| 170 | - } | |
| 171 | - | |
| 172 | - /** | |
| 173 | 155 | * Activation Reset |
| 174 | 156 | * |
| 175 | 157 | * @return void |
| 176 | 158 | * @since 0.0.1 |
| @@ -175,9 +157,18 @@ | ||
| 175 | 157 | * @return void |
| 176 | 158 | * @since 0.0.1 |
| 177 | 159 | */ |
| 178 | 160 | public function activation_redirect() { |
| 161 | + // Avoid redirection in case of WP_CLI calls. | |
| 162 | + if ( defined( 'WP_CLI' ) && \WP_CLI ) { | |
| 163 | + return; | |
| 164 | + } | |
| 179 | 165 | |
| 166 | + // Avoid redirection in case of ajax calls. | |
| 167 | + if ( wp_doing_ajax() ) { | |
| 168 | + return; | |
| 169 | + } | |
| 170 | + | |
| 180 | 171 | $do_redirect = apply_filters( 'srfm_enable_redirect_activation', get_option( '__srfm_do_redirect' ) ); |
| 181 | 172 | |
| 182 | 173 | if ( $do_redirect ) { |
| 183 | 174 | |
| @@ -192,9 +183,9 @@ | ||
| 192 | 183 | ], |
| 193 | 184 | admin_url( 'admin.php' ) |
| 194 | 185 | ) |
| 195 | 186 | ); |
| 196 | - exit(); | |
| 187 | + exit; | |
| 197 | 188 | } |
| 198 | 189 | } |
| 199 | 190 | } |
| 200 | 191 | |
| @@ -204,8 +195,10 @@ | ||
| 204 | 195 | * @return void |
| 205 | 196 | * @since 0.0.1 |
| 206 | 197 | */ |
| 207 | 198 | public function load_classes() { |
| 199 | + | |
| 200 | + Register::get_instance(); | |
| 208 | 201 | if ( is_admin() ) { |
| 209 | 202 | Admin::get_instance(); |
| 210 | 203 | } |
| 211 | 204 | } |
| @@ -241,9 +234,8 @@ | ||
| 241 | 234 | |
| 242 | 235 | /** |
| 243 | 236 | * Language Locale for plugin |
| 244 | 237 | * |
| 245 | - * @var string $get_locale The locale to use. | |
| 246 | 238 | * Uses get_user_locale()` in WordPress 4.7 or greater, |
| 247 | 239 | * otherwise uses `get_locale()`. |
| 248 | 240 | */ |
| 249 | 241 | $locale = apply_filters( 'plugin_locale', $get_locale, 'sureforms' );//phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- wordpress hook |
| @@ -264,9 +256,8 @@ | ||
| 264 | 256 | load_plugin_textdomain( 'sureforms', false, $lang_dir ); |
| 265 | 257 | } |
| 266 | 258 | } |
| 267 | 259 | |
| 268 | - | |
| 269 | 260 | /** |
| 270 | 261 | * Loads plugin files. |
| 271 | 262 | * |
| 272 | 263 | * @since 0.0.1 |
| @@ -273,8 +264,53 @@ | ||
| 273 | 264 | * |
| 274 | 265 | * @return void |
| 275 | 266 | */ |
| 276 | 267 | public function load_plugin() { |
| 268 | + Post_Types::get_instance(); | |
| 269 | + Form_Submit::get_instance(); | |
| 270 | + Block_Patterns::get_instance(); | |
| 271 | + Gutenberg_Hooks::get_instance(); | |
| 272 | + Frontend_Assets::get_instance(); | |
| 273 | + Helper::get_instance(); | |
| 274 | + Activator::get_instance(); | |
| 275 | + Admin_Ajax::get_instance(); | |
| 276 | + Forms_Data::get_instance(); | |
| 277 | + Export::get_instance(); | |
| 278 | + Smart_Tags::get_instance(); | |
| 279 | + Generate_Form_Markup::get_instance(); | |
| 280 | + Create_New_Form::get_instance(); | |
| 281 | + Global_Settings::get_instance(); | |
| 282 | + Email_Summary::get_instance(); | |
| 283 | + Compliance_Settings::get_instance(); | |
| 284 | + Events_Scheduler::get_instance(); | |
| 285 | + AI_Form_Builder::get_instance(); | |
| 286 | + Field_Mapping::get_instance(); | |
| 287 | + Background_Process::get_instance(); | |
| 288 | + Page_Builders::get_instance(); | |
| 289 | + Rest_Api::get_instance(); | |
| 290 | + AI_Helper::get_instance(); | |
| 291 | + AI_Auth::get_instance(); | |
| 292 | + Updater::get_instance(); | |
| 293 | + DatabaseRegister::init(); | |
| 294 | + // Initializing Compatibilities. | |
| 295 | + Astra::get_instance(); | |
| 296 | + /** | |
| 297 | + * Required to add the if check for the class existence to resolve phpstan error, | |
| 298 | + * as the phpstan configuration ignores the inc/lib directory which gives error | |
| 299 | + * unknown class. | |
| 300 | + */ | |
| 301 | + if ( class_exists( 'SRFM\Inc\Lib\SRFM_Nps_Survey' ) && ! apply_filters( 'srfm_disable_nps_survey', false ) ) { | |
| 302 | + SRFM_Nps_Survey::get_instance(); // Inits the NPS Survey class for which inits the NPS Survey plugin. | |
| 303 | + Nps_Notice::get_instance(); // Responsible for displaying the NPS Survey: keeping the line out of the check will also work. | |
| 304 | + } | |
| 305 | + | |
| 306 | + /** | |
| 307 | + * Load core files necessary for the Spectra block. | |
| 308 | + * This method is called in the Spectra block loader to ensure core files are loaded during the 'plugins_loaded' action. | |
| 309 | + * | |
| 310 | + * Note: This code is added at the bottom to ensure the form block is loaded first, | |
| 311 | + * followed by the Spectra blocks such as heading, image, and icon blocks. | |
| 312 | + */ | |
| 277 | 313 | $this->load_core_files(); |
| 278 | 314 | } |
| 279 | 315 | |
| 280 | 316 | /** |
| @@ -287,10 +323,8 @@ | ||
| 287 | 323 | public function load_core_files() { |
| 288 | 324 | include_once SRFM_DIR . 'modules/gutenberg/classes/class-spec-block-loader.php'; |
| 289 | 325 | } |
| 290 | 326 | } |
| 291 | - | |
| 292 | - | |
| 293 | 327 | |
| 294 | 328 | /** |
| 295 | 329 | * Kicking this off by calling 'get_instance()' method |
| 296 | 330 | */ |