bricks.php
65 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_Handle_It; |
| 13 | use JFB_Components\Module\Base_Module_It; |
| 14 | use JFB_Components\Module\Base_Module_Url_It; |
| 15 | use JFB_Components\Module\Base_Module_Dir_It; |
| 16 | |
| 17 | // If this file is called directly, abort. |
| 18 | if ( ! defined( 'WPINC' ) ) { |
| 19 | die; |
| 20 | } |
| 21 | |
| 22 | class Bricks implements Base_Module_It, Base_Module_Handle_It, Base_Module_Url_It, Base_Module_Dir_It { |
| 23 | |
| 24 | use Base_Compat_Handle_Trait; |
| 25 | use Base_Compat_Url_Trait; |
| 26 | use Base_Compat_Dir_Trait; |
| 27 | |
| 28 | public function rep_item_id() { |
| 29 | return 'bricks'; |
| 30 | } |
| 31 | |
| 32 | public function condition(): bool { |
| 33 | return defined( 'BRICKS_VERSION' ); |
| 34 | } |
| 35 | |
| 36 | public function init_hooks() { |
| 37 | add_action( 'init', array( $this, 'register_elements' ), 10 ); |
| 38 | add_action( 'wp_enqueue_scripts', array( $this, 'editor_styles' ) ); |
| 39 | } |
| 40 | |
| 41 | public function remove_hooks() { |
| 42 | remove_action( 'init', array( $this, 'register_elements' ) ); |
| 43 | remove_action( 'wp_enqueue_scripts', array( $this, 'editor_styles' ) ); |
| 44 | } |
| 45 | |
| 46 | public function register_elements() { |
| 47 | $file_path = $this->get_dir( 'widgets/form.php' ); |
| 48 | Elements::register_element( $file_path, '', 'JFB_Compatibility\Bricks\Widgets\Form' ); |
| 49 | |
| 50 | do_action( 'jet-form-builder/bricks/register-elements' ); |
| 51 | } |
| 52 | |
| 53 | public function editor_styles() { |
| 54 | // Enqueue your files on the canvas & frontend, not the builder panel. Otherwise custom CSS might affect builder) |
| 55 | if ( Tools::is_editor() ) { |
| 56 | wp_enqueue_style( |
| 57 | $this->get_handle( 'icons' ), |
| 58 | $this->get_url( 'assets/build/css/editor/icons.css' ), |
| 59 | array(), |
| 60 | Plugin::instance()->get_version() |
| 61 | ); |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 |