/**
 * Check the purchase to ensure a banned email is not allowed through
 *
 * @since       2.0
 * @return      void
 */
function edd_check_purchase_email($valid_data, $posted)
{
    $is_banned = false;
    $banned = edd_get_banned_emails();
    if (empty($banned)) {
        return;
    }
    if (is_user_logged_in()) {
        // The user is logged in, check that their account email is not banned
        $user_data = get_userdata(get_current_user_id());
        if (edd_is_email_banned($user_data->user_email)) {
            $is_banned = true;
        }
        if (edd_is_email_banned($posted['edd_email'])) {
            $is_banned = true;
        }
    } elseif (isset($posted['edd-purchase-var']) && $posted['edd-purchase-var'] == 'needs-to-login') {
        // The user is logging in, check that their email is not banned
        $user_data = get_user_by('login', $posted['edd_user_login']);
        if ($user_data && edd_is_email_banned($user_data->user_email)) {
            $is_banned = true;
        }
    } else {
        // Guest purchase, check that the email is not banned
        if (edd_is_email_banned($posted['edd_email'])) {
            $is_banned = true;
        }
    }
    if ($is_banned) {
        // Set an error and give the customer a general error (don't alert them that they were banned)
        edd_set_error('email_banned', __('An internal error has occurred, please try again or contact support.', 'easy-digital-downloads'));
    }
}
/**
 * Display the ban emails tab
 *
 * @since       2.0
 * @return      void
 */
function edd_tools_banned_emails_display()
{
    do_action('edd_tools_banned_emails_before');
    ?>
	<div class="postbox">
		<h3><span><?php 
    _e('Banned Emails', 'edd');
    ?>
</span></h3>
		<div class="inside">
			<p><?php 
    _e('Emails placed in the box below will not be allowed to make purchases.', 'edd');
    ?>
</p>
			<form method="post" action="<?php 
    echo admin_url('edit.php?post_type=download&page=edd-tools&tab=general');
    ?>
">
				<p>
					<textarea name="banned_emails" rows="10" class="large-text"><?php 
    echo implode("\n", edd_get_banned_emails());
    ?>
</textarea>
					<span class="description"><?php 
    _e('Enter emails to disallow, one per line', 'edd');
    ?>
</span>
				</p>
				<p>
					<input type="hidden" name="edd_action" value="save_banned_emails" />
					<?php 
    wp_nonce_field('edd_banned_emails_nonce', 'edd_banned_emails_nonce');
    ?>
					<?php 
    submit_button(__('Save', 'edd'), 'secondary', 'submit', false);
    ?>
				</p>
			</form>
		</div><!-- .inside -->
	</div><!-- .postbox -->
<?php 
    do_action('edd_tools_banned_emails_after');
    do_action('edd_tools_after');
}
Beispiel #3
0
/**
 * Determines if an email is banned
 *
 * @since       2.0
 * @return      bool
 */
function edd_is_email_banned($email = '')
{
    if (empty($email)) {
        return false;
    }
    $banned_emails = edd_get_banned_emails();
    if (!is_array($banned_emails) || empty($banned_emails)) {
        return false;
    }
    foreach ($banned_emails as $banned_email) {
        if (is_email($banned_email)) {
            $ret = $banned_email == trim($email) ? true : false;
        } else {
            $ret = stristr(trim($email), $banned_email) ? true : false;
        }
        if (true === $ret) {
            break;
        }
    }
    return apply_filters('edd_is_email_banned', $ret, $email);
}
/**
 * Display the ban emails tab
 *
 * @since       2.0
 * @return      void
 */
function edd_tools_banned_emails_display()
{
    if (!current_user_can('manage_shop_settings')) {
        return;
    }
    do_action('edd_tools_banned_emails_before');
    ?>
	<div class="postbox">
		<h3><span><?php 
    _e('Banned Emails', 'easy-digital-downloads');
    ?>
</span></h3>
		<div class="inside">
			<p><?php 
    _e('Emails placed in the box below will not be allowed to make purchases. To ban an entire domain, enter the domain starting with "@".', 'easy-digital-downloads');
    ?>
</p>
			<form method="post" action="<?php 
    echo admin_url('edit.php?post_type=download&page=edd-tools&tab=general');
    ?>
">
				<p>
					<textarea name="banned_emails" rows="10" class="large-text"><?php 
    echo implode("\n", edd_get_banned_emails());
    ?>
</textarea>
					<span class="description"><?php 
    _e('Enter emails and/or domains (starting with @) to disallow, one per line.', 'easy-digital-downloads');
    ?>
</span>
				</p>
				<p>
					<input type="hidden" name="edd_action" value="save_banned_emails" />
					<?php 
    wp_nonce_field('edd_banned_emails_nonce', 'edd_banned_emails_nonce');
    ?>
					<?php 
    submit_button(__('Save', 'easy-digital-downloads'), 'secondary', 'submit', false);
    ?>
				</p>
			</form>
		</div><!-- .inside -->
	</div><!-- .postbox -->
<?php 
    do_action('edd_tools_banned_emails_after');
    do_action('edd_tools_after');
}
/**
 * Determines if an email is banned
 *
 * @since       2.0
 * @return      bool
 */
function edd_is_email_banned($email = '')
{
    if (empty($email)) {
        return false;
    }
    $ret = in_array(trim($email), edd_get_banned_emails());
    return apply_filters('edd_is_email_banned', $ret, $email);
}