module.php
102 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace JFB_Modules\Onboarding; |
| 5 | |
| 6 | use Jet_Form_Builder\Blocks\Block_Helper; |
| 7 | use JFB_Components\Module\Base_Module_Dir_It; |
| 8 | use JFB_Components\Module\Base_Module_Dir_Trait; |
| 9 | use JFB_Components\Module\Base_Module_Handle_It; |
| 10 | use JFB_Components\Module\Base_Module_Handle_Trait; |
| 11 | use JFB_Components\Module\Base_Module_It; |
| 12 | use JFB_Components\Module\Base_Module_Url_It; |
| 13 | use JFB_Components\Module\Base_Module_Url_Trait; |
| 14 | |
| 15 | // If this file is called directly, abort. |
| 16 | if ( ! defined( 'WPINC' ) ) { |
| 17 | die; |
| 18 | } |
| 19 | |
| 20 | class Module implements Base_Module_It, Base_Module_Url_It, Base_Module_Dir_It, Base_Module_Handle_It { |
| 21 | |
| 22 | use Base_Module_Handle_Trait; |
| 23 | use Base_Module_Url_Trait; |
| 24 | use Base_Module_Dir_Trait; |
| 25 | |
| 26 | public function rep_item_id() { |
| 27 | return 'onboarding'; |
| 28 | } |
| 29 | |
| 30 | public function condition(): bool { |
| 31 | return true; |
| 32 | } |
| 33 | |
| 34 | public function init_hooks() { |
| 35 | add_action( |
| 36 | 'jet-form-builder/editor-assets/before', |
| 37 | array( $this, 'editor_assets_before' ), |
| 38 | 20 |
| 39 | ); |
| 40 | add_action( |
| 41 | 'jet-form-builder/editor-assets/before', |
| 42 | array( $this, 'editor_assets_package_before' ), |
| 43 | 0 |
| 44 | ); |
| 45 | add_filter( |
| 46 | 'jet-form-builder/post-type/args', |
| 47 | array( $this, 'add_default_fields_to_form' ), |
| 48 | 99 |
| 49 | ); |
| 50 | } |
| 51 | |
| 52 | public function remove_hooks() { |
| 53 | remove_action( |
| 54 | 'jet-form-builder/editor-assets/before', |
| 55 | array( $this, 'editor_assets_before' ) |
| 56 | ); |
| 57 | remove_action( |
| 58 | 'jet-form-builder/editor-package/before', |
| 59 | array( $this, 'editor_assets_package_before' ) |
| 60 | ); |
| 61 | remove_filter( |
| 62 | 'jet-form-builder/post-type/args', |
| 63 | array( $this, 'add_default_fields_to_form' ), |
| 64 | 99 |
| 65 | ); |
| 66 | } |
| 67 | |
| 68 | public function editor_assets_before() { |
| 69 | wp_enqueue_script( |
| 70 | $this->get_handle(), |
| 71 | $this->get_url( 'assets/build/editor.js' ), |
| 72 | array(), |
| 73 | jet_form_builder()->get_version(), |
| 74 | true |
| 75 | ); |
| 76 | } |
| 77 | |
| 78 | public function editor_assets_package_before() { |
| 79 | wp_enqueue_script( |
| 80 | $this->get_handle( 'package' ), |
| 81 | $this->get_url( 'assets/build/editor.package.js' ), |
| 82 | array(), |
| 83 | jet_form_builder()->get_version(), |
| 84 | true |
| 85 | ); |
| 86 | wp_enqueue_style( |
| 87 | $this->get_handle( 'package' ), |
| 88 | $this->get_url( 'assets/build/editor.css' ), |
| 89 | array(), |
| 90 | jet_form_builder()->get_version() |
| 91 | ); |
| 92 | } |
| 93 | |
| 94 | public function add_default_fields_to_form( $arguments ) { |
| 95 | $arguments['template'] = array( |
| 96 | array( Block_Helper::pref( 'welcome' ) ), |
| 97 | ); |
| 98 | |
| 99 | return $arguments; |
| 100 | } |
| 101 | } |
| 102 |