Files
ogre-captcha/inc/location/class-comment-form.php
T
Cooper Dalrymple e8b8fc1871
Validate Build / validate-build (push) Failing after 35s
Locations and verification
2026-06-04 17:05:42 -05:00

54 lines
1.4 KiB
PHP

<?php
/**
* @package ogre-captcha
* @author cleverogre
* @copyright 2026 CleverOgre
* @license GLP-3.0-or-later
* @version 0.0.0
* @since 0.0.0
*/
namespace Ogre\Captcha\Location;
use Override;
use Ogre\Captcha\Location;
use Ogre\Captcha\Settings;
use WP_Error;
defined('ABSPATH') || exit;
final class CommentForm extends Location {
protected function __construct() {
parent::__construct(Settings::LOCATION_COMMENT_FORM);
}
#[Override]
public function activate(): void
{
add_action('comment_form_after_fields', [$this, 'render'], 1);
add_filter('preprocess_comment', [$this, 'process_form']);
}
public function process_form(array $commentdata):array {
// Don't process CAPTCHA for comment replies inside admin menu
if (isset($_REQUEST['action']) && 'replyto-comment' == $_REQUEST['action'] && (check_ajax_referer('replyto-comment', '_ajax_nonce', false) || check_ajax_referer('replyto-comment', '_ajax_nonce-replyto-comment', false))) {
return $comment;
}
// Don't do CAPTCHA for pingback/trackback
if ('' != $comment['comment_type'] && 'comment' != $comment['comment_type'] && 'review' != $comment['comment_type']) {
return $comment;
}
$errors = new WP_Error();
$this->process($errors);
$this->print_errors($errors);
return $commentdata;
}
}
CommentForm::instance();