| 1 |
<?php |
| 2 |
/** |
| 3 |
* Admin |
| 4 |
* |
| 5 |
* @package AutomatorWP\Integrations\Mailchimp\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_mailchimp_get_option( $option_name, $default = false ) { |
| 23 |
|
| 24 |
$prefix = 'automatorwp_mailchimp_'; |
| 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_mailchimp_settings_sections( $automatorwp_settings_sections ) { |
| 37 |
|
| 38 |
$automatorwp_settings_sections['mailchimp'] = array( |
| 39 |
'title' => __( 'Mailchimp', 'automatorwp' ), |
| 40 |
'icon' => 'dashicons-mailchimp', |
| 41 |
); |
| 42 |
|
| 43 |
return $automatorwp_settings_sections; |
| 44 |
|
| 45 |
} |
| 46 |
add_filter( 'automatorwp_settings_sections', 'automatorwp_mailchimp_settings_sections' ); |
| 47 |
|
| 48 |
/** |
| 49 |
* Register plugin settings meta boxes |
| 50 |
* |
| 51 |
* @since 1.0.0 |
| 52 |
* |
| 53 |
* @return array |
| 54 |
*/ |
| 55 |
function automatorwp_mailchimp_settings_meta_boxes( $meta_boxes ) { |
| 56 |
|
| 57 |
$prefix = 'automatorwp_mailchimp_'; |
| 58 |
|
| 59 |
$meta_boxes['automatorwp-mailchimp-settings'] = array( |
| 60 |
'title' => automatorwp_dashicon( 'mailchimp' ) . __( 'Mailchimp', 'automatorwp' ), |
| 61 |
'fields' => apply_filters( 'automatorwp_mailchimp_settings_fields', array( |
| 62 |
$prefix . 'api_key' => array( |
| 63 |
'name' => __( 'API Key:', 'automatorwp' ), |
| 64 |
'desc' => __( 'Your Mailchimp API key.', 'automatorwp' ), |
| 65 |
'type' => 'text', |
| 66 |
), |
| 67 |
$prefix . 'server_prefix' => array( |
| 68 |
'name' => __( 'Server prefix:', 'automatorwp' ), |
| 69 |
'desc' => __( 'Your Mailchimp server prefix.', 'automatorwp' ), |
| 70 |
'type' => 'text', |
| 71 |
), |
| 72 |
$prefix . 'mailchimp_authorize' => array( |
| 73 |
'type' => 'text', |
| 74 |
'render_row_cb' => 'automatorwp_mailchimp_authorize_display_cb', |
| 75 |
), |
| 76 |
) ), |
| 77 |
); |
| 78 |
|
| 79 |
return $meta_boxes; |
| 80 |
|
| 81 |
} |
| 82 |
add_filter( "automatorwp_settings_mailchimp_meta_boxes", 'automatorwp_mailchimp_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_mailchimp_authorize_display_cb( $field_args, $field ) { |
| 93 |
|
| 94 |
$access_valid = automatorwp_mailchimp_get_option( 'access_valid' ); |
| 95 |
|
| 96 |
?> |
| 97 |
|
| 98 |
<div class="cmb-row cmb-type-custom cmb2-id-automatorwp-mailchimp-authorize table-layout" data-fieldtype="custom"> |
| 99 |
<div class="cmb-th"> |
| 100 |
<label><?php echo __( 'Connect with Mailchimp:', 'automatorwp' ); ?></label> |
| 101 |
</div> |
| 102 |
<div class="cmb-td"> |
| 103 |
<input type="hidden" name="awp-mailchimp-outh-ajax-nonce" id="awp-mailchimp-outh-ajax-nonce" value="<?php echo wp_create_nonce( 'awp-outh-ajax-nonce' ); ?>" /> |
| 104 |
<input type="button" name="automatorwp_save_mailchimp_oauth" id="automatorwp_save_mailchimp_oauth" value="Save Credentials" class="button button-primary" /> |
| 105 |
<?php if ( $access_valid ){ ?> |
| 106 |
<input type="button" name="automatorwp_remove_mailchimp_oauth" id="automatorwp_remove_mailchimp_oauth" value="Delete Credentials" class="button button-danger" /><br> |
| 107 |
<?php } ?> |
| 108 |
<p id='awp_mailchimp_oauth_status'></p> |
| 109 |
</div> |
| 110 |
</div> |
| 111 |
|
| 112 |
<?php |
| 113 |
} |