I want to do some testing using the above filter. Specifically, I am currently trying to total up Itheme and attacks from my Cloudflare bridge plugin
I have got it to pull the i-theme stuff fine using a model if seem before but I’ve tried every variation I can think of to pull cfmwp-attacks, is there a way to pull custom tokens (there in the array and working in the report but I am trying to display a total security count and can’t because I can’t get cfmwp-attacks or any custom added token to “add” it just doesn’t seem to pull through do I need to add something to the plugins or is there another way to pull this data i.e directly out of the generated tokens?
add_filter( 'mainwp_pro_reports_addition_custom_tokens', 'ithemes_and_cloudflare_total_tokens', 10, 3 );
function ithemes_and_cloudflare_total_tokens( $tokens, $site_id, $data ) {
// Log all tokens for debugging
error_log( 'Available Tokens: ' . print_r( $tokens, true ) );
if ( is_array( $data ) && isset( $data[$site_id] ) ) {
// Access existing tokens directly
$ithemes_blocked_count = isset( $data[$site_id]['other_tokens_data']['body']['[ithemes.blocked.count]'] )
? intval( $data[$site_id]['other_tokens_data']['body']['[ithemes.blocked.count]'] )
: 0;
$ithemes_lockout_count = isset( $data[$site_id]['other_tokens_data']['body']['[ithemes.lockout.count]'] )
? intval( $data[$site_id]['other_tokens_data']['body']['[ithemes.lockout.count]'] )
: 0;
$cfmwp_attacks_count = isset( $tokens['[cfmwp-attacks]'] )
? intval( $tokens['[cfmwp-attacks]'] )
: 0;
// Debugging individual token values
error_log( "Blocked: {$ithemes_blocked_count}, Lockouts: {$ithemes_lockout_count}, Attacks: {$cfmwp_attacks_count}" );
// Calculate total
$total_security_issues = $ithemes_blocked_count + $ithemes_lockout_count + $cfmwp_attacks_count;
// Add the total token
$tokens['[security.issues.total]'] = $total_security_issues;
}
return $tokens;
}
Thanks in Advance