Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New. SpamProtection. Added shortcode for easily third party integration. #531

Merged
merged 4 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cleantalk.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
Domain Path: /i18n
*/

use Cleantalk\Antispam\ProtectByShortcode;
use Cleantalk\ApbctWP\Activator;
use Cleantalk\ApbctWP\AdminNotices;
use Cleantalk\ApbctWP\Antispam\EmailEncoder;
Expand Down Expand Up @@ -366,6 +367,9 @@ function apbct_alt_session__save__WP_AJAX()
require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-integrations-by-hook.php');
require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-integrations-by-class.php');

// Form protection by shortcode
new ProtectByShortcode();

// WP Delicious integration
add_filter('delicious_recipes_process_registration_errors', 'apbct_wp_delicious', 10, 4);

Expand Down
51 changes: 51 additions & 0 deletions lib/Cleantalk/Antispam/ProtectByShortcode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace Cleantalk\Antispam;

use Cleantalk\ApbctWP\Variables\Server;

class ProtectByShortcode
{
public function __construct()
{
add_filter('ct_wordpress_protect_from_spam', array($this, 'protectByShortcode'), 10, 2);
AntonV1211 marked this conversation as resolved.
Show resolved Hide resolved
}

public function protectByShortcode($data, $options = [])
{
$output = [
'is_spam' => false,
'message' => '',
];

$input_array = apply_filters('apbct__filter_post', $data);
$data = ct_gfa($input_array);

$base_call_data = array(
alexandergull marked this conversation as resolved.
Show resolved Hide resolved
'message' => ! empty($data['message']) ? json_encode($data['message']) : '',
'sender_email' => ! empty($data['email']) ? $data['email'] : '',
'sender_nickname' => ! empty($data['nickname']) ? $data['nickname'] : '',
'event_token' => ! empty($data['event_token']) ? $data['event_token'] : '',
'post_info' => array(
'post_url' => Server::get('HTTP_REFERER'),
),
);
$result = apbct_base_call($base_call_data, false);
$ct_result = isset($result['ct_result']) ? $result['ct_result'] : null;

$is_spam = $ct_result !== null && $ct_result->allow !== 1;

if (isset($options['redirect_to_block_page']) && $options['redirect_to_block_page'] && $is_spam) {
AntonV1211 marked this conversation as resolved.
Show resolved Hide resolved
wp_die(isset($ct_result->comment) ? $ct_result->comment : __('Blocked by CleanTalk'), __('Forbidden'), array('response' => 403));
}

if ($is_spam) {
$output = [
'is_spam' => true,
'message' => $ct_result->comment,
];
}

return $output;
}
}
Loading