actions
2 years ago
addons
2 years ago
admin
2 years ago
blocks
2 years ago
classes
2 years ago
compatibility
2 years ago
db-queries
2 years ago
dev-mode
2 years ago
exceptions
2 years ago
form-actions
2 years ago
form-messages
2 years ago
form-patterns
2 years ago
form-response
2 years ago
gateways
2 years ago
generators
2 years ago
integrations
2 years ago
migrations
2 years ago
post-meta
2 years ago
presets
2 years ago
request
2 years ago
rest-api
2 years ago
shortcodes
2 years ago
wp-cli
2 years ago
autoloader.php
2 years ago
file-upload.php
2 years ago
form-break.php
2 years ago
form-handler.php
2 years ago
form-manager.php
2 years ago
live-form.php
2 years ago
plugin.php
2 years ago
post-type.php
2 years ago
plugin.php
261 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Jet_Form_Builder; |
| 4 | |
| 5 | // If this file is called directly, abort. |
| 6 | use Jet_Form_Builder\Actions\Manager as ActionsManager; |
| 7 | use Jet_Form_Builder\Admin\Pages\Pages_Manager; |
| 8 | use Jet_Form_Builder\Admin\Tabs_Handlers\Tab_Handler_Manager; |
| 9 | use Jet_Form_Builder\Blocks\Conditional_Block\Render_State; |
| 10 | use Jet_Form_Builder\Blocks\Dynamic_Value; |
| 11 | use Jet_Form_Builder\Blocks\Manager as BlocksManager; |
| 12 | use Jet_Form_Builder\Blocks\Switch_Page_On_Change; |
| 13 | use Jet_Form_Builder\Blocks\Validation; |
| 14 | use Jet_Form_Builder\Classes\Regexp_Tools; |
| 15 | use Jet_Form_Builder\Classes\Tools; |
| 16 | use Jet_Form_Builder\Compatibility\Deprecated; |
| 17 | use Jet_Form_Builder\Compatibility\Elementor\Elementor; |
| 18 | use Jet_Form_Builder\Compatibility\Jet_Appointment\Jet_Appointment; |
| 19 | use Jet_Form_Builder\Compatibility\Jet_Booking\Jet_Booking; |
| 20 | use Jet_Form_Builder\Compatibility\Jet_Engine\Jet_Engine; |
| 21 | use Jet_Form_Builder\Compatibility\Woocommerce\Woocommerce; |
| 22 | use Jet_Form_Builder\Form_Actions\Form_Actions_Manager; |
| 23 | use Jet_Form_Builder\Form_Messages; |
| 24 | use Jet_Form_Builder\Form_Patterns\Manager as PatternsManager; |
| 25 | use Jet_Form_Builder\Framework\CX_Loader; |
| 26 | use Jet_Form_Builder\Gateways\Gateway_Manager; |
| 27 | use Jet_Form_Builder\Integrations\Active_Campaign\Active_Campaign; |
| 28 | use Jet_Form_Builder\Integrations\Forms_Captcha; |
| 29 | use Jet_Form_Builder\Addons\Manager as AddonsManager; |
| 30 | use Jet_Form_Builder\Presets\Preset_Manager; |
| 31 | use Jet_Form_Builder\Wp_Cli\Wp_Cli_Manager; |
| 32 | use Jet_Form_Builder\Migrations; |
| 33 | |
| 34 | if ( ! defined( 'WPINC' ) ) { |
| 35 | die; |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * @property Post_Type $post_type |
| 40 | * @property BlocksManager $blocks |
| 41 | * @property ActionsManager $actions |
| 42 | * @property Form_Manager $form |
| 43 | * @property Form_Handler $form_handler |
| 44 | * @property Forms_Captcha $captcha |
| 45 | * @property Admin\Editor $editor |
| 46 | * @property AddonsManager $addons_manager |
| 47 | * @property \Jet_Admin_Bar $admin_bar |
| 48 | * @property Form_Messages\Msg_Router $msg_router |
| 49 | * @property Regexp_Tools $regexp |
| 50 | * Class Plugin |
| 51 | * @package Jet_Form_Builder |
| 52 | */ |
| 53 | class Plugin { |
| 54 | |
| 55 | public $post_type; |
| 56 | public $blocks; |
| 57 | public $actions; |
| 58 | public $form; |
| 59 | public $form_handler; |
| 60 | public $editor; |
| 61 | public $captcha; |
| 62 | public $allow_gateways; |
| 63 | public $framework; |
| 64 | public $addons_manager; |
| 65 | public $admin_bar; |
| 66 | public $msg_router; |
| 67 | public $regexp; |
| 68 | |
| 69 | private $suffix; |
| 70 | |
| 71 | public static $instance; |
| 72 | |
| 73 | /** |
| 74 | * Instance. |
| 75 | * |
| 76 | * Ensures only one instance of the plugin class is loaded or can be loaded. |
| 77 | * |
| 78 | * @since 1.0.0 |
| 79 | * @access public |
| 80 | * @static |
| 81 | */ |
| 82 | public static function instance() { |
| 83 | |
| 84 | if ( is_null( self::$instance ) ) { |
| 85 | self::$instance = new self(); |
| 86 | } |
| 87 | |
| 88 | return self::$instance; |
| 89 | } |
| 90 | |
| 91 | public static function clear() { |
| 92 | self::$instance = null; |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Register autoloader. |
| 97 | */ |
| 98 | private function register_autoloader() { |
| 99 | require JET_FORM_BUILDER_PATH . 'includes' . DIRECTORY_SEPARATOR . 'autoloader.php'; |
| 100 | Autoloader::run(); |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Initialize plugin parts |
| 105 | * |
| 106 | * @return void |
| 107 | */ |
| 108 | public function init_components() { |
| 109 | $this->allow_gateways = apply_filters( 'jet-form-builder/allow-gateways', false ); |
| 110 | $this->maybe_enable_gateways(); |
| 111 | |
| 112 | /** |
| 113 | * Compatibility & Integrations |
| 114 | */ |
| 115 | Woocommerce::register(); |
| 116 | Jet_Engine::register(); |
| 117 | Active_Campaign::register(); |
| 118 | Elementor::register(); |
| 119 | Jet_Appointment::register(); |
| 120 | Jet_Booking::register(); |
| 121 | new Deprecated(); |
| 122 | |
| 123 | $this->admin_bar = \Jet_Admin_Bar::get_instance(); |
| 124 | $this->msg_router = new Form_Messages\Msg_Router(); |
| 125 | $this->post_type = new Post_Type(); |
| 126 | $this->blocks = new Blocks\Manager(); |
| 127 | $this->actions = new Actions\Manager(); |
| 128 | $this->form = new Form_Manager(); |
| 129 | $this->form_handler = new Form_Handler(); |
| 130 | $this->captcha = new Forms_Captcha(); |
| 131 | $this->addons_manager = new AddonsManager(); |
| 132 | $this->regexp = new Regexp_Tools(); |
| 133 | |
| 134 | /** |
| 135 | * Modules & components |
| 136 | */ |
| 137 | Dev_Mode\Manager::instance(); |
| 138 | File_Upload::instance(); |
| 139 | Validation::instance(); |
| 140 | Render_State::instance(); |
| 141 | new Dynamic_Value(); |
| 142 | new Switch_Page_On_Change(); |
| 143 | |
| 144 | /** |
| 145 | * REST API |
| 146 | */ |
| 147 | ( new Migrations\Rest_Api\Controller() )->rest_api_init(); |
| 148 | ( new Blocks\Conditional_Block\Rest_Api\Rest_Api_Controller() )->rest_api_init(); |
| 149 | ( new Blocks\Ssr_Validation\Rest_Controller() )->rest_api_init(); |
| 150 | |
| 151 | if ( is_admin() ) { |
| 152 | Preset_Manager::instance(); |
| 153 | |
| 154 | $this->editor = new Admin\Editor(); |
| 155 | Pages_Manager::instance()->set_up(); |
| 156 | |
| 157 | new Form_Actions_Manager(); |
| 158 | new PatternsManager(); |
| 159 | } else { |
| 160 | $this->form_handler->call_form(); |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | public function init_framework() { |
| 165 | require $this->plugin_dir( 'framework/loader.php' ); |
| 166 | |
| 167 | $this->framework = new CX_Loader( |
| 168 | array( |
| 169 | $this->plugin_dir( 'framework/vue-ui/cherry-x-vue-ui.php' ), |
| 170 | $this->plugin_dir( 'framework/admin-bar/jet-admin-bar.php' ), |
| 171 | ) |
| 172 | ); |
| 173 | } |
| 174 | |
| 175 | public function maybe_enable_gateways() { |
| 176 | Tab_Handler_Manager::instance()->tab( 'payments-gateways' )->save_global_options(); |
| 177 | $gateways = Tab_Handler_Manager::instance()->tab( 'payments-gateways' )->get_global_options(); |
| 178 | |
| 179 | if ( isset( $gateways['enable_test_mode'] ) ) { |
| 180 | add_filter( |
| 181 | 'jet-form-builder/gateways/paypal/sandbox-mode', |
| 182 | function () use ( $gateways ) { |
| 183 | return $gateways['enable_test_mode']; |
| 184 | } |
| 185 | ); |
| 186 | } |
| 187 | |
| 188 | if ( isset( $gateways['use_gateways'] ) ) { |
| 189 | $this->allow_gateways = $gateways['use_gateways']; |
| 190 | } |
| 191 | |
| 192 | Gateway_Manager::instance()->set_up(); |
| 193 | } |
| 194 | |
| 195 | /** |
| 196 | * Loads the translation files. |
| 197 | * |
| 198 | * @return void |
| 199 | * @since 1.0.0 |
| 200 | * @access public |
| 201 | */ |
| 202 | public function init_lang() { |
| 203 | load_plugin_textdomain( |
| 204 | 'jet-form-builder', |
| 205 | false, |
| 206 | dirname( plugin_basename( JET_FORM_BUILDER__FILE__ ) ) . '/languages' |
| 207 | ); |
| 208 | } |
| 209 | |
| 210 | /** |
| 211 | * Returns url to file or dir inside plugin folder |
| 212 | * |
| 213 | * @param string $path Path inside plugin dir. |
| 214 | * |
| 215 | * @return string |
| 216 | */ |
| 217 | public function plugin_url( string $path = '' ): string { |
| 218 | $path = str_replace( '{min}', Tools::get_suffix(), $path ); |
| 219 | |
| 220 | return JET_FORM_BUILDER_URL . $path; |
| 221 | } |
| 222 | |
| 223 | public function plugin_dir( string $path = '' ): string { |
| 224 | return JET_FORM_BUILDER_PATH . $path; |
| 225 | } |
| 226 | |
| 227 | /** |
| 228 | * Returns plugin version |
| 229 | */ |
| 230 | public function get_version(): string { |
| 231 | return JET_FORM_BUILDER_VERSION; |
| 232 | } |
| 233 | |
| 234 | /** |
| 235 | * Plugin constructor. |
| 236 | */ |
| 237 | private function __construct() { |
| 238 | |
| 239 | $this->register_autoloader(); |
| 240 | $this->init_lang(); |
| 241 | |
| 242 | add_action( |
| 243 | 'after_setup_theme', |
| 244 | function () { |
| 245 | do_action( 'jet-form-builder/before-init' ); |
| 246 | |
| 247 | $this->init_components(); |
| 248 | |
| 249 | do_action( 'jet-form-builder/after-init' ); |
| 250 | }, |
| 251 | 0 |
| 252 | ); |
| 253 | |
| 254 | $this->init_framework(); |
| 255 | Wp_Cli_Manager::register(); |
| 256 | } |
| 257 | |
| 258 | } |
| 259 | |
| 260 | Plugin::instance(); |
| 261 |