// Wigmore Trading - CF7 spam gate + submission-data tools
// Analyse (read-only): /?wgspam=wgs91c4&mode=days&fid=393
// Backup+purge: /?wgspam=wgs91c4&mode=purge&fid=393&min=40 (admin only)
if ( ! defined('WGS_KEY') ) { define('WGS_KEY','wgs91c4'); define('WGS_CAP_CONTACT',3); define('WGS_CAP_OTHER',6); }

/* ---------------- honeypot field injected into every CF7 form ---------------- */
add_filter('wpcf7_form_elements', function($html){
return $html.''
.'';
});

function wgs_ip(){
$k = array('HTTP_CF_CONNECTING_IP','HTTP_X_REAL_IP','HTTP_X_FORWARDED_FOR','REMOTE_ADDR');
foreach($k as $x){ if(!empty($_SERVER[$x])){ $v=explode(',',$_SERVER[$x]); return trim($v[0]); } }
return '0.0.0.0';
}

function wgs_blob(){
$o='';
foreach($_POST as $k=>$v){ if(strpos($k,'_wpcf7')===0||$k==='wg_hp'||$k==='wg_ts') continue; if(is_string($v)) $o.=' '.$v; }
return $o;
}

/* ---------------- the gate ---------------- */
add_filter('wpcf7_spam', function($spam, $submission){
if ($spam) return $spam;
$why = '';

// 1. honeypot filled
if (!empty($_POST['wg_hp'])) $why = 'honeypot';

// 2. submitted impossibly fast (under 4s from render)
if (!$why && !empty($_POST['wg_ts'])) {
$el = time() - (int)$_POST['wg_ts'];
if ($el >= 0 && $el < 4) $why = 'too_fast'; } $blob = wgs_blob(); // 3. non-Latin scripts this business does not receive enquiries in if (!$why && preg_match('/[\x{0400}-\x{04FF}\x{4E00}-\x{9FFF}\x{3040}-\x{30FF}\x{0600}-\x{06FF}]/u', $blob)) $why = 'script'; // 4. link stuffing if (!$why && preg_match_all('#https?://#i', $blob) >= 2) $why = 'links';
if (!$why && preg_match('/\[url|\[link|get_contact_form()->id() : 0;
$cap = ($fid === 393) ? WGS_CAP_CONTACT : WGS_CAP_OTHER;
$key = 'wgs_'.md5(wgs_ip());
$n = (int)get_transient($key);
if ($n >= $cap) $why = 'rate';
else set_transient($key, $n+1, DAY_IN_SECONDS);
}

if ($why) {
// stop CFDB7 storing it too, so the digest counts stay honest
$GLOBALS['wgs_blocked'] = $why;
add_action('wpcf7_before_send_mail', 'wgs_block_storage', 1);
$log = (array)get_option('wgs_log', array());
$d = gmdate('Y-m-d');
if (!isset($log[$d])) $log[$d] = array();
$log[$d][$why] = isset($log[$d][$why]) ? $log[$d][$why]+1 : 1;
if (count($log) > 40) { $log = array_slice($log, -40, null, true); }
update_option('wgs_log', $log, false);
return true;
}
return $spam;
}, 10, 2);

function wgs_block_storage(){
global $wp_filter;
if (empty($GLOBALS['wgs_blocked'])) return;
if (isset($wp_filter['wpcf7_before_send_mail'])) {
foreach ($wp_filter['wpcf7_before_send_mail']->callbacks as $prio => $cbs) {
foreach ($cbs as $id => $cb) {
if (is_string($id) && stripos($id, 'cfdb7') !== false) {
unset($wp_filter['wpcf7_before_send_mail']->callbacks[$prio][$id]);
}
}
}
}
}

/* ---------------- admin tools ---------------- */
add_action('init', function(){
if (empty($_GET['wgspam']) || $_GET['wgspam'] !== WGS_KEY) return;
if (!current_user_can('manage_options')) return;
global $wpdb;
$t = $wpdb->prefix.'db7_forms';
$fid = isset($_GET['fid']) ? (int)$_GET['fid'] : 393;
$mode= isset($_GET['mode']) ? $_GET['mode'] : 'days';

if ($mode === 'log') {
wp_die('

'.esc_html(print_r(get_option('wgs_log', array()), true)).'

');
}

if ($mode === 'days') {
$rows = $wpdb->get_results($wpdb->prepare(
"SELECT DATE(form_date) d, COUNT(*) c FROM $t WHERE form_id=%d GROUP BY d ORDER BY c DESC", $fid));
$tot = 0; $o = ''; $buckets = array('1-5'=>0,'6-20'=>0,'21-40'=>0,'41-100'=>0,'101-500'=>0,'500+'=>0);
$rowsIn = array('1-5'=>0,'6-20'=>0,'21-40'=>0,'41-100'=>0,'101-500'=>0,'500+'=>0);
foreach ($rows as $r) {
$c = (int)$r->c; $tot += $c;
$b = $c<=5?'1-5':($c<=20?'6-20':($c<=40?'21-40':($c<=100?'41-100':($c<=500?'101-500':'500+')))); $buckets[$b]++; $rowsIn[$b] += $c; } $o .= "form_id=$fid total_rows=$tot distinct_days=".count($rows)."\n\n"; $o .= sprintf("%-10s %8s %12s\n", 'per-day', 'days', 'rows'); foreach ($buckets as $b=>$n) $o .= sprintf("%-10s %8d %12d\n", $b, $n, $rowsIn[$b]);
$o .= "\nTop 25 days:\n";
$i=0; foreach ($rows as $r) { if($i++>=25) break; $o .= sprintf(" %s %6d\n", $r->d, $r->c); }
wp_die('

'.esc_html($o).'

');
}

if ($mode === 'purge') {
$min = isset($_GET['min']) ? (int)$_GET['min'] : 0;
if ($min < 10) wp_die('Refusing: min must be >= 10.');
$bak = $wpdb->prefix.'db7_forms_sbak_20261111';
$wpdb->query("CREATE TABLE IF NOT EXISTS $bak LIKE $t");
$sql = $wpdb->prepare(
"INSERT INTO $bak SELECT f.* FROM $t f
JOIN (SELECT DATE(form_date) d FROM $t WHERE form_id=%d GROUP BY d HAVING COUNT(*)>=%d) x
ON DATE(f.form_date)=x.d
WHERE f.form_id=%d", $fid, $min, $fid);
$ins = $wpdb->query($sql);
$del = $wpdb->query($wpdb->prepare(
"DELETE f FROM $t f
JOIN (SELECT DATE(form_date) d FROM $bak WHERE form_id=%d GROUP BY d) x
ON DATE(f.form_date)=x.d
WHERE f.form_id=%d", $fid, $fid));
$left = (int)$wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $t WHERE form_id=%d", $fid));
wp_die('

backed_up='.(int)$ins.'  deleted='.(int)$del.'  remaining_for_form='.$left
      .'  backup_table='.esc_html($bak).'

');
}
}, 2);

LOS Lagos HQ ACC Accra LON London NYC New York
Chat on WhatsApp sales@wigmoretrading.com
Import · Export · Wholesale · Logistics

From West Africa
to the world.

Wigmore Trading is West Africa's one-stop trade partner. We source, ship, warehouse, distribute and market products for brands, importers and retailers — from first quote to shelf.

210,000+SME customers
12,000 ft²Lagos wholesale store
4 officesNG · GH · UK · US
LONNYCROTDXBSHAJNB LOS · LAGOS HQ
Live network LOS → LON · NYC · DXB · SHA · JNB
What we do

One partner. The whole supply chain.

Most trading companies do one link in the chain. We run all five — one contract, one point of contact, and no hand-off failures between suppliers, shippers and sellers.

STAGE 01

Source

Product sourcing and procurement from Nigeria, Ghana and global suppliers — with quality inspection before anything moves.

Agri & commodities →
STAGE 02

Ship

Air cargo, container handling and LCL sea freight, managed end-to-end through our dedicated shipping arm.

Shipping & logistics →
STAGE 03

Store

Temperature-controlled, pallet-shelved warehousing in Lagos. Sensitive goods are inspected and probed on arrival.

Store & sell →
STAGE 04

Distribute

Daily deliveries direct to supermarkets, caterers and retailers across Lagos and West Africa with our own fleet.

Distribution →
STAGE 05

Market

Product launches, exhibitions, influencer campaigns and a sales team that knows how to build a brand in Nigeria.

Marketing & sales →
Who we serve

Built around your side of the trade.

210K
Wigmore Wholesale

Reach 210,000+ SME buyers across Africa.

Whether you're a small importer or a multinational brand, listing on wigmorewholesale.com puts your products in front of West Africa's fastest-growing wholesale cash & carry network — online and from our 12,000 ft² Lagos store.

24/7Ordering reliability
1000sProduct lines in stock
NG + GHSourced locally first
DoorDirect delivery included
Product range

Everything for your business, under one roof.

Consistent availability, exceptional lead times and maximum shelf life across our core categories.

Food products Groceries Health & beauty aids Confectionery Toiletries Household items Cosmetics Wines & spirits Baby care Hair & dental care Bath care Feminine & gents hygiene Stationery Batteries & hardware Agri-commodities
Latest insights

From the trade floor.

All news & insights
Energy Products and Electricity Projects from Spain: Sourcing Brief
Import & Export GuidesGuide

Energy Products and Electricity Projects from Spain: Sourcing Brief

Energy enquiries can concern a physical product, industrial equipment or an electricity-market project. The parties, permits, technical requirements and delivery arrangements differ. Wigmore Trading accepts commercial research and sourcing-coordination enquiries, subject to confirming the actual scope, lawful parties, product eligibility and feasible route. No live energy allocation or trading licence is claimed here. Identify the […]

Read article →
Civil Aircraft, Ships and Rail Equipment from Spain: Procurement Guide
Import & Export GuidesGuide

Civil Aircraft, Ships and Rail Equipment from Spain: Procurement Guide

Civil transport assets require ownership, technical and regulatory review before a commercial movement is arranged. Aircraft, ships, railway equipment and their parts have different documentation and professional responsibilities. Wigmore Trading accepts sourcing-research and coordination enquiries, with availability, supplier authority, permissions, feasibility and terms confirmed for the actual project. Define the civil purpose and asset State […]

Read article →
Beauty, Perfume and Personal Care from Spain: Wholesale Sourcing
Import & Export GuidesGuide

Beauty, Perfume and Personal Care from Spain: Wholesale Sourcing

Sourcing beauty and personal-care products from Spain means identifying the exact labelled product, lawful source and intended market. Cosmetics, perfumes, hair preparations, shaving products and industrial scented mixtures should not be treated as interchangeable. Wigmore Trading can discuss commercial sourcing and coordination, subject to confirming product availability, eligibility and terms. Define the product and buyer […]

Read article →
Start trading with us

Tell us what you need to move.

Book a free 15-minute consultation and we'll map the fastest route from your product to its market — sourcing, shipping, storage, distribution or all of it.

WhatsApp Chat