| 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\Pages\Settings_Page; |
| 9 |
use Jet_Form_Builder\Admin\Pages\Addons_Page; |
| 10 |
use Jet_Form_Builder\Admin\Tabs_Handlers\Tab_Handler_Manager; |
| 11 |
use Jet_Form_Builder\Blocks\Manager as BlocksManager; |
| 12 |
use Jet_Form_Builder\Form_Actions\Form_Actions_Manager; |
| 13 |
use Jet_Form_Builder\Framework\CX_Loader; |
| 14 |
use Jet_Form_Builder\Integrations\Forms_Captcha; |
| 15 |
use Jet_Form_Builder\Widgets\Elementor_Controller; |
| 16 |
use Jet_Form_Builder\License\Manager as LicenseManager; |
| 17 |
|
| 18 |
if ( ! defined( 'WPINC' ) ) { |
| 19 |
die; |
| 20 |
} |
| 21 |
|
| 22 |
/** |
| 23 |
* @property Post_Type $post_type |
| 24 |
* @property BlocksManager $blocks |
| 25 |
* @property ActionsManager $actions |
| 26 |
* @property Form_Manager $form |
| 27 |
* @property Form_Handler $form_handler |
| 28 |
* @property Forms_Captcha $captcha |
| 29 |
* @property Admin\Editor $editor |
| 30 |
* @property LicenseManager $license_manager |
| 31 |
* @property \Jet_Admin_Bar $admin_bar |
| 32 |
* Class Plugin |
| 33 |
* @package Jet_Form_Builder |
| 34 |
*/ |
| 35 |
class Plugin { |
| 36 |
|
| 37 |
public $post_type; |
| 38 |
public $blocks; |
| 39 |
public $actions; |
| 40 |
public $form; |
| 41 |
public $form_handler; |
| 42 |
public $editor; |
| 43 |
public $captcha; |
| 44 |
public $dev_manager; |
| 45 |
|
| 46 |
public $is_activated_jet_sm; |
| 47 |
public $allow_gateways; |
| 48 |
public $framework; |
| 49 |
public $license_manager; |
| 50 |
public $admin_bar; |
| 51 |
|
| 52 |
public static $instance; |
| 53 |
|
| 54 |
/** |
| 55 |
* Instance. |
| 56 |
* |
| 57 |
* Ensures only one instance of the plugin class is loaded or can be loaded. |
| 58 |
* |
| 59 |
* @since 1.0.0 |
| 60 |
* @access public |
| 61 |
* @static |
| 62 |
*/ |
| 63 |
public static function instance() { |
| 64 |
|
| 65 |
if ( is_null( self::$instance ) ) { |
| 66 |
self::$instance = new self(); |
| 67 |
} |
| 68 |
|
| 69 |
return self::$instance; |
| 70 |
} |
| 71 |
|
| 72 |
public static function clear() { |
| 73 |
self::$instance = null; |
| 74 |
} |
| 75 |
|
| 76 |
/** |
| 77 |
* Register autoloader. |
| 78 |
*/ |
| 79 |
private function register_autoloader() { |
| 80 |
require JET_FORM_BUILDER_PATH . 'includes' . DIRECTORY_SEPARATOR . 'autoloader.php'; |
| 81 |
Autoloader::run(); |
| 82 |
} |
| 83 |
|
| 84 |
/** |
| 85 |
* Initialize plugin parts |
| 86 |
* |
| 87 |
* @return void |
| 88 |
*/ |
| 89 |
public function init_components() { |
| 90 |
$this->allow_gateways = apply_filters( 'jet-form-builder/allow-gateways', false ); |
| 91 |
$this->maybe_enable_gateways(); |
| 92 |
|
| 93 |
$this->admin_bar = \Jet_Admin_Bar::get_instance(); |
| 94 |
$this->post_type = new Post_Type(); |
| 95 |
$this->blocks = new Blocks\Manager(); |
| 96 |
$this->actions = new Actions\Manager(); |
| 97 |
$this->form = new Form_Manager(); |
| 98 |
$this->form_handler = new Form_Handler(); |
| 99 |
$this->captcha = new Forms_Captcha(); |
| 100 |
$this->license_manager = new LicenseManager(); |
| 101 |
|
| 102 |
Dev_Mode\Manager::instance(); |
| 103 |
File_Upload::instance(); |
| 104 |
new Elementor_Controller(); |
| 105 |
|
| 106 |
if ( is_admin() ) { |
| 107 |
$this->editor = new Admin\Editor(); |
| 108 |
new Form_Actions_Manager(); |
| 109 |
new Pages_Manager( array( |
| 110 |
new Settings_Page(), |
| 111 |
new Addons_Page() |
| 112 |
) ); |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
public function init_framework() { |
| 117 |
require $this->plugin_dir( 'framework/loader.php' ); |
| 118 |
|
| 119 |
$this->framework = new CX_Loader( array( |
| 120 |
$this->plugin_dir( 'framework/vue-ui/cherry-x-vue-ui.php' ), |
| 121 |
$this->plugin_dir( 'framework/admin-bar/jet-admin-bar.php' ), |
| 122 |
) ); |
| 123 |
} |
| 124 |
|
| 125 |
public function maybe_enable_gateways() { |
| 126 |
Tab_Handler_Manager::instance()->tab( 'payments-gateways' )->save_global_options(); |
| 127 |
$gateways = Tab_Handler_Manager::instance()->tab( 'payments-gateways' )->get_global_options(); |
| 128 |
|
| 129 |
if ( isset( $gateways['enable_test_mode'] ) ) { |
| 130 |
add_filter( 'jet-form-builder/gateways/paypal/sandbox-mode', function () use ( $gateways ) { |
| 131 |
return $gateways['enable_test_mode']; |
| 132 |
} ); |
| 133 |
} |
| 134 |
|
| 135 |
if ( isset( $gateways['use_gateways'] ) ) { |
| 136 |
$this->allow_gateways = $gateways['use_gateways']; |
| 137 |
} |
| 138 |
} |
| 139 |
|
| 140 |
|
| 141 |
/** |
| 142 |
* Returns url to file or dir inside plugin folder |
| 143 |
* |
| 144 |
* @param string $path Path inside plugin dir. |
| 145 |
* |
| 146 |
* @return string |
| 147 |
*/ |
| 148 |
public function plugin_url( $path = null ) { |
| 149 |
return JET_FORM_BUILDER_URL . $path; |
| 150 |
} |
| 151 |
|
| 152 |
public function plugin_dir( $path = '' ) { |
| 153 |
return JET_FORM_BUILDER_PATH . $path; |
| 154 |
} |
| 155 |
|
| 156 |
/** |
| 157 |
* Returns plugin version |
| 158 |
*/ |
| 159 |
public function get_version() { |
| 160 |
return JET_FORM_BUILDER_VERSION; |
| 161 |
} |
| 162 |
|
| 163 |
/** |
| 164 |
* Plugin constructor. |
| 165 |
*/ |
| 166 |
private function __construct() { |
| 167 |
|
| 168 |
$this->register_autoloader(); |
| 169 |
|
| 170 |
add_action( 'after_setup_theme', function () { |
| 171 |
do_action( 'jet-form-builder/before-init' ); |
| 172 |
|
| 173 |
$this->init_components(); |
| 174 |
|
| 175 |
do_action( 'jet-form-builder/after-init' ); |
| 176 |
}, 0 ); |
| 177 |
|
| 178 |
$this->init_framework(); |
| 179 |
} |
| 180 |
|
| 181 |
} |
| 182 |
|
| 183 |
Plugin::instance(); |
| 184 |
|