Changeset 3012514
- Timestamp:
- 12/20/2023 03:11:32 PM (2 years ago)
- Location:
- block-specific-spam-woo-orders/trunk
- Files:
-
- 2 edited
-
readme.txt (modified) (2 diffs)
-
woo-block-spam-orders.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
block-specific-spam-woo-orders/trunk/readme.txt
r2806972 r3012514 3 3 Tags: woocommerce,woo,block,spam,orders 4 4 Requires at least: 5.1 5 Tested up to: 6. 15 Tested up to: 6.4.2 6 6 Requires PHP: 5.4 7 7 Stable tag: 4.3 … … 25 25 == Changelog == 26 26 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 27 32 = 0.6 = 28 33 * 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 6 6 * Description: A quick plugin to block on-going issues with spam WooCommerce orders November 2020 7 7 * Author: guwii 8 * Version: 0. 68 * Version: 0.7 9 9 * Author URI: https://guwii.com 10 10 * License: GPL3+ 11 11 * Text Domain: guwii-woo-block-spam-orders 12 12 * WC requires at least: 4.3 13 * WC tested up to: 7.013 * WC tested up to: 8.4 14 14 */ 15 15 16 16 // Only use this plugin if WooCommerce is active 17 17 if (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); 20 20 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 } 39 42 } 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 } 51 48 } 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 } 52 58 }
Note: See TracChangeset
for help on using the changeset viewer.