| 1 |
<?php |
| 2 |
/** |
| 3 |
* Admin |
| 4 |
* |
| 5 |
* @package AutomatorWP\Integrations\ConvertKit\Admin |
| 6 |
* @author AutomatorWP <contact@automatorwp.com>, Ruben Garcia <rubengcdev@gmail.com> |
| 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_convertkit_get_option( $option_name, $default = false ) { |
| 23 |
|
| 24 |
$prefix = 'automatorwp_convertkit_'; |
| 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_convertkit_settings_sections( $automatorwp_settings_sections ) { |
| 37 |
|
| 38 |
$automatorwp_settings_sections['convertkit'] = array( |
| 39 |
'title' => __( 'ConvertKit', 'automatorwp' ), |
| 40 |
'icon' => 'dashicons-convertkit', |
| 41 |
); |
| 42 |
|
| 43 |
return $automatorwp_settings_sections; |
| 44 |
|
| 45 |
} |
| 46 |
add_filter( 'automatorwp_settings_sections', 'automatorwp_convertkit_settings_sections' ); |
| 47 |
|
| 48 |
/** |
| 49 |
* Register plugin settings meta boxes |
| 50 |
* |
| 51 |
* @since 1.0.0 |
| 52 |
* |
| 53 |
* @return array |
| 54 |
*/ |
| 55 |
function automatorwp_convertkit_settings_meta_boxes( $meta_boxes ) { |
| 56 |
|
| 57 |
$prefix = 'automatorwp_convertkit_'; |
| 58 |
|
| 59 |
$meta_boxes['automatorwp-convertkit-settings'] = array( |
| 60 |
'title' => automatorwp_dashicon( 'convertkit' ) . __( 'ConvertKit', 'automatorwp' ), |
| 61 |
'fields' => apply_filters( 'automatorwp_convertkit_settings_fields', array( |
| 62 |
$prefix . 'key' => array( |
| 63 |
'name' => __( 'API key:', 'automatorwp' ), |
| 64 |
'desc' => sprintf( __( 'Your ConvertKit API key.'), 'automatorwp' ), |
| 65 |
'type' => 'text', |
| 66 |
), |
| 67 |
$prefix . 'secret' => array( |
| 68 |
'name' => __( 'API Secret:', 'automatorwp' ), |
| 69 |
'desc' => sprintf( __( 'Your ConvertKit API Secret.'), 'automatorwp' ), |
| 70 |
'type' => 'text', |
| 71 |
), |
| 72 |
$prefix . 'authorize' => array( |
| 73 |
'type' => 'text', |
| 74 |
'render_row_cb' => 'automatorwp_convertkit_authorize_display_cb' |
| 75 |
), |
| 76 |
) ), |
| 77 |
); |
| 78 |
|
| 79 |
return $meta_boxes; |
| 80 |
|
| 81 |
} |
| 82 |
add_filter( "automatorwp_settings_convertkit_meta_boxes", 'automatorwp_convertkit_settings_meta_boxes' ); |
| 83 |
|
| 84 |
/** |
| 85 |
* Display callback for the authorize setting |
| 86 |
* |
| 87 |
* @since 1.0.0 |
| 88 |
* |
| 89 |
* @param array $field_args Array of field arguments. |
| 90 |
* @param CMB2_Field $field The field object |
| 91 |
*/ |
| 92 |
function automatorwp_convertkit_authorize_display_cb( $field_args, $field ) { |
| 93 |
|
| 94 |
$field_id = $field_args['id']; |
| 95 |
|
| 96 |
$key = automatorwp_convertkit_get_option( 'key', '' ); |
| 97 |
$secret = automatorwp_convertkit_get_option( 'secret', '' ); |
| 98 |
|
| 99 |
?> |
| 100 |
<div class="cmb-row cmb-type-custom cmb2-id-automatorwp-convertkit-authorize table-layout" data-fieldtype="custom"> |
| 101 |
<div class="cmb-th"> |
| 102 |
<label><?php echo __( 'Connect with ConvertKit:', 'automatorwp' ); ?></label> |
| 103 |
</div> |
| 104 |
<div class="cmb-td"> |
| 105 |
<a id="<?php echo $field_id; ?>" class="button button-primary" href="#"><?php echo __( 'Save credentials', 'automatorwp' ); ?></a> |
| 106 |
<p class="cmb2-metabox-description"><?php echo __( 'Add you ConvertKit API key and API secret fields and click on "Authorize" to connect.', 'automatorwp' ); ?></p> |
| 107 |
<?php if ( ! empty( $key ) && ! empty( $secret ) ) : ?> |
| 108 |
<div class="automatorwp-notice-success"><?php echo __( 'Site connected with ConvertKit successfully.', 'automatorwp' ); ?></div> |
| 109 |
<?php endif; ?> |
| 110 |
</div> |
| 111 |
</div> |
| 112 |
<?php |
| 113 |
} |