/** * Trigger form submission. * * @since 1.0.0 * * @param array $data Sanitized form data * * @return null */ public static function submit($data) { $result = false; /* Subscribe the new user */ $user = WPBO_MC()->submit($data); /* Insertion is successful */ if (!is_wp_error($user)) { $result = true; } return $result; }
/** * Display a list of groups. * * If groups are available for the specified list then we display a list * with checkboxes. * * @since 1.1.0 * @return string List markup */ function wpbo_mc_display_groups() { /* Make sure we have a list ID to check */ if (!isset($_POST['mc_list_id'])) { echo '<div class="form-invalid" style="padding: 1em;">' . __('An error occurred during the request. The list ID is missing.', 'betteroptin') . '</div>'; wp_die(); } $list_id = sanitize_key($_POST['mc_list_id']); $post_id = (int) $_POST['mc_post_id']; /* Get the groups */ $groups = WPBO_MC()->get_groups($list_id); if (is_wp_error($groups)) { /** * @var WP_Error $groups */ echo '<div class="form-invalid" style="padding: 1em;">' . $groups->get_error_message() . '</div>'; wp_die(); } if (is_array($groups) && !empty($groups)) { foreach ($groups as $group) { $show_groups = new WPMC_MailChimp_Groups($group['id'], $group['groups'], $post_id); $group_name = $group['name']; $group_options = $group['form_field']; echo "<p>{$group_name}</p>"; switch ($group_options) { case 'checkboxes': $show_groups->show_group_type_checkboxes(); break; case 'radio': $show_groups->show_group_type_radio(); break; case 'dropdown': $show_groups->show_group_type_dropdown(); break; case 'hidden': $show_groups->show_group_type_checkboxes(); break; } } wp_die(); } else { echo '<div class="form-invalid" style="padding: 1em;">' . __('This list does not have any groups.', 'betteroptin') . '</div>'; wp_die(); } }
/** * Addon settings. * * Add new settings to the plugin settings page. * * @since 1.0.0 * * @param array $settings Pre-existing settings * * @return array Updated settings containing MailChimp options */ function wpbo_mc_settings($settings) { $lists = WPBO_MC()->get_lists(); if (false === $lists) { $list_id = array('name' => __('List ID', 'betteroptin'), 'id' => 'mc_list_id', 'type' => 'text', 'default' => '', 'desc' => sprintf(__('Input your API key and save if you want to see a dropdown of all your lists. If you don\'t know how to get your API key please <a href="%s" target="_blank">read this documentation</a>.', 'betteroptin'), esc_url('http://eepurl.com/im9k'))); } else { if (isset($lists['data']) && is_array($lists['data'])) { $opts[''] = __('Please select...', 'betteroptin'); foreach ($lists['data'] as $key => $list) { $opts[$list['id']] = $list['name']; } $list_id = array('name' => __('List ID', 'betteroptin'), 'id' => 'mc_list_id', 'type' => 'select', 'options' => $opts, 'default' => ''); } else { $list_id = array('name' => __('List ID', 'betteroptin'), 'id' => 'mc_list_id', 'type' => 'text', 'default' => '', 'desc' => __('Input your API key and save if you want to see a dropdown of all your lists.', 'betteroptin'), 'default' => ''); } } $settings['mailchimp'] = array('name' => __('MailChimp', 'betteroptin'), 'options' => array(array('type' => 'note', 'desc' => __('First of all, please input your MailChimp API key. Then hit the blue «Save Changes» button at the bottom of the screen. On page refresh, the <code>List ID</code> field will turn into a select dropdown showing all your MailChimp lists. If something goes wrong and you don\'t see the select dropdown, you can always input the list ID manually.', 'wpbo')), array('name' => __('API Key', 'betteroptin'), 'id' => 'mc_api_key', 'type' => 'text', 'default' => '', 'desc' => sprintf(__('If you don\'t know how to get your API key please <a href="%s" target="_blank">read this documentation</a>.', 'wpmc'), esc_url('http://eepurl.com/im9k'))), $list_id, array('name' => __('Double-Optin', 'betteroptin'), 'id' => 'mc_double_optin', 'type' => 'checkbox', 'default' => true, 'desc' => __('MailChimp asks for a subscription confirmation. It is advised NOT to disable it.', 'betteroptin')), array('name' => __('Update Existing', 'betteroptin'), 'id' => 'mc_update_existing', 'type' => 'checkbox', 'default' => true, 'desc' => __('Update contacts if already subscribed.', 'betteroptin')), array('name' => __('Welcome E-Mail', 'betteroptin'), 'id' => 'mc_welcome', 'type' => 'checkbox', 'default' => true, 'desc' => __('Send a welcome e-mail after subscription.', 'betteroptin')))); return $settings; }
/** * Change the save button label if MailChimp integration is not yet ready * * @since 1.0 * * @param $translation * @param $text * * @return string|void */ function wpbo_mc_publish_button_label($translation, $text) { if (!wpbo_is_popup_edit_screen()) { return $translation; } global $typenow; if ('wpbo-popup' == $typenow) { if (isset($_GET['post']) && 'Publish' == $text && !WPBO_MC()->is_mailchimp_ready()) { $translation = __('Save', 'betteroptin'); } } return $translation; }
} if ('mail-chimp' === wpbo_get_option('mailing_provider', '')) { require WPBO_PATH . 'includes/providers/mailchimp/functions-ajax.php'; require WPBO_PATH . 'includes/providers/mailchimp/class-mailchimp.php'; require WPBO_PATH . 'includes/providers/mailchimp/class-mailchimp-groups.php'; if (!defined('DOING_AJAX') || !DOING_AJAX) { // Load provider files if (is_admin()) { require WPBO_PATH . 'includes/providers/mailchimp/settings.php'; require WPBO_PATH . 'includes/providers/mailchimp/functions-metabox.php'; require WPBO_PATH . 'includes/providers/mailchimp/functions-admin.php'; } require WPBO_PATH . 'includes/providers/mailchimp/class-provider-mailchimp.php'; } // Instantiate the MailChimp provider WPBO_MC(); } add_filter('wpbo_mailing_providers', 'wpbo_provider_register_mailchimp'); /** * Register the WordPress provider * * @since 2.0 * * @param array $providers Existing providers * * @return array */ function wpbo_provider_register_mailchimp($providers) { $providers['mail-chimp'] = 'MailChimp'; // The dash in the name is just here so that the final class name resolves into MailChimp (with the capital letters)
<?php global $wpbo_submit, $post; if (!WPBO_MC()->is_mailchimp_ready()) { ?> <p class="wpbo-warning"><?php printf(__('MailChimp integration is not correctly setup. Your popups won\'t send subscribers anywhere! <a href="%s">Click here to see the settings</a>.', 'betteroptin'), esc_url(add_query_arg(array('post_type' => 'wpbo-popup', 'page' => 'edit.php?post_type=wpbo-popup-settings&tab=mailchimp'), admin_url('edit.php')))); ?> </p><?php } else { $lists = WPBO_MC()->get_lists(); $default = wpbo_get_option('mc_list_id'); $opts = array(); $value = isset($_GET['post']) ? get_post_meta(intval($_GET['post']), 'wpbo_mc_list', true) : ''; if (isset($lists['data']) && is_array($lists['data'])) { foreach ($lists['data'] as $key => $list) { $opts[$list['id']] = $list['name']; } $def_name = $opts[$default]; } else { ?> <p><?php printf(__('If you don\'t specify a list here, the default one will be used (currently %s).', 'betteroptin'), "<code>{$default}</code>"); ?> </p> <input type="text" id="wpbo_mc_list" name="wpbo_mc_list" style="width:100%" value="<?php echo $value; ?> " placeholder="<?php _e('List ID', 'betteroptin');