handling recaptcha on the PHP side
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
<?php
|
||||
namespace MailPoet\Form;
|
||||
|
||||
use MailPoet\Models\Setting;
|
||||
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
class Renderer {
|
||||
@@ -39,15 +41,23 @@ class Renderer {
|
||||
}
|
||||
|
||||
static function renderBlocks($blocks = array(), $honeypot_enabled = true) {
|
||||
$html = array();
|
||||
// add honeypot for spambots
|
||||
$html = ($honeypot_enabled) ?
|
||||
$html[] = ($honeypot_enabled) ?
|
||||
'<label class="mailpoet_hp_email_label">' . __('Please leave this field empty', 'mailpoet') . '<input type="email" name="data[email]"></label>' :
|
||||
'';
|
||||
foreach($blocks as $key => $block) {
|
||||
$html .= static::renderBlock($block) . PHP_EOL;
|
||||
$html[] = static::renderBlock($block) . PHP_EOL;
|
||||
}
|
||||
|
||||
return $html;
|
||||
if(Setting::getValue('re_captcha.enabled')) {
|
||||
$submit = array_pop($html);
|
||||
$site_key = Setting::getValue('re_captcha.site_token');
|
||||
$html[] = '<div class="g-recaptcha" data-sitekey="'. $site_key .'"></div>';
|
||||
$html[] = $submit;
|
||||
}
|
||||
|
||||
return implode('', $html);
|
||||
}
|
||||
|
||||
static function renderBlock($block = array()) {
|
||||
|
@@ -7,6 +7,7 @@ use MailPoet\Config\Env;
|
||||
use MailPoet\Config\Renderer as ConfigRenderer;
|
||||
use MailPoet\Form\Renderer as FormRenderer;
|
||||
use MailPoet\Models\Form;
|
||||
use MailPoet\Models\Setting;
|
||||
use MailPoet\Util\Security;
|
||||
use MailPoet\WP\Hooks;
|
||||
|
||||
@@ -48,6 +49,9 @@ class Widget extends \WP_Widget {
|
||||
wp_print_scripts('jquery');
|
||||
wp_print_scripts('mailpoet_vendor');
|
||||
wp_print_scripts('mailpoet_public');
|
||||
if(Setting::getValue('re_captcha.enabled')) {
|
||||
echo '<script src="https://www.google.com/recaptcha/api.js"></script>';
|
||||
}
|
||||
$scripts = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
@@ -320,4 +324,4 @@ EOL;
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user