', PHP_EOL, __('This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.', self::SGR_TEXT_DOMAIN));
}
$this->displayDisableProtection();
echo sprintf('%s', $badgeText);
}
private function displayDisableProtection()
{
if ($this->adminCookieHash()) {
echo sprintf('
', __('Error:', self::SGR_TEXT_DOMAIN), __('verification failed', self::SGR_TEXT_DOMAIN), __('Do you have JavaScript enabled?', self::SGR_TEXT_DOMAIN)), 'reCAPTCHA', ['response' => 403, 'back_link' => 1]);
}
}
/**
* @return string
*/
public function messageProtectionStatus()
{
$type = $this->version === 3 ? self::SGR_V3 : self::SGR_V2;
if (!$this->siteKey || !$this->secretKey) {
return sprintf('
%s Google reCAPTCHA %s!
%s
', __('Warning:', self::SGR_TEXT_DOMAIN), __('is disabled', self::SGR_TEXT_DOMAIN), sprintf(__('You have to register your domain, get required Google reCAPTCHA keys %s and save them bellow.', self::SGR_TEXT_DOMAIN), $type));
} else {
return sprintf('
%s Google reCAPTCHA %s!
%s
', __('Notice:', self::SGR_TEXT_DOMAIN), __('is enabled', self::SGR_TEXT_DOMAIN), __('Keep on mind, that in case of emergency, you can disable this plugin via FTP access, just rename the plugin folder.', self::SGR_TEXT_DOMAIN));
}
}
/**
* @return bool
*/
public function adminCookieHash()
{
$cookieHash = filter_input(INPUT_COOKIE, self::SGR_OPTION_HASH, FILTER_SANITIZE_SPECIAL_CHARS);
if ($cookieHash === md5($this->siteKey . $this->secretKey)) {
return true;
} else {
return false;
}
}
public function run()
{
$this->pluginName = get_file_data(__FILE__, ['Name' => 'Plugin Name'])['Name'];
$postAction = filter_input(INPUT_POST, self::SGR_ACTION, FILTER_SANITIZE_SPECIAL_CHARS);
if ($postAction === self::UPDATE) {
$this->updateSettings();
}
$this->siteKey = filter_var(get_option(self::SGR_OPTION_SITE_KEY), FILTER_SANITIZE_FULL_SPECIAL_CHARS);
$this->secretKey = filter_var(get_option(self::SGR_OPTION_SECRET_KEY), FILTER_SANITIZE_FULL_SPECIAL_CHARS);
$this->version = (int)filter_var(get_option(self::SGR_OPTION_VERSION), FILTER_SANITIZE_NUMBER_INT);
$this->loginDisable = (int)filter_var(get_option(self::SGR_OPTION_LOGIN_DISABLE), FILTER_SANITIZE_NUMBER_INT);
$this->badgeHide = (int)filter_var(get_option(self::SGR_OPTION_BADGE_HIDE), FILTER_SANITIZE_NUMBER_INT);
$getAction = filter_input(INPUT_GET, self::SGR_ACTION, FILTER_SANITIZE_SPECIAL_CHARS);
if ($getAction === self::DISABLE) {
$this->disableProtection();
}
add_filter(sprintf('plugin_action_links_%s', plugin_basename(__FILE__)), [$this, 'action_links']);
add_action('admin_menu', [$this, 'menu']);
if (!is_user_logged_in() && !wp_doing_ajax() && !function_exists('wpcf7_contact_form_shortcode') && $this->siteKey && $this->secretKey) {
$this->frontend();
}
}
}
new SimpleGoogleRecaptcha();