bricks.php
92 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace JFB_Compatibility\Bricks; |
| 5 | |
| 6 | use Bricks\Elements; |
| 7 | use Jet_Form_Builder\Plugin; |
| 8 | use Jet_Form_Builder\Classes\Tools; |
| 9 | use JFB_Components\Compatibility\Base_Compat_Handle_Trait; |
| 10 | use JFB_Components\Compatibility\Base_Compat_Url_Trait; |
| 11 | use JFB_Components\Compatibility\Base_Compat_Dir_Trait; |
| 12 | use JFB_Components\Module\Base_Module_After_Install_It; |
| 13 | use JFB_Components\Module\Base_Module_Handle_It; |
| 14 | use JFB_Components\Module\Base_Module_It; |
| 15 | use JFB_Components\Module\Base_Module_Url_It; |
| 16 | use JFB_Components\Module\Base_Module_Dir_It; |
| 17 | |
| 18 | // If this file is called directly, abort. |
| 19 | if ( ! defined( 'WPINC' ) ) { |
| 20 | die; |
| 21 | } |
| 22 | |
| 23 | class Bricks implements |
| 24 | Base_Module_It, |
| 25 | Base_Module_Handle_It, |
| 26 | Base_Module_Url_It, |
| 27 | Base_Module_Dir_It, |
| 28 | Base_Module_After_Install_It { |
| 29 | |
| 30 | use Base_Compat_Handle_Trait; |
| 31 | use Base_Compat_Url_Trait; |
| 32 | use Base_Compat_Dir_Trait; |
| 33 | |
| 34 | /** |
| 35 | * @var Onboarding_Builder |
| 36 | */ |
| 37 | private $onboarding_builder; |
| 38 | |
| 39 | public function rep_item_id() { |
| 40 | return 'bricks'; |
| 41 | } |
| 42 | |
| 43 | public function condition(): bool { |
| 44 | return defined( 'BRICKS_VERSION' ); |
| 45 | } |
| 46 | |
| 47 | public function on_install() { |
| 48 | $this->onboarding_builder = new Onboarding_Builder(); |
| 49 | } |
| 50 | |
| 51 | public function on_uninstall() { |
| 52 | } |
| 53 | |
| 54 | public function init_hooks() { |
| 55 | add_action( 'init', array( $this, 'register_elements' ), 10 ); |
| 56 | add_action( 'wp_enqueue_scripts', array( $this, 'editor_styles' ) ); |
| 57 | |
| 58 | $this->get_onboarding_builder()->init_hooks(); |
| 59 | } |
| 60 | |
| 61 | public function remove_hooks() { |
| 62 | remove_action( 'init', array( $this, 'register_elements' ) ); |
| 63 | remove_action( 'wp_enqueue_scripts', array( $this, 'editor_styles' ) ); |
| 64 | } |
| 65 | |
| 66 | public function register_elements() { |
| 67 | $file_path = $this->get_dir( 'widgets/form.php' ); |
| 68 | Elements::register_element( $file_path, '', 'JFB_Compatibility\Bricks\Widgets\Form' ); |
| 69 | |
| 70 | do_action( 'jet-form-builder/bricks/register-elements' ); |
| 71 | } |
| 72 | |
| 73 | public function editor_styles() { |
| 74 | // Enqueue your files on the canvas & frontend, not the builder panel. Otherwise custom CSS might affect builder) |
| 75 | if ( Tools::is_editor() ) { |
| 76 | wp_enqueue_style( |
| 77 | $this->get_handle( 'icons' ), |
| 78 | $this->get_url( 'assets/build/editor/icons.css' ), |
| 79 | array(), |
| 80 | Plugin::instance()->get_version() |
| 81 | ); |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * @return Onboarding_Builder |
| 87 | */ |
| 88 | public function get_onboarding_builder(): Onboarding_Builder { |
| 89 | return $this->onboarding_builder; |
| 90 | } |
| 91 | } |
| 92 |