| 1 |
<?php |
| 2 |
namespace WP_Defender\Component; |
| 3 |
|
| 4 |
use WP_Defender\Component; |
| 5 |
|
| 6 |
/** |
| 7 |
* Use different actions for "What's new" modals. |
| 8 |
* |
| 9 |
* Class Feature_Modal |
| 10 |
* @package WP_Defender\Component |
| 11 |
* @since 2.5.5 |
| 12 |
*/ |
| 13 |
class Feature_Modal extends Component { |
| 14 |
/** |
| 15 |
* Feature data for the last active "What's new" modal. |
| 16 |
*/ |
| 17 |
public const FEATURE_SLUG = 'wd_show_feature_biometric_login'; |
| 18 |
public const FEATURE_VERSION = '3.0.0'; |
| 19 |
|
| 20 |
/** |
| 21 |
* Get modals that are displayed on the Dashboard page. |
| 22 |
* |
| 23 |
* @return array |
| 24 |
* @since 2.7.0 Use one template for Welcome modal and dynamic data. |
| 25 |
*/ |
| 26 |
public function get_dashboard_modals() { |
| 27 |
$title = sprintf( |
| 28 |
/* translators: %s: separator */ |
| 29 |
__( 'New: Set up Biometric Two-Factor %s Authentication!', 'wpdef' ), |
| 30 |
'<br/>' |
| 31 |
); |
| 32 |
$desc = sprintf( |
| 33 |
/* translators: %s: plugin version */ |
| 34 |
__( "To harden your site's security and facilitate the login process, Defender %s enables you to set up biometric 2FA. It allows your users to authenticate their logins using Touch ID, Face ID, or FIDO-certified authentication devices.", 'wpdef' ), |
| 35 |
self::FEATURE_VERSION |
| 36 |
); |
| 37 |
|
| 38 |
return array( |
| 39 |
'show_welcome_modal' => $this->display_last_modal( self::FEATURE_SLUG ), |
| 40 |
'welcome_modal' => array( |
| 41 |
'title' => $title, |
| 42 |
'desc' => $desc, |
| 43 |
'banner_1x' => defender_asset_url( '/assets/img/modal/welcome-modal.png' ), |
| 44 |
'banner_2x' => defender_asset_url( '/assets/img/modal/[email protected]' ), |
| 45 |
'banner_alt' => __( 'Modal for Biometric authentication', 'wpdef' ), |
| 46 |
'button_title' => __( 'Got it', 'wpdef' ), |
| 47 |
// Additional information. |
| 48 |
'additional_text' => $this->additional_text(), |
| 49 |
), |
| 50 |
); |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Display modal with the latest changes if: |
| 55 |
* plugin settings have been reset before -> this is not fresh install, |
| 56 |
* Whitelabel > Documentation, Tutorials and What’s New Modal > checked Show tab OR Whitelabel is disabled. |
| 57 |
* |
| 58 |
* @param string $key |
| 59 |
* |
| 60 |
* @return bool |
| 61 |
*/ |
| 62 |
protected function display_last_modal( $key ) { |
| 63 |
$info = defender_white_label_status(); |
| 64 |
|
| 65 |
return (bool) get_site_option( 'wd_nofresh_install' ) |
| 66 |
&& (bool) get_site_option( $key ) |
| 67 |
&& ! $info['hide_doc_link']; |
| 68 |
} |
| 69 |
|
| 70 |
public function upgrade_site_options() { |
| 71 |
$db_version = get_site_option( 'wd_db_version' ); |
| 72 |
$feature_slugs = array( |
| 73 |
// Important slugs to display Onboarding, e.g. after the click on Reset settings. |
| 74 |
array( |
| 75 |
'slug' => 'wp_defender_shown_activator', |
| 76 |
'vers' => '2.4.0', |
| 77 |
), |
| 78 |
array( |
| 79 |
'slug' => 'wp_defender_is_free_activated', |
| 80 |
'vers' => '2.4.0', |
| 81 |
), |
| 82 |
// The latest feature. |
| 83 |
array( |
| 84 |
'slug' => 'wd_show_feature_auth_methods', |
| 85 |
'vers' => '2.8.0', |
| 86 |
), |
| 87 |
// The current feature. |
| 88 |
array( |
| 89 |
'slug' => self::FEATURE_SLUG, |
| 90 |
'vers' => self::FEATURE_VERSION, |
| 91 |
), |
| 92 |
); |
| 93 |
foreach ( $feature_slugs as $feature ) { |
| 94 |
if ( version_compare( $db_version, $feature['vers'], '==' ) ) { |
| 95 |
// The current feature |
| 96 |
update_site_option( $feature['slug'], true ); |
| 97 |
} else { |
| 98 |
// and old one. |
| 99 |
delete_site_option( $feature['slug'] ); |
| 100 |
} |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
/** |
| 105 |
* Get additional text. |
| 106 |
* |
| 107 |
* @return string |
| 108 |
*/ |
| 109 |
private function additional_text() { |
| 110 |
$text = '<ul class="list-disc list-inside m-0">'; |
| 111 |
$text .= '<li class="mb-30px relative">'; |
| 112 |
$text .= '<strong class="text-base text-gray-500 absolute left-10px">'; |
| 113 |
$text .= __( 'Fingerprint and Facial recognition:', 'wpdef' ); |
| 114 |
$text .= '</strong>'; |
| 115 |
$text .= '<span class="sui-description mt-0">'; |
| 116 |
$text .= __( 'Users are able to register and authenticate the device(s) that supports fingerprint scan or facial recognition they wish to use for their biometric authentication. Additionally, users can enable multiple authentication methods at the same time.', 'wpdef' ); |
| 117 |
$text .= '</span>'; |
| 118 |
$text .= '</li>'; |
| 119 |
$text .= '<li class="sui-no-margin-bottom relative">'; |
| 120 |
$text .= '<strong class="text-base text-gray-500 absolute left-10px">'; |
| 121 |
$text .= __( 'Upgrade PHP to improve overall performance', 'wpdef' ); |
| 122 |
$text .= '</strong>'; |
| 123 |
$text .= '<span class="sui-description mt-0">'; |
| 124 |
$text .= sprintf( |
| 125 |
/* translators: %s: plugin version */ |
| 126 |
__( "Defender %s now requires PHP 7.2 or above. This improves Defender's performance and security while also supporting the new biometric 2FA feature.", 'wpdef' ), |
| 127 |
self::FEATURE_VERSION |
| 128 |
); |
| 129 |
$text .= '</span>'; |
| 130 |
$text .= '</li>'; |
| 131 |
$text .= '</ul>'; |
| 132 |
|
| 133 |
return $text; |
| 134 |
} |
| 135 |
} |
| 136 |
|