Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save harryfear/c0996b716757cace22dd065db3bc4538 to your computer and use it in GitHub Desktop.
Save harryfear/c0996b716757cace22dd065db3bc4538 to your computer and use it in GitHub Desktop.
// Check if WPForms is active
if ( class_exists( 'WPForms' ) ) {
// // Check if any active plugins contain the word "cache" or "caching"
if ( wpforms_has_caching_plugins() ) {
// Hook into the admin_notices action to display the warning banner
add_action('admin_notices', 'check_wpforms_for_antispam');
}
}
// Function to check if any active plugins contain the word "cache" or "caching"
function wpforms_has_caching_plugins() {
// Get all active plugins
$active_plugins = get_option( 'active_plugins' );
// Loop through each active plugin
foreach ( $active_plugins as $plugin ) {
// Check if the plugin name contains the word "cache" or "caching"
if ( stripos( $plugin, 'cache' ) !== false || stripos( $plugin, 'caching' ) !== false ) {
return true;
}
}
return false;
}
function check_wpforms_for_antispam() {
// Check if the current user is an admin.
if ( is_admin() && current_user_can('administrator') ) {
// Get all forms using WPForms API.
$forms = wpforms()->form->get();
// Flag to track if any form has anti-spam enabled.
$anti_spam_enabled = false;
// Loop through the forms to check for anti-spam settings.
foreach ($forms as $form) {
$settings = wpforms_decode($form->post_content);
// Check if anti-spam is enabled for the form.
if (!empty($settings['settings']['antispam'])) {
$anti_spam_enabled = true;
break;
}
}
// If any form has anti-spam enabled, show the warning banner.
if ($anti_spam_enabled) {
?>
<div class="notice notice-error is-dismissible wpforms-anti-spam-warning">
<p><strong>Warning:</strong> One or more WPForms forms have anti-spam protection enabled; this feature doesn't work nicely or safely with caching plugins.</p>
</div>
<?php
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment