jet-appointment.php
94 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace JFB_Compatibility\Jet_Appointment; |
| 5 | |
| 6 | use JFB_Components\Compatibility\Base_Compat_Dir_Trait; |
| 7 | use JFB_Components\Compatibility\Base_Compat_Handle_Trait; |
| 8 | use JFB_Components\Compatibility\Base_Compat_Url_Trait; |
| 9 | use JFB_Components\Module\Base_Module_Dir_It; |
| 10 | use JFB_Components\Module\Base_Module_It; |
| 11 | use JFB_Components\Module\Base_Module_Handle_It; |
| 12 | use JFB_Components\Module\Base_Module_Url_It; |
| 13 | use Jet_Form_Builder\Blocks\Module; |
| 14 | |
| 15 | // If this file is called directly, abort. |
| 16 | if ( ! defined( 'WPINC' ) ) { |
| 17 | die; |
| 18 | } |
| 19 | |
| 20 | class Jet_Appointment implements |
| 21 | Base_Module_It, |
| 22 | Base_Module_Handle_It, |
| 23 | Base_Module_Url_It, |
| 24 | Base_Module_Dir_It { |
| 25 | |
| 26 | use Base_Compat_Handle_Trait; |
| 27 | use Base_Compat_Url_Trait; |
| 28 | use Base_Compat_Dir_Trait; |
| 29 | |
| 30 | public function rep_item_id() { |
| 31 | return 'jet-appointment'; |
| 32 | } |
| 33 | |
| 34 | public function condition(): bool { |
| 35 | return function_exists( 'jet_apb' ); |
| 36 | } |
| 37 | |
| 38 | public function init_hooks() { |
| 39 | add_action( |
| 40 | 'wp_enqueue_scripts', |
| 41 | array( $this, 'register_scripts' ) |
| 42 | ); |
| 43 | |
| 44 | add_filter( |
| 45 | 'render_block_jet-forms/appointment-date', |
| 46 | array( $this, 'add_compatibility_script' ), |
| 47 | 10, |
| 48 | 3 |
| 49 | ); |
| 50 | } |
| 51 | |
| 52 | public function remove_hooks() { |
| 53 | remove_action( |
| 54 | 'wp_enqueue_scripts', |
| 55 | array( $this, 'register_scripts' ) |
| 56 | ); |
| 57 | |
| 58 | remove_filter( |
| 59 | 'render_block_jet-forms/appointment-date', |
| 60 | array( $this, 'add_compatibility_script' ) |
| 61 | ); |
| 62 | } |
| 63 | |
| 64 | public function register_scripts() { |
| 65 | $script_asset = require_once $this->get_dir( 'assets/build/frontend.asset.php' ); |
| 66 | |
| 67 | if ( true === $script_asset ) { |
| 68 | return; |
| 69 | } |
| 70 | |
| 71 | array_push( |
| 72 | $script_asset['dependencies'], |
| 73 | Module::MAIN_SCRIPT_HANDLE, |
| 74 | Module::LISTING_OPTIONS_HANDLE |
| 75 | ); |
| 76 | |
| 77 | wp_register_script( |
| 78 | $this->get_handle(), |
| 79 | $this->get_url( 'assets/build/frontend.js' ), |
| 80 | $script_asset['dependencies'], |
| 81 | $script_asset['version'], |
| 82 | true |
| 83 | ); |
| 84 | } |
| 85 | |
| 86 | // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed |
| 87 | public function add_compatibility_script( string $markup, array $parsed, $block ): string { |
| 88 | wp_enqueue_script( $this->get_handle() ); |
| 89 | |
| 90 | return $markup; |
| 91 | } |
| 92 | |
| 93 | } |
| 94 |