| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentForm\App\Modules\Registerer; |
| 4 |
|
| 5 |
defined('ABSPATH') or die; |
| 6 |
|
| 7 |
use FluentForm\App\Helpers\Helper; |
| 8 |
use FluentForm\App\Http\Controllers\AdminNoticeController; |
| 9 |
use FluentForm\Framework\Helpers\ArrayHelper; |
| 10 |
|
| 11 |
class CaptchaKeyNotice |
| 12 |
{ |
| 13 |
public static function register() |
| 14 |
{ |
| 15 |
if (static::shouldRegister()) { |
| 16 |
add_action('fluentform/global_menu', [static::class, 'show'], 99); |
| 17 |
} |
| 18 |
} |
| 19 |
|
| 20 |
protected static function shouldRegister() |
| 21 |
{ |
| 22 |
if (!Helper::isFluentAdminPage() || wp_doing_ajax()) { |
| 23 |
return false; |
| 24 |
} |
| 25 |
|
| 26 |
if (!Helper::isAutoloadCaptchaEnabled()) { |
| 27 |
return false; |
| 28 |
} |
| 29 |
|
| 30 |
$statusOption = ArrayHelper::get(static::statusOptionMap(), static::selectedType()); |
| 31 |
|
| 32 |
return !$statusOption || !get_option($statusOption, false); |
| 33 |
} |
| 34 |
|
| 35 |
public static function show() |
| 36 |
{ |
| 37 |
$notice = new AdminNoticeController(); |
| 38 |
$notice->addNotice(self::getMessage()); |
| 39 |
$notice->showNotice(); |
| 40 |
} |
| 41 |
|
| 42 |
protected static function selectedType() |
| 43 |
{ |
| 44 |
return ArrayHelper::get(get_option('_fluentform_global_form_settings'), 'misc.captcha_type'); |
| 45 |
} |
| 46 |
|
| 47 |
protected static function statusOptionMap() |
| 48 |
{ |
| 49 |
return [ |
| 50 |
'recaptcha' => '_fluentform_reCaptcha_keys_status', |
| 51 |
'hcaptcha' => '_fluentform_hCaptcha_keys_status', |
| 52 |
'turnstile' => '_fluentform_turnstile_keys_status', |
| 53 |
]; |
| 54 |
} |
| 55 |
|
| 56 |
protected static function settingsUrl() |
| 57 |
{ |
| 58 |
$anchors = [ |
| 59 |
'recaptcha' => '#re_captcha', |
| 60 |
'hcaptcha' => '#h_captcha', |
| 61 |
'turnstile' => '#turnstile', |
| 62 |
'cleantalk' => '#cleantalk', |
| 63 |
]; |
| 64 |
|
| 65 |
$anchor = ArrayHelper::get($anchors, static::selectedType(), ''); |
| 66 |
|
| 67 |
return admin_url('admin.php?page=fluent_forms_settings') . $anchor; |
| 68 |
} |
| 69 |
|
| 70 |
private static function getMessage() |
| 71 |
{ |
| 72 |
$message = __( |
| 73 |
'Fluent Forms global captcha is enabled, but the selected captcha type has no valid keys. Until you add valid keys, your forms are not protected by captcha.', |
| 74 |
'fluentform' |
| 75 |
); |
| 76 |
|
| 77 |
return [ |
| 78 |
'name' => 'autoload_captcha_keys_missing', |
| 79 |
'title' => '', |
| 80 |
'message' => $message, |
| 81 |
'links' => [ |
| 82 |
[ |
| 83 |
'href' => static::settingsUrl(), |
| 84 |
'btn_text' => __('Configure Captcha', 'fluentform'), |
| 85 |
'btn_atts' => 'class="mr-1 el-button--success el-button--mini"', |
| 86 |
], |
| 87 |
], |
| 88 |
]; |
| 89 |
} |
| 90 |
} |
| 91 |
|