Plugin Directory

Changeset 2806972


Ignore:
Timestamp:
10/29/2022 10:24:39 AM (3 years ago)
Author:
Wigster
Message:

Added support to handle blocking multiple domains, and confirming functionality with latest WP/WooCommerce

Location:
block-specific-spam-woo-orders/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • block-specific-spam-woo-orders/trunk/readme.txt

    r2719240 r2806972  
    33Tags: woocommerce,woo,block,spam,orders
    44Requires at least: 5.1
    5 Tested up to: 6.0
     5Tested up to: 6.1
    66Requires PHP: 5.4
    77Stable tag: 4.3
     
    2525== Changelog ==
    2626
     27= 0.6 =
     28* Added a new function to handle checking against multiple blocked domains, now including ["@fakemail"]
     29* Confirming support with WP 6.1 and Latest WooCommerce
     30
    2731= 0.55 =
    2832* Tested support with WP 6.0 and latest WC - works fine.
  • block-specific-spam-woo-orders/trunk/woo-block-spam-orders.php

    r2719240 r2806972  
    66* Description: A quick plugin to block on-going issues with spam WooCommerce orders November 2020
    77* Author: guwii
    8 * Version: 0.55
     8* Version: 0.6
    99* Author URI: https://guwii.com
    1010* License: GPL3+
    1111* Text Domain: guwii-woo-block-spam-orders
    1212* WC requires at least: 4.3
    13 * WC tested up to: 6.4.1
     13* WC tested up to: 7.0
    1414*/
    1515
     
    1919    add_action('woocommerce_after_checkout_validation', 'action_woocommerce_validate_spam_checkout', 10, 2);
    2020
     21    // Check over a list of provided domains, to see if $user_email matches any of them:
     22    function has_a_blocked_domain($user_email)
     23    {
     24        // Provide our list of domains we want to block:
     25        $listOfBlockedDomains = ['abbuzz.com', 'fakemail.com'];
     26        // Set the default return of false:
     27        $hasABlockedDomain = false;
     28        // Compare users email with our list of blocked domains:
     29        foreach ($listOfBlockedDomains as $aBlockedDomain) {
     30            // If a blocked domain exists in the users email, return true;
     31            // Info:
     32            // "!== false" is used for comparison, as if the users email matches a blocked domain
     33            // the return from [strpos()] is the position of the string (a number), we don't care about that, we just want to know if it was false [i.e not found]
     34            if (strpos($user_email, $aBlockedDomain) !== false) {
     35                $hasABlockedDomain = true;
     36            }
     37        }
     38        return $hasABlockedDomain;
     39    }
    2140    // Check if billing name or email domain is a specific string, if it is we'll decline the order:
    2241    function action_woocommerce_validate_spam_checkout($fields, $errors)
    2342    {
    2443        $customer_name_to_block = 'bbbbb';
    25         $email_domain_to_block = 'abbuzz.com';
    2644        if (
    2745            $fields['billing_first_name'] == $customer_name_to_block
    2846            ||
    29             strpos(strtolower($fields['billing_email']), $email_domain_to_block)
     47            (has_a_blocked_domain($fields['billing_email']) == true)
    3048        ) {
    3149            $errors->add('validation', 'Spam.');
Note: See TracChangeset for help on using the changeset viewer.