| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
namespace JFB_Modules\Wysiwyg; |
| 5 |
|
| 6 |
use Jet_Form_Builder\Blocks\Module as BlocksModule; |
| 7 |
use Jet_Form_Builder\Plugin; |
| 8 |
use JFB_Components\Module\Base_Module_Dir_It; |
| 9 |
use JFB_Components\Module\Base_Module_Dir_Trait; |
| 10 |
use JFB_Components\Module\Base_Module_Handle_It; |
| 11 |
use JFB_Components\Module\Base_Module_Handle_Trait; |
| 12 |
use JFB_Components\Module\Base_Module_It; |
| 13 |
use JFB_Components\Module\Base_Module_Url_It; |
| 14 |
use JFB_Components\Module\Base_Module_Url_Trait; |
| 15 |
|
| 16 |
// If this file is called directly, abort. |
| 17 |
if ( ! defined( 'WPINC' ) ) { |
| 18 |
die; |
| 19 |
} |
| 20 |
|
| 21 |
final class Module implements |
| 22 |
Base_Module_It, |
| 23 |
Base_Module_Url_It, |
| 24 |
Base_Module_Handle_It, |
| 25 |
Base_Module_Dir_It { |
| 26 |
|
| 27 |
use Base_Module_Url_Trait; |
| 28 |
use Base_Module_Dir_Trait; |
| 29 |
use Base_Module_Handle_Trait; |
| 30 |
|
| 31 |
public function rep_item_id() { |
| 32 |
return 'wysiwyg'; |
| 33 |
} |
| 34 |
|
| 35 |
public function condition(): bool { |
| 36 |
return true; |
| 37 |
} |
| 38 |
|
| 39 |
public function init_hooks() { |
| 40 |
add_filter( 'jet-form-builder/blocks/items', array( $this, 'add_blocks_types' ) ); |
| 41 |
add_action( 'init', array( $this, 'register_editor_styles' ) ); |
| 42 |
add_action( 'jet-form-builder/editor-assets/before', array( $this, 'enqueue_admin_assets' ) ); |
| 43 |
add_action( 'wp_enqueue_scripts', array( $this, 'register_frontend_scripts' ) ); |
| 44 |
add_action( 'jet_plugins/frontend/register_scripts', array( $this, 'register_frontend_scripts' ) ); |
| 45 |
} |
| 46 |
|
| 47 |
public function remove_hooks() { |
| 48 |
remove_filter( 'jet-form-builder/blocks/items', array( $this, 'add_blocks_types' ) ); |
| 49 |
remove_action( 'init', array( $this, 'register_editor_styles' ) ); |
| 50 |
remove_action( 'jet-form-builder/editor-assets/before', array( $this, 'enqueue_admin_assets' ) ); |
| 51 |
remove_action( 'wp_enqueue_scripts', array( $this, 'register_frontend_scripts' ) ); |
| 52 |
remove_action( 'jet_plugins/frontend/register_scripts', array( $this, 'register_frontend_scripts' ) ); |
| 53 |
} |
| 54 |
|
| 55 |
public function add_blocks_types( array $block_types ): array { |
| 56 |
$block_types[] = new Blocks\Wysiwyg\Block_Type(); |
| 57 |
|
| 58 |
return $block_types; |
| 59 |
} |
| 60 |
|
| 61 |
public function register_editor_styles() { |
| 62 |
|
| 63 |
$editor_asset = require $this->get_dir( 'assets/build/editor.asset.php' ); |
| 64 |
wp_register_style( |
| 65 |
$this->get_handle( 'lightgray-skin' ), |
| 66 |
includes_url( 'js/tinymce/skins/lightgray/skin.min.css' ), |
| 67 |
array(), |
| 68 |
$editor_asset['version'] |
| 69 |
); |
| 70 |
wp_register_style( |
| 71 |
$this->get_handle(), |
| 72 |
$this->get_url( 'assets/build/wysiwyg.css' ), |
| 73 |
array( |
| 74 |
'editor-buttons', |
| 75 |
), |
| 76 |
$editor_asset['version'] |
| 77 |
); |
| 78 |
} |
| 79 |
|
| 80 |
public function enqueue_admin_assets() { |
| 81 |
$script_asset = require $this->get_dir( 'assets/build/editor.asset.php' ); |
| 82 |
|
| 83 |
wp_enqueue_script( |
| 84 |
$this->get_handle(), |
| 85 |
$this->get_url( 'assets/build/editor.js' ), |
| 86 |
$script_asset['dependencies'], |
| 87 |
$script_asset['version'], |
| 88 |
true |
| 89 |
); |
| 90 |
} |
| 91 |
|
| 92 |
public function register_frontend_scripts() { |
| 93 |
$script_asset = require $this->get_dir( 'assets/build/wysiwyg.asset.php' ); |
| 94 |
|
| 95 |
if ( true === $script_asset ) { |
| 96 |
return; |
| 97 |
} |
| 98 |
|
| 99 |
array_push( |
| 100 |
$script_asset['dependencies'], |
| 101 |
BlocksModule::MAIN_SCRIPT_HANDLE |
| 102 |
); |
| 103 |
|
| 104 |
wp_register_script( |
| 105 |
$this->get_handle(), |
| 106 |
$this->get_url( 'assets/build/wysiwyg.js' ), |
| 107 |
$script_asset['dependencies'], |
| 108 |
$script_asset['version'], |
| 109 |
true |
| 110 |
); |
| 111 |
wp_register_style( |
| 112 |
$this->get_handle(), |
| 113 |
$this->get_url( 'assets/build/wysiwyg.css' ), |
| 114 |
array(), |
| 115 |
$script_asset['version'] |
| 116 |
); |
| 117 |
} |
| 118 |
} |
| 119 |
|