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