module.php
98 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace JFB_Modules\Html_Parser; |
| 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_Handle_It, |
| 22 | Base_Module_Url_It, |
| 23 | Base_Module_Dir_It { |
| 24 | |
| 25 | use Base_Module_Url_Trait; |
| 26 | use Base_Module_Handle_Trait; |
| 27 | use Base_Module_Dir_Trait; |
| 28 | |
| 29 | public function rep_item_id() { |
| 30 | return 'html-parser'; |
| 31 | } |
| 32 | |
| 33 | public function condition(): bool { |
| 34 | return true; |
| 35 | } |
| 36 | |
| 37 | public function init_hooks() { |
| 38 | } |
| 39 | |
| 40 | public function remove_hooks() { |
| 41 | } |
| 42 | |
| 43 | public function register_scripts() { |
| 44 | $script_asset = require_once $this->get_dir( 'assets/build/parser.asset.php' ); |
| 45 | |
| 46 | // script have already registered |
| 47 | if ( true === $script_asset ) { |
| 48 | return; |
| 49 | } |
| 50 | |
| 51 | /** @var \JFB_Modules\Jet_Plugins\Module $jet_plugins */ |
| 52 | /** @noinspection PhpUnhandledExceptionInspection */ |
| 53 | $jet_plugins = jet_form_builder()->module( 'jet-plugins' ); |
| 54 | $jet_plugins->register_scripts(); |
| 55 | |
| 56 | array_push( |
| 57 | $script_asset['dependencies'], |
| 58 | $jet_plugins::HANDLE |
| 59 | ); |
| 60 | |
| 61 | wp_register_script( |
| 62 | $this->get_handle(), |
| 63 | $this->get_url( 'assets/build/parser.js' ), |
| 64 | $script_asset['dependencies'], |
| 65 | $script_asset['version'], |
| 66 | true |
| 67 | ); |
| 68 | |
| 69 | wp_localize_script( |
| 70 | $this->get_handle(), |
| 71 | 'JetFormBuilderParserConfig', |
| 72 | array( |
| 73 | 'mimes' => get_allowed_mime_types(), |
| 74 | ) |
| 75 | ); |
| 76 | |
| 77 | $ui_asset = require $this->get_dir( 'assets/build/admin-ui.asset.php' ); |
| 78 | wp_register_script( |
| 79 | 'jfb-html-parser-admin-ui', |
| 80 | $this->get_url( 'assets/build/admin-ui.js' ), |
| 81 | $ui_asset['dependencies'], |
| 82 | $ui_asset['version'], |
| 83 | true |
| 84 | ); |
| 85 | |
| 86 | if ( |
| 87 | is_admin() |
| 88 | && isset( $_GET['post_type'] ) |
| 89 | && 'jet-form-builder' === $_GET['post_type'] |
| 90 | && isset( $_SERVER['REQUEST_URI'] ) |
| 91 | && false !== strpos( $_SERVER['REQUEST_URI'], 'edit.php' ) // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
| 92 | ) { |
| 93 | wp_enqueue_script( $this->get_handle() ); |
| 94 | wp_enqueue_script( 'jfb-html-parser-admin-ui' ); |
| 95 | } |
| 96 | } |
| 97 | } |
| 98 |