Skip to content

Commit

Permalink
1.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ovx committed Aug 8, 2024
1 parent e33053c commit 5e662f2
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 21 deletions.
16 changes: 13 additions & 3 deletions altcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
* 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.5.0
* Stable tag: 1.5.0
* Version: 1.6.0
* Stable tag: 1.6.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.5.0');
define('ALTCHA_VERSION', '1.6.0');
define('ALTCHA_WEBSITE', 'https://altcha.org/');
define('ALTCHA_WIDGET_VERSION', '0.6.7');
define('ALTCHA_LANGUAGES', [
Expand Down Expand Up @@ -78,6 +78,8 @@
register_activation_hook(__FILE__, 'altcha_activate');
register_deactivation_hook(__FILE__, 'altcha_deactivate');

add_action('wp_enqueue_scripts', 'altcha_enqueue_widget_scripts');

add_shortcode(
'altcha',
function ($attrs) {
Expand Down Expand Up @@ -105,3 +107,11 @@ function altcha_activate()
function altcha_deactivate()
{
}

function altcha_enqueue_widget_scripts()
{
if (AltchaPlugin::$instance->has_active_integrations()) {
altcha_enqueue_scripts();
altcha_enqueue_styles();
}
}
19 changes: 19 additions & 0 deletions includes/core.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,25 @@ public function get_translations($language = null)
return ALTCHA_VERSION_TRANSLATIONS[$language] ?: ALTCHA_VERSION_TRANSLATIONS["en"];
}


public function has_active_integrations()
{
$integrations = array(
$this->get_integration_contact_form_7(),
$this->get_integration_custom(),
$this->get_integration_elementor(),
$this->get_integration_forminator(),
$this->get_integration_gravityforms(),
$this->get_integration_html_forms(),
$this->get_integration_wordpress_register(),
$this->get_integration_wordpress_login(),
$this->get_integration_wordpress_reset_password(),
$this->get_integration_wordpress_comments(),
$this->get_integration_wpforms(),
);
return in_array("captcha", $integrations) || in_array("captcha_spamfilter", $integrations) || in_array("shortcode", $integrations);
}

public function random_secret()
{
return bin2hex(random_bytes(12));
Expand Down
1 change: 1 addition & 0 deletions includes/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ function altcha_settings_init()
"" => "Disable",
"captcha" => "Captcha",
"captcha_spamfilter" => "Captcha + Spam Filter",
"shortcode" => "Shortcode",
),
)
);
Expand Down
14 changes: 10 additions & 4 deletions integrations/contact-form-7.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
if ( ! defined( 'ABSPATH' ) ) exit;

if (altcha_plugin_active('contact-form-7')) {
add_filter('wpcf7_form_elements', 'do_shortcode');

add_filter(
'wpcf7_form_elements',
function ($elements) {
Expand All @@ -12,9 +14,13 @@ function ($elements) {
$elements .= wp_nonce_field('altcha_verification', '_altchanonce', true, false);
}
if ($mode === "captcha" || $mode === "captcha_spamfilter") {
altcha_enqueue_scripts();
altcha_enqueue_styles();
$elements .= wp_kses($plugin->render_widget($mode), AltchaPlugin::$html_espace_allowed_tags);
$button = '<input class="wpcf7-form-control wpcf7-submit ';
$widget = wp_kses($plugin->render_widget($mode, true), AltchaPlugin::$html_espace_allowed_tags);
if (str_contains($elements, $button)) {
$elements = str_replace($button, $widget . $button, $elements);
} else {
$elements .= $widget;
}
}
return $elements;
},
Expand All @@ -32,7 +38,7 @@ function ($spam) {
$plugin = AltchaPlugin::$instance;
$mode = $plugin->get_integration_contact_form_7();
if (!empty($mode) && (wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['_altchanonce'])), 'altcha_verification') !== false || $nonceok)) {
if ($mode === "captcha" || $mode === "captcha_spamfilter") {
if ($mode === "captcha" || $mode === "captcha_spamfilter" || $mode === "shortcode") {
$altcha = isset($_POST['altcha']) ? trim(sanitize_text_field($_POST['altcha'])) : '';
return $plugin->verify($altcha) === false;
}
Expand Down
2 changes: 0 additions & 2 deletions integrations/custom.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ function () {
$plugin = AltchaPlugin::$instance;
$mode = $plugin->get_integration_custom();
if ($mode === 'captcha' || $mode === 'captcha_spamfilter') {
altcha_enqueue_scripts();
altcha_enqueue_styles();
wp_enqueue_script(
'altcha-widget-custom',
AltchaPlugin::$custom_script_src,
Expand Down
29 changes: 29 additions & 0 deletions integrations/elementor/field.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,35 @@ public function render($item, $item_index, $form)
echo wp_kses('<input type="hidden" ' . $form->get_render_attribute_string('input' . $item_index) . '>', AltchaPlugin::$html_espace_allowed_tags);
}

public function update_controls($widget)
{
$elementor = \ElementorPro\Plugin::elementor();
$control_data = $elementor->controls_manager->get_control_from_stack($widget->get_unique_name(), 'form_fields');
if (is_wp_error($control_data)) {
return;
}
$control_data = $this->remove_control_form_field_type('required', $control_data);
$widget->update_control('form_fields', $control_data);
}

private function remove_control_form_field_type($control_name, $control_data)
{
foreach ($control_data['fields'] as $index => $field) {
if ($control_name !== $field['name']) {
continue;
}
foreach ($field['conditions']['terms'] as $condition_index => $terms) {
if (!isset($terms['name']) || 'field_type' !== $terms['name'] || !isset($terms['operator']) || '!in' !== $terms['operator']) {
continue;
}
$control_data['fields'][$index]['conditions']['terms'][$condition_index]['value'][] = $this->get_type();
break;
}
break;
}
return $control_data;
}

public function validation($field, $record, $ajax_handler)
{
$plugin = AltchaPlugin::$instance;
Expand Down
2 changes: 0 additions & 2 deletions integrations/forminator.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ function altcha_forminator_render_widget($html)
$plugin = AltchaPlugin::$instance;
$mode = $plugin->get_integration_forminator();
if ($mode === "captcha" || $mode === "captcha_spamfilter") {
altcha_enqueue_scripts();
altcha_enqueue_styles();
$elements = wp_kses($plugin->render_widget($mode, true), AltchaPlugin::$html_espace_allowed_tags);
return str_replace('<button class="forminator-button ', $elements . '<button class="forminator-button ', $html);
}
Expand Down
2 changes: 0 additions & 2 deletions integrations/gravityforms/field.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ public function get_field_input($form, $value = '', $entry = null)
. '<div><span>' . __("ALTCHA placeholder", 'altcha-spam-protection') . '</span></div>'
. '</div>';
} else {
altcha_enqueue_scripts();
altcha_enqueue_styles();
$widget_html = wp_kses($plugin->render_widget($mode), AltchaPlugin::$html_espace_allowed_tags);
}
return sprintf("<div class='ginput_container ginput_container_%s gfield--type-html'>%s</div>", $this->type, $widget_html);
Expand Down
2 changes: 0 additions & 2 deletions integrations/html-forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ function ($html) {
$html = str_replace('</form>', wp_nonce_field('altcha_verification', '_altchanonce') . '</form>', $html);
}
if ($mode === "captcha" || $mode === "captcha_spamfilter") {
altcha_enqueue_scripts();
altcha_enqueue_styles();
return str_replace('</form>', wp_kses($plugin->render_widget($mode), AltchaPlugin::$html_espace_allowed_tags) . '</form>', $html);
}
return $html;
Expand Down
2 changes: 0 additions & 2 deletions integrations/wordpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,6 @@ function ($comment) {

function altcha_wordpress_comments_render_widget($mode, $full_width = false)
{
altcha_enqueue_scripts();
altcha_enqueue_styles();
$plugin = AltchaPlugin::$instance;
echo wp_kses(wp_nonce_field('altcha_verification', '_altchanonce'), AltchaPlugin::$html_espace_allowed_tags);
echo wp_kses($plugin->render_widget($mode, true), AltchaPlugin::$html_espace_allowed_tags);
Expand Down
2 changes: 0 additions & 2 deletions integrations/wpforms.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ function () {
echo wp_kses(wp_nonce_field('altcha_verification', '_altchanonce'), AltchaPlugin::$html_espace_allowed_tags);
}
if ($mode === "captcha" || $mode === "captcha_spamfilter") {
altcha_enqueue_scripts();
altcha_enqueue_styles();
echo wp_kses($plugin->render_widget($mode, true), AltchaPlugin::$html_espace_allowed_tags);
}
},
Expand Down
8 changes: 6 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
Tags: altcha, captcha, spam, anti-spam, anti-bot, antispam, recaptcha, hcaptcha, gdpr
Author: Altcha.org
Author URI: https://altcha.org
Version: 1.5.0
Stable tag: 1.5.0
Version: 1.6.0
Stable tag: 1.6.0
Requires at least: 5.0
Requires PHP: 7.3
Tested up to: 6.6
Expand Down Expand Up @@ -94,6 +94,10 @@ All source code for the plugin, and the ALTCHA widget is available on GitHub. In

== Changelog ==

= 1.6.0 =
* Fix Elementor Pro Forms widget rendering
* Fix Contact Form 7 widget position and shortcode support

= 1.5.0 =
* Fix REST base URL (+ REST prefix removed from settings) [#13]

Expand Down

0 comments on commit 5e662f2

Please sign in to comment.