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