Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions inc/cleantalk-integrations-by-hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,11 @@
'setting' => 'forms__contact_forms_test',
'ajax' => true
),
'Amelia' => array(
'hook' => 'wpamelia_api',
'setting' => 'forms__contact_forms_test',
'ajax' => true
),
);

add_action('plugins_loaded', function () use ($apbct_active_integrations) {
Expand Down
61 changes: 61 additions & 0 deletions lib/Cleantalk/Antispam/Integrations/Amelia.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

namespace Cleantalk\Antispam\Integrations;

class Amelia extends IntegrationBase
{
public function doPrepareActions($argument)
{
$call = isset($_GET['call']) ? (string) $_GET['call'] : '';

if ( $call !== '/bookings' ) {
return false;
}

return true;
}

public function getDataForChecking($argument)
{
$raw = file_get_contents('php://input');
if ( ! $raw ) {
return null;
}

$payload = json_decode($raw, true);
if ( ! is_array($payload) ) {
return null;
}

$email = '';
if ( ! empty($payload['customer']['email']) ) {
$email = (string) $payload['customer']['email'];
} elseif ( ! empty($payload['bookings'][0]['customer']['email']) ) {
$email = (string) $payload['bookings'][0]['customer']['email'];
} elseif ( ! empty($payload['email']) ) {
$email = (string) $payload['email'];
}

if ( ! $email ) {
return null;
}

return array('email' => $email, 'sender_nickname' => 'stop_emai');
}

public function doBlock($message)
{
remove_action('wp_ajax_wpamelia_api', array('AmeliaBooking\\Plugin', 'wpAmeliaApiCall'));
remove_action('wp_ajax_nopriv_wpamelia_api', array('AmeliaBooking\\Plugin', 'wpAmeliaApiCall'));

header('Content-Type: application/json; charset=utf-8');
echo wp_json_encode(array(
'message' => $message,
'data' => array(
'message' => $message,
'reason' => $message,
),
));
exit;
}
}
Loading