module.php
81 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace JFB_Modules\Data; |
| 5 | |
| 6 | use JFB_Components\Module\Base_Module_Dir_It; |
| 7 | use JFB_Components\Module\Base_Module_Dir_Trait; |
| 8 | use JFB_Components\Module\Base_Module_Handle_It; |
| 9 | use JFB_Components\Module\Base_Module_Handle_Trait; |
| 10 | use JFB_Components\Module\Base_Module_It; |
| 11 | use JFB_Components\Module\Base_Module_Url_It; |
| 12 | use JFB_Components\Module\Base_Module_Url_Trait; |
| 13 | |
| 14 | class Module implements |
| 15 | Base_Module_It, |
| 16 | Base_Module_Url_It, |
| 17 | Base_Module_Dir_It, |
| 18 | Base_Module_Handle_It { |
| 19 | |
| 20 | use Base_Module_Handle_Trait; |
| 21 | use Base_Module_Url_Trait; |
| 22 | use Base_Module_Dir_Trait; |
| 23 | |
| 24 | public function rep_item_id() { |
| 25 | return 'data'; |
| 26 | } |
| 27 | |
| 28 | public function condition(): bool { |
| 29 | return true; |
| 30 | } |
| 31 | |
| 32 | public function init_hooks() { |
| 33 | add_action( |
| 34 | 'enqueue_block_editor_assets', |
| 35 | array( $this, 'register_assets' ), |
| 36 | -10 |
| 37 | ); |
| 38 | add_action( |
| 39 | 'wp_enqueue_scripts', |
| 40 | array( $this, 'register_assets' ), |
| 41 | -10 |
| 42 | ); |
| 43 | } |
| 44 | |
| 45 | public function remove_hooks() { |
| 46 | remove_action( |
| 47 | 'enqueue_block_editor_assets', |
| 48 | array( $this, 'register_assets' ), |
| 49 | -10 |
| 50 | ); |
| 51 | remove_action( |
| 52 | 'wp_enqueue_scripts', |
| 53 | array( $this, 'register_assets' ), |
| 54 | -10 |
| 55 | ); |
| 56 | } |
| 57 | |
| 58 | public function register_assets() { |
| 59 | $script_asset = require_once $this->get_dir( 'assets/build/index.asset.php' ); |
| 60 | |
| 61 | if ( true === $script_asset ) { |
| 62 | return; |
| 63 | } |
| 64 | |
| 65 | wp_register_style( |
| 66 | $this->get_handle(), |
| 67 | $this->get_url( 'assets/build/index.css' ), |
| 68 | array(), |
| 69 | $script_asset['version'] |
| 70 | ); |
| 71 | |
| 72 | wp_register_script( |
| 73 | $this->get_handle(), |
| 74 | $this->get_url( 'assets/build/index.js' ), |
| 75 | $script_asset['dependencies'], |
| 76 | $script_asset['version'], |
| 77 | true |
| 78 | ); |
| 79 | } |
| 80 | } |
| 81 |