Skip to content

Commit

Permalink
1.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ovx committed Aug 2, 2024
1 parent 6869aea commit ec922a1
Show file tree
Hide file tree
Showing 10 changed files with 177 additions and 59 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Having troubles? Please report in [Issues](https://github.com/altcha-org/wordpre
## Supported Integrations

* Contact Form 7
* Elementor Pro Forms
* Forminator
* GravityForms
* HTML Forms
Expand Down
9 changes: 5 additions & 4 deletions altcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
* Description: ALTCHA is a free, open-source CAPTCHA alternative that offers robust protection without using cookies, ensuring full GDPR compliance by design. It also provides invisible anti-spam and anti-bot protection through ALTCHA's API.
* Author: Altcha.org
* Author URI: https://altcha.org
* Version: 1.3.1
* Stable tag: 1.3.1
* Version: 1.4.0
* Stable tag: 1.4.0
* Requires at least: 5.0
* Requires PHP: 7.3
* Tested up to: 6.6
* License: GPLv2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
*/

define('ALTCHA_VERSION', '1.3.1');
define('ALTCHA_VERSION', '1.4.0');
define('ALTCHA_WEBSITE', 'https://altcha.org/');
define('ALTCHA_WIDGET_VERSION', '0.6.4');
define('ALTCHA_WIDGET_VERSION', '0.6.7');
define('ALTCHA_LANGUAGES', [
"bg" => "Bulgarian",
"ca" => "Catalan",
Expand Down Expand Up @@ -62,6 +62,7 @@

require plugin_dir_path( __FILE__ ) . './integrations/contact-form-7.php';
require plugin_dir_path( __FILE__ ) . './integrations/custom.php';
require plugin_dir_path( __FILE__ ) . './integrations/elementor.php';
require plugin_dir_path( __FILE__ ) . './integrations/forminator.php';
require plugin_dir_path( __FILE__ ) . './integrations/html-forms.php';
require plugin_dir_path( __FILE__ ) . './integrations/gravityforms.php';
Expand Down
10 changes: 10 additions & 0 deletions includes/core.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class AltchaPlugin

public static $option_integration_custom = "altcha_integration_custom";

public static $option_integration_elementor = "altcha_integration_elementor";

public static $option_integration_forminator = "altcha_integration_forminator";

public static $option_integration_gravityforms = "altcha_integration_gravityforms";
Expand Down Expand Up @@ -84,12 +86,15 @@ class AltchaPlugin
),
'div' => array(
'class' => array(),
'style' => array(),
),
'input' => array(
'class' => array(),
'id' => array(),
'name' => array(),
'type' => array(),
'value' => array(),
'style' => array(),
),
'noscript' => array(),
);
Expand Down Expand Up @@ -186,6 +191,11 @@ public function get_integration_custom()
return trim(get_option(AltchaPlugin::$option_integration_custom));
}

public function get_integration_elementor()
{
return trim(get_option(AltchaPlugin::$option_integration_elementor));
}

public function get_integration_forminator()
{
return trim(get_option(AltchaPlugin::$option_integration_forminator));
Expand Down
2 changes: 2 additions & 0 deletions includes/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

function altcha_plugin_active($name) {
switch ($name) {
case 'elementor':
return is_plugin_active('elementor/elementor.php');
case 'forminator':
return is_plugin_active('forminator/forminator.php');
case 'gravityforms':
Expand Down
26 changes: 26 additions & 0 deletions includes/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ function altcha_settings_init()
AltchaPlugin::$option_integration_custom
);

register_setting(
'altcha_options',
AltchaPlugin::$option_integration_elementor
);

register_setting(
'altcha_options',
AltchaPlugin::$option_integration_forminator
Expand Down Expand Up @@ -388,6 +393,27 @@ function altcha_settings_init()
)
);

add_settings_field(
'altcha_settings_elementor_integration_field',
'Elementor Pro Forms',
'altcha_settings_select_callback',
'altcha_admin',
'altcha_integrations_settings_section',
array(
"name" => AltchaPlugin::$option_integration_elementor,
"disabled" => !altcha_plugin_active('elementor'),
"spamfilter_options" => array(
"spamfilter",
"captcha_spamfilter",
),
"options" => array(
"" => "Disable",
"captcha" => "Captcha",
"captcha_spamfilter" => "Captcha + Spam Filter",
),
)
);

add_settings_field(
'altcha_settings_forminator_integration_field',
'Forminator',
Expand Down
16 changes: 16 additions & 0 deletions integrations/elementor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

if ( ! defined( 'ABSPATH' ) ) exit;

if (altcha_plugin_active('elementor')){
function altcha_register_form_field( $form_fields_registrar ) {
require_once(__DIR__ . '/elementor/field.php');

$form_fields_registrar->register(new \Elementor_Form_Altcha_Field());
}
$plugin = AltchaPlugin::$instance;
$mode = $plugin->get_integration_elementor();
if ($mode === 'captcha' || $mode === 'captcha_spamfilter') {
add_action('elementor_pro/forms/fields/register', 'altcha_register_form_field');
}
}
57 changes: 57 additions & 0 deletions integrations/elementor/field.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

if (!defined('ABSPATH')) exit;

if (!class_exists('\ElementorPro\Modules\Forms\Fields\Field_Base')) {
die();
}

class Elementor_Form_Altcha_Field extends \ElementorPro\Modules\Forms\Fields\Field_Base
{
public function get_type()
{
return 'altcha';
}

public function get_name()
{
return esc_html__('ALTCHA', 'altcha-spam-protection');
}

public function render($item, $item_index, $form)
{
$plugin = AltchaPlugin::$instance;
$mode = $plugin->get_integration_elementor();
if (empty($mode) || $mode === 'spamfilter') {
return '';
}
echo wp_kses(wp_nonce_field('altcha_verification', '_altchanonce', true, false), AltchaPlugin::$html_espace_allowed_tags);
echo wp_kses("<div style=\"flex-basis:100%\">" . $plugin->render_widget($mode, false) . "</div>", AltchaPlugin::$html_espace_allowed_tags);
// shadow element for error reporting
echo wp_kses('<input type="hidden" ' . $form->get_render_attribute_string('input' . $item_index) . '>', AltchaPlugin::$html_espace_allowed_tags);
}

public function validation($field, $record, $ajax_handler)
{
$plugin = AltchaPlugin::$instance;
$mode = $plugin->get_integration_elementor();
if (!empty($mode)) {
if ($mode === "captcha" || $mode === "captcha_spamfilter") {
if (wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['_altchanonce'])), 'altcha_verification') === false) {
$ajax_handler->add_error(
$field['id'],
esc_html__('Nonce verification failed.', 'altcha-spam-protection')
);
} else {
$altcha = isset($_POST['altcha']) ? trim(sanitize_text_field($_POST['altcha'])) : '';
if ($plugin->verify($altcha) === false) {
$ajax_handler->add_error(
$field['id'],
esc_html__('Verification failed.', 'altcha-spam-protection')
);
}
}
}
}
}
}
Loading

0 comments on commit ec922a1

Please sign in to comment.