Plugin Directory

Changeset 3012514


Ignore:
Timestamp:
12/20/2023 03:11:32 PM (2 years ago)
Author:
Wigster
Message:

Upgrading to 0.7 - rework checking logic and adding localisation to output

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

Legend:

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

    r2806972 r3012514  
    33Tags: woocommerce,woo,block,spam,orders
    44Requires at least: 5.1
    5 Tested up to: 6.1
     5Tested up to: 6.4.2
    66Requires PHP: 5.4
    77Stable tag: 4.3
     
    2525== Changelog ==
    2626
     27= 0.7 =
     28* Update logic slightly to simplify checks. Names are now also array based if people wanted to manually extend.
     29* Added ability to translate/localise the Spam Validation message with typical language translators (WPML etc).
     30* Confirming support with WP 6.4 and Latest WooCommerce
     31
    2732= 0.6 =
    2833* Added a new function to handle checking against multiple blocked domains, now including ["@fakemail"]
  • block-specific-spam-woo-orders/trunk/woo-block-spam-orders.php

    r2806972 r3012514  
    66* Description: A quick plugin to block on-going issues with spam WooCommerce orders November 2020
    77* Author: guwii
    8 * Version: 0.6
     8* Version: 0.7
    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: 7.0
     13* WC tested up to: 8.4
    1414*/
    1515
    1616// Only use this plugin if WooCommerce is active
    1717if (in_array('woocommerce/woocommerce.php', get_option('active_plugins'))) {
    18     // Add our custom checks to the built in WooCommerce checkout validation:
    19     add_action('woocommerce_after_checkout_validation', 'action_woocommerce_validate_spam_checkout', 10, 2);
     18  // Add our custom checks to the built in WooCommerce checkout validation:
     19  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;
     21  // Check over a list of provided domains, to see if $user_email matches any of them:
     22  function bssorders_is_a_spam_order($fields)
     23  {
     24    // Setup the fields we're checking for spam:
     25    $billing_email = sanitize_email($fields['billing_email']);
     26    $billing_first_name = sanitize_text_field($fields['billing_first_name']);
     27
     28    // Provide the list of email domains we want to block:
     29    $blocked_email_domains = ['abbuzz.com', 'fakemail.com'];
     30    // Provide the list of first names we want to block:
     31    $blocked_names = ['aaaaa', 'bbbbb'];
     32
     33    // Set the default return of false:
     34    $is_a_spam_order = false;
     35
     36    // Compare users email domain with our list of blocked email domains:
     37    foreach ($blocked_email_domains as $blocked_email_domain) {
     38      // If a blocked email domain exists in the users email, return spam=true;
     39      if (strpos($billing_email, $blocked_email_domain) !== false) {
     40        $is_a_spam_order = true;
     41      }
    3942    }
    40     // Check if billing name or email domain is a specific string, if it is we'll decline the order:
    41     function action_woocommerce_validate_spam_checkout($fields, $errors)
    42     {
    43         $customer_name_to_block = 'bbbbb';
    44         if (
    45             $fields['billing_first_name'] == $customer_name_to_block
    46             ||
    47             (has_a_blocked_domain($fields['billing_email']) == true)
    48         ) {
    49             $errors->add('validation', 'Spam.');
    50         }
     43    foreach ($blocked_names as $blocked_name) {
     44      // If a blocked Name exists in the users email, return true;
     45      if (strpos($billing_first_name, $blocked_name) !== false) {
     46        $is_a_spam_order = true;
     47      }
    5148    }
     49    return $is_a_spam_order;
     50  }
     51  // Run the customers name & billing email through our func, report "Spam" if true:
     52  function action_woocommerce_validate_spam_checkout($fields, $errors)
     53  {
     54    if ((bssorders_is_a_spam_order($fields) == true)) {
     55      $errors->add('validation', __('Spam.', 'guwii-woo-block-spam-orders'));
     56    }
     57  }
    5258}
Note: See TracChangeset for help on using the changeset viewer.