_e('to know how to get this information. In case you don\'t want to enable subscription option, just leave this field blank.', 'signals');
?>
</p>
			</div>

			<div class="signals-form-group">
				<label for="signals_csmm_list" class="signals-strong"><?php 
_e('MailChimp List', 'signals');
?>
</label>

				<?php 
// Checking if the API key is present in the database
if (!empty($signals_csmm_options['mailchimp_api'])) {
    // Grabbing lists using the MailChimp API
    $signals_api = new Signals_MailChimp($signals_csmm_options['mailchimp_api']);
    $signals_lists = $signals_api->call('lists/list', array('apikey' => $signals_csmm_options['mailchimp_api']));
    if (!$signals_lists) {
        echo '<p class="signals-form-help-block">' . __('There was an error communicating with the MailChimp server. Please make sure that the API Key used is correct and try again.', 'signals') . '</p>';
    } else {
        if ($signals_lists['total'] == 0) {
            echo '<p class="signals-form-help-block">' . __('It seems that there is no list created for this account. Why not create one on the MailChimp website and then try here.', 'signals') . '</p>';
        } else {
            echo '<select name="signals_csmm_list" id="signals_csmm_list">';
            foreach ($signals_lists['data'] as $signals_single_list) {
                echo '<option value="' . $signals_single_list['id'] . '"' . selected($signals_single_list['id'], $signals_csmm_options['mailchimp_list']) . '>' . $signals_single_list['name'] . '</option>';
            }
            echo '</select>';
            echo '<p class="signals-form-help-block">' . __('Select your MailChimp list in which you would like to store the subscribers data.', 'signals') . '</p>';
        }
    }
Esempio n. 2
0
$custom_html = stripslashes($options['custom_html']);
// form
if (!empty($custom_html) && false !== strpos($custom_html, '{{form}}')) {
    if (!empty($options['mailchimp_api']) && !empty($options['mailchimp_list'])) {
        // Checking if the form is submitted or not
        if (isset($_POST['signals_email'])) {
            // Processing begins
            $signals_email = strip_tags($_POST['signals_email']);
            if ('' === $signals_email) {
                $code = 'danger';
                $response = __('Please provide your email address.', 'signals');
            } else {
                $signals_email = filter_var(strtolower(trim($signals_email)), FILTER_SANITIZE_EMAIL);
                if (strpos($signals_email, '@')) {
                    require_once SIGNALS_CSMM_PATH . '/framework/admin/include/classes/class-mailchimp.php';
                    $signals_connect = new Signals_MailChimp($options['mailchimp_api']);
                    $signals_response = $signals_connect->call('lists/subscribe', array('id' => $options['mailchimp_list'], 'email' => array('email' => $signals_email), 'send_welcome' => true));
                    // Showing message as per the response from the mailchimp server
                    if (isset($signals_response['code']) && 214 !== $signals_response['code']) {
                        $code = 'danger';
                        $response = $options['message_wrong'];
                    } elseif (isset($signals_response['code']) && 214 === $signals_response['code']) {
                        $code = 'success';
                        $response = $options['message_subscribed'];
                    } else {
                        $code = 'success';
                        $response = $options['message_done'];
                    }
                } else {
                    $code = 'danger';
                    $response = $options['message_noemail'];