actions
2 years ago
admin
2 years ago
api
2 years ago
assets
2 years ago
methods
2 years ago
rest-api
2 years ago
module.php
2 years ago
module.php
122 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace JFB_Modules\Active_Campaign; |
| 5 | |
| 6 | use Jet_Form_Builder\Actions\Manager; |
| 7 | use Jet_Form_Builder\Admin\Tabs_Handlers\Tab_Handler_Manager; |
| 8 | use JFB_Components\Module\Base_Module_Dir_It; |
| 9 | use JFB_Components\Module\Base_Module_Dir_Trait; |
| 10 | use JFB_Components\Rest_Api\Rest_Api_Controller_Base; |
| 11 | use JFB_Modules\Active_Campaign\Actions\Active_Campaign_Action; |
| 12 | use JFB_Modules\Active_Campaign\Rest_Api\Rest_Controller; |
| 13 | use JFB_Components\Module\Base_Module_After_Install_It; |
| 14 | use JFB_Components\Module\Base_Module_Handle_It; |
| 15 | use JFB_Components\Module\Base_Module_Handle_Trait; |
| 16 | use JFB_Components\Module\Base_Module_It; |
| 17 | use JFB_Components\Module\Base_Module_Url_It; |
| 18 | use JFB_Components\Module\Base_Module_Url_Trait; |
| 19 | use JFB_Modules\Active_Campaign\Admin\Tabs; |
| 20 | |
| 21 | // If this file is called directly, abort. |
| 22 | if ( ! defined( 'WPINC' ) ) { |
| 23 | die; |
| 24 | } |
| 25 | |
| 26 | final class Module implements |
| 27 | Base_Module_It, |
| 28 | Base_Module_After_Install_It, |
| 29 | Base_Module_Url_It, |
| 30 | Base_Module_Handle_It, |
| 31 | Base_Module_Dir_It { |
| 32 | |
| 33 | use Base_Module_Url_Trait; |
| 34 | use Base_Module_Handle_Trait; |
| 35 | use Base_Module_Dir_Trait; |
| 36 | |
| 37 | private $rest; |
| 38 | |
| 39 | public function rep_item_id() { |
| 40 | return 'active-campaign'; |
| 41 | } |
| 42 | |
| 43 | public function condition(): bool { |
| 44 | return true; |
| 45 | } |
| 46 | |
| 47 | public function on_install() { |
| 48 | $this->rest = new Rest_Controller(); |
| 49 | |
| 50 | // install tab handler for Settings page |
| 51 | Tab_Handler_Manager::instance()->install( new Tabs\Active_Campaign_Handler() ); |
| 52 | } |
| 53 | |
| 54 | public function on_uninstall() { |
| 55 | unset( $this->rest ); |
| 56 | // remove tab handler from Settings page |
| 57 | Tab_Handler_Manager::instance()->uninstall( 'active-campaign-tab' ); |
| 58 | } |
| 59 | |
| 60 | public function init_hooks() { |
| 61 | add_action( 'rest_api_init', array( $this->get_rest(), 'register_routes' ) ); |
| 62 | add_action( 'jet-form-builder/actions/register', array( $this, 'add_action' ) ); |
| 63 | add_action( |
| 64 | 'jet-form-builder/editor-assets/before', |
| 65 | array( $this, 'editor_assets' ), |
| 66 | 0 |
| 67 | ); |
| 68 | add_action( |
| 69 | 'jet-fb/admin-pages/before-assets/jfb-settings', |
| 70 | array( $this, 'admin_settings_assets' ), |
| 71 | 0 |
| 72 | ); |
| 73 | } |
| 74 | |
| 75 | public function remove_hooks() { |
| 76 | remove_action( 'rest_api_init', array( $this->get_rest(), 'register_routes' ) ); |
| 77 | remove_action( 'jet-form-builder/actions/register', array( $this, 'add_action' ) ); |
| 78 | remove_action( |
| 79 | 'jet-form-builder/editor-assets/before', |
| 80 | array( $this, 'editor_assets' ), |
| 81 | 0 |
| 82 | ); |
| 83 | remove_action( |
| 84 | 'jet-fb/admin-pages/before-assets/jfb-settings', |
| 85 | array( $this, 'admin_settings_assets' ), |
| 86 | 0 |
| 87 | ); |
| 88 | } |
| 89 | |
| 90 | public function add_action( Manager $manager ) { |
| 91 | $manager->register_action_type( new Active_Campaign_Action() ); |
| 92 | } |
| 93 | |
| 94 | public function editor_assets() { |
| 95 | $script_asset = require_once $this->get_dir( 'assets/build/editor.asset.php' ); |
| 96 | |
| 97 | wp_enqueue_script( |
| 98 | $this->get_handle(), |
| 99 | $this->get_url( 'assets/build/editor.js' ), |
| 100 | $script_asset['dependencies'], |
| 101 | $script_asset['version'], |
| 102 | true |
| 103 | ); |
| 104 | } |
| 105 | |
| 106 | public function admin_settings_assets() { |
| 107 | $script_asset = require_once $this->get_dir( 'assets/build/admin/jfb-settings.asset.php' ); |
| 108 | |
| 109 | wp_enqueue_script( |
| 110 | $this->get_handle(), |
| 111 | $this->get_url( 'assets/build/admin/jfb-settings.js' ), |
| 112 | $script_asset['dependencies'], |
| 113 | $script_asset['version'], |
| 114 | true |
| 115 | ); |
| 116 | } |
| 117 | |
| 118 | public function get_rest(): Rest_Api_Controller_Base { |
| 119 | return $this->rest; |
| 120 | } |
| 121 | } |
| 122 |