actions
1 year ago
admin
2 years ago
api
2 years ago
assets
1 year ago
methods
2 years ago
rest-api
1 year ago
module.php
1 year ago
module.php
134 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\Base_Handler; |
| 8 | use Jet_Form_Builder\Admin\Tabs_Handlers\Tab_Handler_Manager; |
| 9 | use JFB_Components\Module\Base_Module_Dir_It; |
| 10 | use JFB_Components\Module\Base_Module_Dir_Trait; |
| 11 | use JFB_Modules\Active_Campaign\Actions\Active_Campaign_Action; |
| 12 | use JFB_Modules\Active_Campaign\Rest_Api\Active_Campaign\Active_Campaign_Route; |
| 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 | public function rep_item_id() { |
| 38 | return 'active-campaign'; |
| 39 | } |
| 40 | |
| 41 | public function condition(): bool { |
| 42 | return true; |
| 43 | } |
| 44 | |
| 45 | public function on_install() { |
| 46 | // install tab handler for Settings page |
| 47 | Tab_Handler_Manager::instance()->install( new Tabs\Active_Campaign_Handler() ); |
| 48 | } |
| 49 | |
| 50 | public function on_uninstall() { |
| 51 | // remove tab handler from Settings page |
| 52 | Tab_Handler_Manager::instance()->uninstall( 'active-campaign-tab' ); |
| 53 | } |
| 54 | |
| 55 | public function init_hooks() { |
| 56 | add_action( 'rest_api_init', array( $this, 'register_routes' ) ); |
| 57 | add_action( 'jet-form-builder/actions/register', array( $this, 'add_action' ) ); |
| 58 | add_action( |
| 59 | 'jet-form-builder/editor-assets/after', |
| 60 | array( $this, 'editor_assets' ) |
| 61 | ); |
| 62 | add_action( |
| 63 | 'jet-fb/admin-pages/before-assets/jfb-settings', |
| 64 | array( $this, 'admin_settings_assets' ), |
| 65 | 0 |
| 66 | ); |
| 67 | } |
| 68 | |
| 69 | public function remove_hooks() { |
| 70 | remove_action( 'rest_api_init', array( $this, 'register_routes' ) ); |
| 71 | remove_action( 'jet-form-builder/actions/register', array( $this, 'add_action' ) ); |
| 72 | remove_action( |
| 73 | 'jet-form-builder/editor-assets/after', |
| 74 | array( $this, 'editor_assets' ) |
| 75 | ); |
| 76 | remove_action( |
| 77 | 'jet-fb/admin-pages/before-assets/jfb-settings', |
| 78 | array( $this, 'admin_settings_assets' ), |
| 79 | 0 |
| 80 | ); |
| 81 | } |
| 82 | |
| 83 | public function add_action( Manager $manager ) { |
| 84 | $manager->register_action_type( new Active_Campaign_Action() ); |
| 85 | } |
| 86 | |
| 87 | public function editor_assets() { |
| 88 | $script_asset = require_once $this->get_dir( 'assets/build/editor.asset.php' ); |
| 89 | |
| 90 | array_push( |
| 91 | $script_asset['dependencies'], |
| 92 | 'jet-fb-components', |
| 93 | 'jet-fb-data', |
| 94 | 'jet-fb-actions-v2', |
| 95 | 'jet-fb-blocks-v2-to-actions-v2' |
| 96 | ); |
| 97 | |
| 98 | wp_enqueue_script( |
| 99 | $this->get_handle(), |
| 100 | $this->get_url( 'assets/build/editor.js' ), |
| 101 | $script_asset['dependencies'], |
| 102 | $script_asset['version'], |
| 103 | true |
| 104 | ); |
| 105 | } |
| 106 | |
| 107 | public function admin_settings_assets() { |
| 108 | $script_asset = require_once $this->get_dir( 'assets/build/admin/jfb-settings.asset.php' ); |
| 109 | |
| 110 | wp_enqueue_script( |
| 111 | $this->get_handle(), |
| 112 | $this->get_url( 'assets/build/admin/jfb-settings.js' ), |
| 113 | $script_asset['dependencies'], |
| 114 | $script_asset['version'], |
| 115 | true |
| 116 | ); |
| 117 | } |
| 118 | |
| 119 | public function register_routes() { |
| 120 | $route = new Active_Campaign_Route(); |
| 121 | $route->register(); |
| 122 | |
| 123 | register_setting( |
| 124 | trim( Base_Handler::PREFIX, '_' ), |
| 125 | Base_Handler::PREFIX . 'active-campaign-tab', |
| 126 | array( |
| 127 | 'type' => 'string', |
| 128 | 'show_in_rest' => true, |
| 129 | 'default' => '{}', |
| 130 | ) |
| 131 | ); |
| 132 | } |
| 133 | } |
| 134 |