Skip to content

Instantly share code, notes, and snippets.

@Zodiac1978
Last active January 7, 2024 13:33
Show Gist options
  • Save Zodiac1978/1d0f017a4486d917703eac4a8e4f5d0f to your computer and use it in GitHub Desktop.
Save Zodiac1978/1d0f017a4486d917703eac4a8e4f5d0f to your computer and use it in GitHub Desktop.
Repair AJAX comments for Antispam Bee in Streamtube theme (and maybe many more) - work in progress
<?php
/**
* Plugin Name: Repair AJAX comments for Antispam Bee
* Description: Add honeypot check and enable AJAX for Antispam Bee.
* Plugin URI: https://torstenlandsiedel.de
* Version: 1.0.0
* Author: Torsten Landsiedel
* Author URI: https://torstenlandsiedel.de
* Licence: GPL 2
* License URI: http://opensource.org/licenses/GPL-2.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
/**
* Repair the honyepot check for default comments.
*/
function asb_repair_ajax_comments() {
// Get post ID.
$post_id = (int) Antispam_Bee::get_key( $_POST, 'comment_post_ID' );
// Bail early if not in comment context.
if ( 0 === $post_id ) {
return;
}
// Create secret with post ID.
$secret = Antispam_Bee::get_secret_id_for_post( $post_id );
// Read honeypot and comment field.
$hidden_field = Antispam_Bee::get_key( $_POST, 'comment' );
$plugin_field = Antispam_Bee::get_key( $_POST, $secret );
// Compare and maybe fix fields.
if ( empty( $hidden_field ) && ! empty( $plugin_field ) ) {
$_POST['comment'] = $plugin_field;
unset( $_POST[ $secret ] );
} else {
// If nothing is fixed, no comment is possible, so nothing to do here.
}
}
if ( class_exists( 'Antispam_Bee' ) ) {
// Enable AJAX through disabling the block.
add_filter( 'antispam_bee_disallow_ajax_calls', '__return_false' );
// Switch comment content to repair honeypot check.
add_action( 'init', 'asb_repair_ajax_comments' ); // Very early hook.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment