| 1 |
<?php |
| 2 |
declare( strict_types=1 ); |
| 3 |
|
| 4 |
namespace WP_Defender\Component; |
| 5 |
|
| 6 |
use WP_Defender\Component; |
| 7 |
|
| 8 |
/** |
| 9 |
* Use different actions for "What's new" modals. |
| 10 |
* |
| 11 |
* Class Feature_Modal |
| 12 |
* @package WP_Defender\Component |
| 13 |
* @since 2.5.5 |
| 14 |
*/ |
| 15 |
class Feature_Modal extends Component { |
| 16 |
/** |
| 17 |
* Feature data for the last active "What's new" modal. |
| 18 |
*/ |
| 19 |
public const FEATURE_SLUG = 'wd_show_feature_yubico'; |
| 20 |
public const FEATURE_VERSION = '3.1.0'; |
| 21 |
|
| 22 |
/** |
| 23 |
* Get modals that are displayed on the Dashboard page. |
| 24 |
* |
| 25 |
* @return array |
| 26 |
* @since 2.7.0 Use one template for Welcome modal and dynamic data. |
| 27 |
*/ |
| 28 |
public function get_dashboard_modals(): array { |
| 29 |
$title = sprintf( |
| 30 |
/* translators: %s: separator */ |
| 31 |
__( 'New: Two-factor authentication using Yubico %s hardware keys!', 'wpdef' ), |
| 32 |
'<br/>' |
| 33 |
); |
| 34 |
$desc = __( "The usage of FIDO2 WebAuthn protocols in Defender 3.1.0 enables you to use Yubico's hardware keys, also known as YubiKeys, as a two-factor authentication method. This definitely hardens the security of your website as it requires a hardware (physical) key to authenticate user logins", 'wpdef' ); |
| 35 |
|
| 36 |
return [ |
| 37 |
'show_welcome_modal' => $this->display_last_modal( self::FEATURE_SLUG ), |
| 38 |
'welcome_modal' => [ |
| 39 |
'title' => $title, |
| 40 |
'desc' => $desc, |
| 41 |
'banner_1x' => defender_asset_url( '/assets/img/modal/welcome-modal.png' ), |
| 42 |
'banner_2x' => defender_asset_url( '/assets/img/modal/[email protected]' ), |
| 43 |
'banner_alt' => __( 'Modal for Yubico feature', 'wpdef' ), |
| 44 |
'button_title' => __( 'Got it', 'wpdef' ), |
| 45 |
// Additional information. |
| 46 |
'additional_text' => $this->additional_text(), |
| 47 |
], |
| 48 |
]; |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* Display modal with the latest changes if: |
| 53 |
* plugin settings have been reset before -> this is not fresh install, |
| 54 |
* Whitelabel > Documentation, Tutorials and What’s New Modal > checked Show tab OR Whitelabel is disabled. |
| 55 |
* |
| 56 |
* @param string $key |
| 57 |
* |
| 58 |
* @return bool |
| 59 |
*/ |
| 60 |
protected function display_last_modal( $key ): bool { |
| 61 |
$info = defender_white_label_status(); |
| 62 |
|
| 63 |
return (bool) get_site_option( 'wd_nofresh_install' ) |
| 64 |
&& (bool) get_site_option( $key ) |
| 65 |
&& ! $info['hide_doc_link']; |
| 66 |
} |
| 67 |
|
| 68 |
public function upgrade_site_options() { |
| 69 |
$db_version = get_site_option( 'wd_db_version' ); |
| 70 |
$feature_slugs = [ |
| 71 |
// Important slugs to display Onboarding, e.g. after the click on Reset settings. |
| 72 |
[ |
| 73 |
'slug' => 'wp_defender_shown_activator', |
| 74 |
'vers' => '2.4.0', |
| 75 |
], |
| 76 |
[ |
| 77 |
'slug' => 'wp_defender_is_free_activated', |
| 78 |
'vers' => '2.4.0', |
| 79 |
], |
| 80 |
// The latest feature. |
| 81 |
[ |
| 82 |
'slug' => 'wd_show_feature_biometric_login', |
| 83 |
'vers' => '3.0.0', |
| 84 |
], |
| 85 |
// The current feature. |
| 86 |
[ |
| 87 |
'slug' => self::FEATURE_SLUG, |
| 88 |
'vers' => self::FEATURE_VERSION, |
| 89 |
], |
| 90 |
]; |
| 91 |
foreach ( $feature_slugs as $feature ) { |
| 92 |
if ( version_compare( $db_version, $feature['vers'], '==' ) ) { |
| 93 |
// The current feature |
| 94 |
update_site_option( $feature['slug'], true ); |
| 95 |
} else { |
| 96 |
// and old one. |
| 97 |
delete_site_option( $feature['slug'] ); |
| 98 |
} |
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
/** |
| 103 |
* Get additional text. |
| 104 |
* |
| 105 |
* @return string |
| 106 |
*/ |
| 107 |
private function additional_text(): string { |
| 108 |
$text = '<ul class="list-disc list-inside m-0">'; |
| 109 |
$text .= '<li class="sui-no-margin-bottom relative">'; |
| 110 |
$text .= '<strong class="text-base text-gray-500 absolute left-10px">'; |
| 111 |
$text .= __( 'Hardware Authentication', 'wpdef' ); |
| 112 |
$text .= '</strong>'; |
| 113 |
$text .= '<span class="sui-description mt-0">'; |
| 114 |
$text .= __( 'The <strong>YubiKey</strong> is a physical authentication device manufactured by Yubico to protect', 'wpdef' ); |
| 115 |
$text .= __( ' access to computers, networks, and online services using <strong>Universal 2nd Factor</strong> and', 'wpdef' ); |
| 116 |
$text .= __( ' <strong>FIDO2</strong> protocols developed by the <strong>FIDO Alliance</strong>.', 'wpdef' ); |
| 117 |
$text .= __( ' By enabling our new Hardware Authentication method, your users can quickly and', 'wpdef' ); |
| 118 |
$text .= __( ' easily verify their identity during the login process by simply inserting their YubiKey into their device and tapping it.', 'wpdef' ); |
| 119 |
$text .= '</span>'; |
| 120 |
$text .= '</li>'; |
| 121 |
$text .= '</ul>'; |
| 122 |
|
| 123 |
return $text; |
| 124 |
} |
| 125 |
} |
| 126 |
|