Ejemplo n.º 1
0
    private function render_settings_tab()
    {
        $mailchimp_apikey = get_site_option('mailchimp_apikey', '');
        $mailchimp_mailing_list = get_site_option('mailchimp_mailing_list');
        $mailchimp_auto_opt_in = get_site_option('mailchimp_auto_opt_in');
        $mailchimp_ignore_plus = get_site_option('mailchimp_ignore_plus');
        $mailchimp_allow_widget = get_site_option('mailchimp_allow_widget', false);
        $mailchimp_allow_shortcode = get_site_option('mailchimp_allow_shortcode', false);
        $webhooks_settings = mailchimp_get_webhooks_settings();
        $groups = get_site_option('mailchimp_groups');
        if (!empty($mailchimp_apikey)) {
            $api = mailchimp_load_API();
            if (is_wp_error($api)) {
                $api_error = $api->get_error_message();
            }
            $mailchimp_lists = mailchimp_get_lists();
            $api_error = !empty($api_error);
            $list_groups = array();
            if ($mailchimp_lists && $mailchimp_mailing_list) {
                $list_groups = mailchimp_get_list_groups($mailchimp_mailing_list);
            }
        }
        if (empty($mailchimp_apikey)) {
            ?>
   			<p><?php 
            _e('After you have entered a valid API key you will be able to select different MailChimp options below.', MAILCHIMP_LANG_DOMAIN);
            ?>
</p>
    	<?php 
        }
        ?>

    	<table class="form-table">


	        <tr class="form-field form-required">
	            <th scope="row"><?php 
        _e('MailChimp API Key', MAILCHIMP_LANG_DOMAIN);
        ?>
</th>
	            <td><input type="text" name="mailchimp_apikey" id="mailchimp_apikey" value="<?php 
        echo $mailchimp_apikey;
        ?>
" /><br />
	            <?php 
        _e('Visit <a href="http://admin.mailchimp.com/account/api" target="_blank">your API dashboard</a> to create an API key.', MAILCHIMP_LANG_DOMAIN);
        ?>
	            </td>
	        </tr>

	        <?php 
        if (!empty($mailchimp_apikey)) {
            ?>

	        	<?php 
            if (!$api_error) {
                ?>
					<tr class="form-field form-required">
						<th scope="row"><?php 
                _e('API Key Test', MAILCHIMP_LANG_DOMAIN);
                ?>
</th>
						<td><strong style="color:#006633"><?php 
                _e('Passed', MAILCHIMP_LANG_DOMAIN);
                ?>
</strong>
						</td>
					</tr>
    				<tr class="form-field form-required">
        				<th scope="row"><?php 
                _e('Auto Opt-in', MAILCHIMP_LANG_DOMAIN);
                ?>
</th>
        					<td>
        						<select name="mailchimp_auto_opt_in" id="mailchimp_auto_opt_in">
				                    <option value="yes" <?php 
                selected($mailchimp_auto_opt_in, 'yes');
                ?>
 ><?php 
                _e('Yes', MAILCHIMP_LANG_DOMAIN);
                ?>
</option>
				                    <option value="no" <?php 
                selected($mailchimp_auto_opt_in, 'no');
                ?>
 ><?php 
                _e('No', MAILCHIMP_LANG_DOMAIN);
                ?>
</option>
				                </select>
        						<span class="description"><?php 
                _e('Automatically opt-in new users to the mailing list. Users will not receive an email confirmation. Use at your own risk.', MAILCHIMP_LANG_DOMAIN);
                ?>
</span>
        					</td>
		            </tr>
		            <tr class="form-field form-required">
		                <th scope="row"><?php 
                _e('Ignore email addresses including + signs', MAILCHIMP_LANG_DOMAIN);
                ?>
</th>
		                <td>
		                	<select name="mailchimp_ignore_plus" id="mailchimp_ignore_plus">
		                    	<option value="yes" <?php 
                selected($mailchimp_ignore_plus, 'yes');
                ?>
 ><?php 
                _e('Yes', MAILCHIMP_LANG_DOMAIN);
                ?>
</option>
		                    	<option value="no" <?php 
                selected($mailchimp_ignore_plus, 'no');
                ?>
 ><?php 
                _e('No', MAILCHIMP_LANG_DOMAIN);
                ?>
</option>
		                	</select>
		                	<span class="description"><?php 
                _e('Ignore email address including + signs. These are usually duplicate accounts.', MAILCHIMP_LANG_DOMAIN);
                ?>
</span>
		                </td>
		            </tr>

				    <?php 
                if (!is_array($mailchimp_lists) || !count($mailchimp_lists)) {
                    ?>
				    	<div class="error"><p><?php 
                    _e('You must have at least one MailChimp mailing list in order to use this plugin. Please create a mailing list via the MailChimp admin panel.', MAILCHIMP_LANG_DOMAIN);
                    ?>
</p></div>
					<?php 
                } else {
                    ?>
						<tr class="form-field form-required">
			                <th scope="row"><?php 
                    _e('Mailing List', MAILCHIMP_LANG_DOMAIN);
                    ?>
</th>
			                <td>
			                  	<select name="mailchimp_mailing_list" id="mailchimp_mailing_list">
            						<?php 
                    if (empty($mailchimp_mailing_list)) {
                        ?>
										<option value="" selected="selected" ><?php 
                        _e('Please select a mailing list', MAILCHIMP_LANG_DOMAIN);
                        ?>
</option>
              						<?php 
                    }
                    ?>
									<?php 
                    foreach ($mailchimp_lists as $mailchimp_list) {
                        ?>
										<option value="<?php 
                        echo $mailchimp_list['id'];
                        ?>
" <?php 
                        selected($mailchimp_mailing_list, $mailchimp_list['id']);
                        ?>
><?php 
                        echo $mailchimp_list['name'];
                        ?>
</option>
									<?php 
                    }
                    ?>
								</select>
              					<span class="description"><?php 
                    _e('Select a mailing list you want to have new users added to.', MAILCHIMP_LANG_DOMAIN);
                    ?>
</span>
			                </td>
			            </tr>
					<?php 
                }
                ?>

					<?php 
                if (!empty($list_groups) && is_array($list_groups)) {
                    ?>
						<p><?php 
                    _e('Assign users to the following groups:', MAILCHIMP_LANG_DOMAIN);
                    ?>
</p>
						<tr class="form-field">
			                <th scope="row"><?php 
                    _e('List Groups', MAILCHIMP_LANG_DOMAIN);
                    ?>
</th>
			                <td>
			                	<?php 
                    foreach ($list_groups as $group) {
                        ?>
			                		<?php 
                        if (empty($group['groups'])) {
                            continue;
                        }
                        ?>

			                		<?php 
                        $this->render_list_group($group);
                        ?>

			                	<?php 
                    }
                    ?>

			                </td>
			            </tr>
					<?php 
                }
                ?>



					<?php 
                if (is_multisite() && apply_filters('mailchimp_allow_front_widgets', true)) {
                    ?>
	      				<tr class="form-field form-required">
				            <th scope="row"><?php 
                    _e('Allow widget in all subsites', MAILCHIMP_LANG_DOMAIN);
                    ?>
</th>
				            <td><input type="checkbox" name="allow_widget" id="allow_widget" <?php 
                    checked($mailchimp_allow_widget);
                    ?>
 style="width:inherit;"/>
				            </td>
				        </tr>
				        <tr class="form-field form-required">
				            <th scope="row"><?php 
                    _e('Allow shortcode use in all subsites', MAILCHIMP_LANG_DOMAIN);
                    ?>
</th>
				            <td><input type="checkbox" name="allow_shortcode" id="allow_shortcode" <?php 
                    checked($mailchimp_allow_shortcode);
                    ?>
 style="width:inherit;"/>
				            </td>
				        </tr>
				    <?php 
                }
                ?>

				<?php 
            } else {
                // if ! $api_error
                ?>
					<tr class="form-field form-required">
						<th scope="row"><?php 
                _e('API Key Test', MAILCHIMP_LANG_DOMAIN);
                ?>
</th>
						<td><strong style="color:#990000"><?php 
                _e('Failed - Please check your key and try again.', MAILCHIMP_LANG_DOMAIN);
                ?>
</strong>
						</td>
					</tr>
				<?php 
            }
            ?>

	    	<?php 
        }
        // if ( ! empty( $mailchimp_apikey ) )
        ?>

    	</table>

		<?php 
        if (!empty($mailchimp_apikey) && !empty($mailchimp_mailing_list)) {
            ?>

	    	<h3><?php 
            esc_html_e('Webhooks', MAILCHIMP_LANG_DOMAIN);
            ?>
</h3>
			<p><?php 
            _e('Allows WordPress users to be updated with MailChimp subscribe/unsubscribe actions', MAILCHIMP_LANG_DOMAIN);
            ?>
</p>
			<p><?php 
            printf(__('Please, follow <a href="%s">this</a> instructions to set up your webhooks', MAILCHIMP_LANG_DOMAIN), 'http://kb.mailchimp.com/integrations/other-integrations/what-are-webhooks-and-how-can-i-set-them-up');
            ?>
</p>

			<table class="form-table">

		        <tr class="form-field form-required">
		            <th scope="row"><?php 
            _e('Specify a unique webhook key', MAILCHIMP_LANG_DOMAIN);
            ?>
</th>
		            <td>
		            	<input type="text" name="mailchimp_webhooks[webhook_key]" value="<?php 
            echo esc_attr($webhooks_settings['webhook_key']);
            ?>
" /><br/>

		            	<?php 
            if (mailchimp_get_webhook_url()) {
                ?>
		            		<span class="description"><?php 
                printf(__('Your Webhook URL is: <code>%s</code>', MAILCHIMP_LANG_DOMAIN), mailchimp_get_webhook_url());
                ?>
</span><br/>
		            	<?php 
            } else {
                ?>
		            		<span class="description"><?php 
                _e('Enter the name you want to use for your secret key, then click Save Changes. The callback URL you will need to add to your webhook at MailChimp will then appear here', MAILCHIMP_LANG_DOMAIN);
                ?>
</span>
		            	<?php 
            }
            ?>
		            </td>

		            </tr>
						<tr class="form-field form-required">
						<th scope="row"><label for="mailchimp_webhooks_delete_user"><?php 
            _e('Action to take when user unsubscribes from list', MAILCHIMP_LANG_DOMAIN);
            ?>
</label></th>
						<td>
							<select name="mailchimp_webhooks[delete_user]" id="mailchimp_webhooks_delete_user">
				                <option value="mark" <?php 
            selected($webhooks_settings['delete_user'] == 'mark');
            ?>
><?php 
            _e('Mark as not subscribed', MAILCHIMP_LANG_DOMAIN);
            ?>
</option>
				                <option value="delete" <?php 
            selected($webhooks_settings['delete_user'] == 'delete');
            ?>
><?php 
            _e('Delete user', MAILCHIMP_LANG_DOMAIN);
            ?>
</option>
				            </select><br />
							<?php 
            _e('<strong>Warning</strong>: Use with caution! Please note, Administrators (on single sites) and Super Administrators (on networks) cannot be deleted.', MAILCHIMP_LANG_DOMAIN);
            ?>
						</td>
					</tr>

		        </tr>

			</table>

		<?php 
        }
        ?>

    	<?php 
    }
Ejemplo n.º 2
0
 private function unsubscribe($data)
 {
     $user_email = $data['email'];
     $user = get_user_by('email', $user_email);
     if (!$user) {
         return new WP_Error('user_not_exists', sprintf(__('User not found with this email address: "%s"', MAILCHIMP_LANG_DOMAIN), $user_email));
     }
     $settings = mailchimp_get_webhooks_settings();
     if ('mark' === $settings['delete_user']) {
         $list_id = get_site_option('mailchimp_mailing_list');
         update_user_meta($user->ID, 'mailchimp_subscriber_' . $list_id, 0);
         $this->log(sprintf(__('UNSUBSCRIBE: user unsubscribed from list: "%s"', MAILCHIMP_LANG_DOMAIN), $user_email));
     } else {
         if (is_multisite()) {
             if (!function_exists('wp_delete_user')) {
                 require_once ABSPATH . 'wp-admin/includes/ms.php';
             }
             if (is_super_admin()) {
                 return new WP_Error('user_not_exists', sprintf(__('Deleting Super Admins is not allowed: "%s"', MAILCHIMP_LANG_DOMAIN), $user_email));
             }
             $result = wpmu_delete_user($user->ID, false);
         } else {
             if (!function_exists('wp_delete_user')) {
                 require_once ABSPATH . 'wp-admin/includes/user.php';
             }
             if (current_user_can('manage_options')) {
                 return new WP_Error('user_not_exists', sprintf(__('Deleting Administrators is not allowed: "%s"', MAILCHIMP_LANG_DOMAIN), $user_email));
             }
             $result = wp_delete_user($user->ID, false);
         }
         if (!$result) {
             return new WP_Error('error_deleting_user', sprintf(__('FAILED: Something went wrong while trying to delete user: "******"', MAILCHIMP_LANG_DOMAIN), $user_email));
         }
         $this->log(sprintf(__('UNSUBSCRIBE: user deleted: "%s"', MAILCHIMP_LANG_DOMAIN), $user_email));
     }
     return true;
 }