| 1 |
<?php |
| 2 |
/** |
| 3 |
* Admin |
| 4 |
* |
| 5 |
* @package AutomatorWP\Integrations\ActiveCampaign\Admin |
| 6 |
* @author AutomatorWP <[email protected]>, Ruben Garcia <[email protected]> |
| 7 |
* @since 1.0.0 |
| 8 |
*/ |
| 9 |
// Exit if accessed directly |
| 10 |
if( !defined( 'ABSPATH' ) ) exit; |
| 11 |
|
| 12 |
/** |
| 13 |
* Shortcut function to get plugin options |
| 14 |
* |
| 15 |
* @since 1.0.0 |
| 16 |
* |
| 17 |
* @param string $option_name |
| 18 |
* @param bool $default |
| 19 |
* |
| 20 |
* @return mixed |
| 21 |
*/ |
| 22 |
function automatorwp_activecampaign_get_option( $option_name, $default = false ) { |
| 23 |
|
| 24 |
$prefix = 'automatorwp_activecampaign_'; |
| 25 |
|
| 26 |
return automatorwp_get_option( $prefix . $option_name, $default ); |
| 27 |
} |
| 28 |
|
| 29 |
/** |
| 30 |
* Register plugin settings sections |
| 31 |
* |
| 32 |
* @since 1.0.0 |
| 33 |
* |
| 34 |
* @return array |
| 35 |
*/ |
| 36 |
function automatorwp_activecampaign_settings_sections( $automatorwp_settings_sections ) { |
| 37 |
|
| 38 |
$automatorwp_settings_sections['activecampaign'] = array( |
| 39 |
'title' => __( 'ActiveCampaign', 'automatorwp' ), |
| 40 |
'icon' => 'dashicons-activecampaign', |
| 41 |
); |
| 42 |
|
| 43 |
return $automatorwp_settings_sections; |
| 44 |
|
| 45 |
} |
| 46 |
add_filter( 'automatorwp_settings_sections', 'automatorwp_activecampaign_settings_sections' ); |
| 47 |
|
| 48 |
/** |
| 49 |
* Register plugin settings meta boxes |
| 50 |
* |
| 51 |
* @since 1.0.0 |
| 52 |
* |
| 53 |
* @return array |
| 54 |
*/ |
| 55 |
function automatorwp_activecampaign_settings_meta_boxes( $meta_boxes ) { |
| 56 |
|
| 57 |
$prefix = 'automatorwp_activecampaign_'; |
| 58 |
|
| 59 |
$meta_boxes['automatorwp-settings'] = array( |
| 60 |
'title' => automatorwp_dashicon( 'activecampaign' ) . __( 'ActiveCampaign', 'automatorwp' ), |
| 61 |
'fields' => apply_filters( 'automatorwp_activecampaign_settings_fields', array( |
| 62 |
$prefix . 'url' => array( |
| 63 |
'name' => __( 'API URL:', 'automatorwp' ), |
| 64 |
'desc' => sprintf( __( 'Your ActiveCampaign url.'), 'automatorwp' ), |
| 65 |
'type' => 'text', |
| 66 |
), |
| 67 |
$prefix . 'key' => array( |
| 68 |
'name' => __( 'API key:', 'automatorwp' ), |
| 69 |
'desc' => sprintf( __( 'Your ActiveCampaign API key.'), 'automatorwp' ), |
| 70 |
'type' => 'text', |
| 71 |
), |
| 72 |
$prefix . 'webhook' => array( |
| 73 |
'type' => 'text', |
| 74 |
'render_row_cb' => 'automatorwp_activecampaign_webhook_url_cb', |
| 75 |
), |
| 76 |
$prefix . 'authorize' => array( |
| 77 |
'type' => 'text', |
| 78 |
'render_row_cb' => 'automatorwp_activecampaign_authorize_display_cb' |
| 79 |
), |
| 80 |
) ), |
| 81 |
); |
| 82 |
|
| 83 |
return $meta_boxes; |
| 84 |
|
| 85 |
} |
| 86 |
add_filter( "automatorwp_settings_activecampaign_meta_boxes", 'automatorwp_activecampaign_settings_meta_boxes' ); |
| 87 |
|
| 88 |
|
| 89 |
/** |
| 90 |
* Display callback for the webhook URL |
| 91 |
* |
| 92 |
* @since 1.0.0 |
| 93 |
* |
| 94 |
*/ |
| 95 |
|
| 96 |
function automatorwp_activecampaign_webhook_url_cb( ) { |
| 97 |
|
| 98 |
$webhook_url = automatorwp_activecampaign_get_webhook_url(); |
| 99 |
|
| 100 |
?> |
| 101 |
<div class="cmb-row cmb-type-custom cmb2-id-automatorwp-redirect-url table-layout" data-fieldtype="custom"> |
| 102 |
<div class="cmb-th"> |
| 103 |
<label><?php echo __( 'Webhook URL:', 'automatorwp' ); ?></label> |
| 104 |
</div> |
| 105 |
<div class="cmb-td"> |
| 106 |
<input type="text" class="regular-text" value="<?php echo $webhook_url; ?>" readonly> |
| 107 |
<a id="automatorwp_activecampaign_refresh" class="button" href="#"><?php echo __( 'Regenerate URL', 'automatorwp' ); ?></a> |
| 108 |
<p class="cmb2-metabox-description"><?php echo __( 'Copy this URL and place it on your ActiveCampaign account.', 'automatorwp' ); ?></p> |
| 109 |
</div> |
| 110 |
</div> |
| 111 |
<?php |
| 112 |
|
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
/** |
| 117 |
* Display callback for the authorize setting |
| 118 |
* |
| 119 |
* @since 1.0.0 |
| 120 |
* |
| 121 |
* @param array $field_args Array of field arguments. |
| 122 |
* @param CMB2_Field $field The field object |
| 123 |
*/ |
| 124 |
function automatorwp_activecampaign_authorize_display_cb( $field_args, $field ) { |
| 125 |
|
| 126 |
$field_id = $field_args['id']; |
| 127 |
|
| 128 |
$url = automatorwp_activecampaign_get_option( 'url', '' ); |
| 129 |
$key = automatorwp_activecampaign_get_option( 'key', '' ); |
| 130 |
|
| 131 |
?> |
| 132 |
<div class="cmb-row cmb-type-custom cmb2-id-automatorwp-authorize table-layout" data-fieldtype="custom"> |
| 133 |
<div class="cmb-th"> |
| 134 |
<label><?php echo __( 'Connect with ActiveCampaign:', 'automatorwp' ); ?></label> |
| 135 |
</div> |
| 136 |
<div class="cmb-td"> |
| 137 |
<a id="<?php echo $field_id; ?>" class="button button-primary" href="#"><?php echo __( 'Save credentials', 'automatorwp' ); ?></a> |
| 138 |
<p class="cmb2-metabox-description"><?php echo __( 'Add you ActiveCampaign API key and URL fields and click on "Authorize" to connect.', 'automatorwp' ); ?></p> |
| 139 |
<?php if ( ! empty( $url ) && ! empty( $key ) ) : ?> |
| 140 |
<div class="automatorwp-notice-success"><?php echo __( 'Site connected with ActiveCampaign successfully.', 'automatorwp' ); ?></div> |
| 141 |
<?php endif; ?> |
| 142 |
</div> |
| 143 |
</div> |
| 144 |
<?php |
| 145 |
} |