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

Procatcha support #786

Merged
merged 3 commits into from
Nov 7, 2024
Merged
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
10 changes: 10 additions & 0 deletions assets/src/js/admin/form-editor/field-forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,14 @@ forms.number = function (config) {
]
}

forms.procaptcha = function (config) {
config.placeholder = ''
config.label = ''
config.wrap = false
config.required = false
config.type = 'hidden'

return []
}

module.exports = forms
9 changes: 9 additions & 0 deletions assets/src/js/admin/form-editor/field-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,15 @@ function registerCustomFields (lists) {
title: i18n.submitButton
}, true)

register(i18n.formFields, {
name: 'procaptcha',
type: 'procaptcha',
label: 'Procaptcha',
title: 'Procaptcha',
showLabel: false,
required: true
}, true)

// register lists choice field
choices = {}
for (const key in lists) {
Expand Down
2 changes: 2 additions & 0 deletions autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
'MC4WP_Ninja_Forms_Integration' => __DIR__ . '/integrations/ninja-forms/class-ninja-forms.php',
'MC4WP_Ninja_Forms_V2_Integration' => __DIR__ . '/integrations/ninja-forms-2/class-ninja-forms.php',
'MC4WP_Plugin' => __DIR__ . '/includes/class-plugin.php',
'MC4WP_Procaptcha_Integration' => __DIR__ . '/integrations/prosopo-procaptcha/class-procaptcha-integration.php',
'MC4WP_Procaptcha' => __DIR__ . '/integrations/prosopo-procaptcha/class-procaptcha.php',
'MC4WP_Queue' => __DIR__ . '/includes/class-queue.php',
'MC4WP_Queue_Job' => __DIR__ . '/includes/class-queue-job.php',
'MC4WP_Registration_Form_Integration' => __DIR__ . '/integrations/wp-registration-form/class-registration-form.php',
Expand Down
2 changes: 2 additions & 0 deletions includes/admin/class-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,8 @@ public function show_generals_setting_page()
}

$obfuscated_api_key = mc4wp_obfuscate_string($api_key);
$is_procaptcha_configured = MC4WP_Procaptcha::get_instance()->is_enabled();

require MC4WP_PLUGIN_DIR . '/includes/views/general-settings.php';
}

Expand Down
34 changes: 34 additions & 0 deletions includes/views/general-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,40 @@
?>
</td>

<tr valign="top">
<th scope="row"><label><?php echo esc_html__('Procaptcha', 'mailchimp-for-wp'); ?></label></th>
<td>
<?php
if (true === $is_procaptcha_configured) {
?>
<span class="mc4wp-status positive"><?php echo esc_html__('CONFIGURED', 'mailchimp-for-wp'); ?></span>
<?php
} else {
?>
<span class="mc4wp-status neutral"><?php echo esc_html__('NOT CONFIGURED', 'mailchimp-for-wp'); ?></span>
<?php
}
?>
<?php
$procaptcha_settings_url = admin_url('admin.php?page=mailchimp-for-wp-integrations&integration=prosopo-procaptcha');
?>
<p class="description" style="padding:15px;">
<?php
printf(
// translators: %1$s is the opening <a> tag, %2$s is the closing </a> tag, %3$s is the opening <a> tag, %4$s is the closing </a> tag.
esc_html__(
'Click %1$s here %2$s to configure %3$s Procaptcha%4$s, privacy-friendly and GDPR-compliant anti-bot protection.',
'mailchimp-for-wp'
),
'<a href="' . esc_html($procaptcha_settings_url) . '">',
dannyvankooten marked this conversation as resolved.
Show resolved Hide resolved
'</a>',
'<a target="_blank" href="https://prosopo.io/">',
'</a>'
);
?>
</p>
</td>

</tr>

</table>
Expand Down
2 changes: 2 additions & 0 deletions integrations/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ function mc4wp_admin_after_integration_settings(MC4WP_Integration $integration,
mc4wp_register_integration('memberpress', 'MC4WP_MemberPress_Integration');
mc4wp_register_integration('affiliatewp', 'MC4WP_AffiliateWP_Integration');
mc4wp_register_integration('give', 'MC4WP_Give_Integration');

require __DIR__ . '/woocommerce/woocommerce.php';
require __DIR__ . '/prosopo-procaptcha/bootstrap.php';

mc4wp_register_integration('custom', 'MC4WP_Custom_Integration', true);
require __DIR__ . '/ninja-forms/bootstrap.php';
Expand Down
148 changes: 148 additions & 0 deletions integrations/prosopo-procaptcha/admin-after.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
<?php

$opts = $opts ?? array();
$opts = true === is_array($opts) ?
$opts :
array();

$site_key = $opts['site_key'] ?? '';
$secret_key = $opts['secret_key'] ?? '';
$enabled = $opts['enabled'] ?? '0';
$display_for_authorized = $opts['display_for_authorized'] ?? '0';
$theme = $opts['theme'] ?? '';
$type = $opts['type'] ?? '';

$theme_options = array(
'light' => esc_html__('Light', 'mailchimp-for-wp'),
'dark' => esc_html__('Dark', 'mailchimp-for-wp'),
);
$type_options = array(
'frictionless' => esc_html__('Frictionless', 'mailchimp-for-wp'),
'pow' => esc_html__('Pow', 'mailchimp-for-wp'),
'image' => esc_html__('Image', 'mailchimp-for-wp'),
);

?>

<?php
if ('1' === $enabled) {
?>
<p>
<?php echo esc_html__('Preview: if the credentials are valid, you should be able to complete the captcha below:', 'mailchimp-for-wp'); ?>
</p>
<?php
}
$procaptcha_api = MC4WP_Procaptcha::get_instance();
echo $procaptcha_api->print_captcha_element(true, true);
?>

<input class="prosopo-procaptcha__enabled-setting" type="hidden" name="mc4wp_integrations[prosopo-procaptcha][enabled]" value="<?php echo esc_attr($enabled); ?>">

<table class="form-table">
<tbody>
<tr valign="top">
<th scope="row"><?php echo esc_html__('Site Key', 'mailchimp-for-wp'); ?></th>
<td class="nowrap integration-toggles-wrap">
<label>
<input class="widefat prosopo-procaptcha__site-key" type="text" name="mc4wp_integrations[prosopo-procaptcha][site_key]"
placeholder="<?php echo esc_attr__('Enter your site key', 'mailchimp-for-wp'); ?>"
value="<?php echo esc_attr($site_key); ?>">
</label>
<p class="description">
<?php
echo
sprintf(
// translators: %1$s: opening anchor tag, %2$s: closing anchor tag
esc_html__('The API key for connecting with your Procaptcha account. %1$s Get your Site key here %2$s', 'mailchimp-for-wp'),
'<a href="https://portal.prosopo.io/" target="_blank">',
'</a>'
);
?>
</p>
</td>
</tr>
<tr valign="top">
<th scope="row"><?php echo esc_html__('Secret Key', 'mailchimp-for-wp'); ?></th>
<td class="nowrap integration-toggles-wrap">
<label>
<input class="widefat prosopo-procaptcha__secret-key" type="password" name="mc4wp_integrations[prosopo-procaptcha][secret_key]"
placeholder="<?php echo esc_attr__('Enter your secret key', 'mailchimp-for-wp'); ?>"
value="<?php echo esc_attr($secret_key); ?>">
</label>
</td>
</tr>
<tr valign="top">
<th scope="row"><?php echo esc_html__('Theme', 'mailchimp-for-wp'); ?></th>
<td class="nowrap integration-toggles-wrap">
<label>
<select name="mc4wp_integrations[prosopo-procaptcha][theme]" style="width:250px;">
<?php
foreach ($theme_options as $value => $label) {
$selected = $theme === $value ? ' selected' : '';
printf('<option value="%s"%s>%s</option>', esc_attr($value), esc_attr($selected), esc_html($label));
}
?>
</select>
</label>
</td>
</tr>
<tr valign="top">
<th scope="row"><?php echo esc_html__('Type', 'mailchimp-for-wp'); ?></th>
<td class="nowrap integration-toggles-wrap">
<label>
<select name="mc4wp_integrations[prosopo-procaptcha][type]" style="width:250px;">
<?php
foreach ($type_options as $value => $label) {
$selected = $type === $value ? ' selected' : '';
printf('<option value="%s"%s>%s</option>', esc_attr($value), esc_attr($selected), esc_html($label));
}
?>
</select>
</label>
</td>
</tr>
<tr valign="top">
<th scope="row"><?php echo esc_html__('Display for authorized users', 'mailchimp-for-wp'); ?></th>
<td class="nowrap integration-toggles-wrap">
<label>
<input type="radio" name="mc4wp_integrations[prosopo-procaptcha][display_for_authorized]" value="1" <?php checked($display_for_authorized, '1'); ?> />&rlm;
<?php echo esc_html__('Yes', 'mailchimp-for-wp'); ?>
</label> &nbsp;
<label>
<input type="radio" name="mc4wp_integrations[prosopo-procaptcha][display_for_authorized]" value="0" <?php checked($display_for_authorized, '0'); ?> />&rlm;
<?php echo esc_html__('No', 'mailchimp-for-wp'); ?>
</label>
<p class="description"><?php echo esc_html__('Select "yes" to require the captcha even from authorized users.', 'mailchimp-for-wp'); ?></p>
</td>
</tr>
</tbody>
</table>

<prosopo-procaptcha-settings></prosopo-procaptcha-settings>

<script type="module">
class ProsopoProcaptchaSettings extends HTMLElement {
connectedCallback(){
"loading" === document.readyState ?
document.addEventListener("DOMContentLoaded", this.setup.bind(this)) :
this.setup()
}

updateEnabledSetting(event){
let form = event.target;
let enabledInput = form.querySelector('.prosopo-procaptcha__enabled-setting');
let siteKey= form.querySelector('.prosopo-procaptcha__site-key').value.trim();
let secretKey = form.querySelector('.prosopo-procaptcha__secret-key').value.trim();

enabledInput.value = '' !== siteKey &&
'' !== secretKey?
1:
0;
}

setup(){
this.closest('form').addEventListener('submit', this.updateEnabledSetting.bind(this))
}
}
customElements.define('prosopo-procaptcha-settings', ProsopoProcaptchaSettings);
</script>
11 changes: 11 additions & 0 deletions integrations/prosopo-procaptcha/admin-before.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

// translators: %1$s is opening anchor tag, %2$s is closing anchor tag
echo sprintf(
esc_html__(
'%1$s Procaptcha (by Prosopo) %2$s is offering seamless bot protection without compromising user data. You can customize settings and algorithms, ensuring optimal defense against all types of malicious bots.',
'mailchimp-for-wp'
),
'<a href="https://prosopo.io/" target="_blank">',
'</a>'
);
5 changes: 5 additions & 0 deletions integrations/prosopo-procaptcha/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

mc4wp_register_integration('prosopo-procaptcha', 'MC4WP_Procaptcha_Integration');

MC4WP_Procaptcha::get_instance()->set_hooks();
63 changes: 63 additions & 0 deletions integrations/prosopo-procaptcha/class-procaptcha-integration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

defined('ABSPATH') or exit;

/**
* Class MC4WP_Ninja_Forms_Integration
*
* @ignore
*/
class MC4WP_Procaptcha_Integration extends MC4WP_Integration
{
/**
* @var string
*/
public $name = 'Procaptcha (by Prosopo)';

/**
* @var string
*/
public $description = 'Privacy-friendly and GDPR-compliant anti-bot protection.';

/**
* @return void
*/
protected function add_hooks()
{
}

/**
* @return bool
*/
public function is_installed()
{
return true;
}

/**
* @return array
*/
public function get_ui_elements()
{
return array(
'procaptcha_site_key',
'procaptcha_secret_key',
);
}

/**
* @return array
*/
protected function get_default_options()
{
return array(
'enabled' => '0',
'css' => '0',
'site_key' => '',
'secret_key' => '',
'theme' => 'light',
'type' => 'frictionless',
'display_for_authorized' => '0',
);
}
}
Loading
Loading