Refactor recatcha and honeypot rendering to extra private methods
[MAILPOET-2665]
This commit is contained in:
committed by
Jack Kitterhing
parent
73281f0851
commit
a759530b9d
@@ -5,7 +5,6 @@ namespace MailPoet\Form;
|
||||
use MailPoet\Form\Util\Styles;
|
||||
use MailPoet\Settings\SettingsController;
|
||||
use MailPoet\Subscription\Captcha;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
class Renderer {
|
||||
/** @var Styles */
|
||||
@@ -46,13 +45,23 @@ class Renderer {
|
||||
|
||||
public function renderBlocks(array $blocks = [], bool $honeypotEnabled = true): string {
|
||||
// add honeypot for spambots
|
||||
$html = ($honeypotEnabled) ?
|
||||
'<label class="mailpoet_hp_email_label">' . WPFunctions::get()->__('Please leave this field empty', 'mailpoet') . '<input type="email" name="data[email]"></label>' :
|
||||
'';
|
||||
$html = ($honeypotEnabled) ? $this->renderHoneypot() : '';
|
||||
foreach ($blocks as $key => $block) {
|
||||
if ($block['type'] == 'submit' && $this->settings->get('captcha.type') === Captcha::TYPE_RECAPTCHA) {
|
||||
$html .= $this->renderReCaptcha();
|
||||
}
|
||||
$html .= $this->renderBlock($block) . PHP_EOL;
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
|
||||
private function renderHoneypot(): string {
|
||||
return '<label class="mailpoet_hp_email_label">' . __('Please leave this field empty', 'mailpoet') . '<input type="email" name="data[email]"></label>';
|
||||
}
|
||||
|
||||
private function renderReCaptcha(): string {
|
||||
$siteKey = $this->settings->get('captcha.recaptcha_site_token');
|
||||
$html .= '<div class="mailpoet_recaptcha" data-sitekey="' . $siteKey . '">
|
||||
return '<div class="mailpoet_recaptcha" data-sitekey="' . $siteKey . '">
|
||||
<div class="mailpoet_recaptcha_container"></div>
|
||||
<noscript>
|
||||
<div>
|
||||
@@ -71,11 +80,6 @@ class Renderer {
|
||||
<input class="mailpoet_recaptcha_field" type="hidden" name="recaptcha">
|
||||
</div>';
|
||||
}
|
||||
$html .= $this->renderBlock($block) . PHP_EOL;
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
private function renderBlock(array $block = []): string {
|
||||
$html = '';
|
||||
|
Reference in New Issue
Block a user