PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 6.3.0
Defender Security – Malware Scanner, Login Security & Firewall v6.3.0
6.3.0 6.2.3 6.2.4 6.2.0 6.2.1 6.2.2 6.1.0 5.3.1 5.4.0 5.4.1 5.5.0 5.5.1 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.7.2 5.8.0 5.8.1 5.9.0 6.0.0 6.0.1 3.0.1 3.1.0 All 141 releases
defender-security / src / component / class-feature-modal.php

class-feature-modal.php in Defender Security – Malware Scanner, Login Security & Firewall 6.3.0, at src/component/class-feature-modal.php

129 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Manages the display of "What's New" modals dashboard.
4 *
5 * @package WP_Defender\Component
6 */
7
8 namespace WP_Defender\Component;
9
10 use WP_Defender\Component;
11 use WP_Defender\Traits\Defender_Dashboard_Client;
12
13 /**
14 * Use different actions for "What's new" modals.
15 *
16 * @since 2.5.5
17 */
18 class Feature_Modal extends Component {
19 use Defender_Dashboard_Client;
20
21 /**
22 * Feature data for the last active "What's new" modal.
23 */
24 public const FEATURE_SLUG = 'wd_show_feature_redesign';
25 public const FEATURE_VERSION = '6.0.0';
26
27 /**
28 * Get modals that are displayed on the Dashboard page.
29 *
30 * @param bool $force_hide The modal is not displayed in every version, so we need a flag that will control the
31 * display process.
32 *
33 * @return array
34 * @since 2.7.0 Use one template for Welcome modal and dynamic data.
35 */
36 public function get_dashboard_modals( $force_hide = false ): array {
37 $is_displayed = $force_hide ? false : $this->display_last_modal( self::FEATURE_SLUG );
38 $current_user = wp_get_current_user();
39
40 return array(
41 'show_welcome_modal' => $is_displayed,
42 );
43 }
44
45 /**
46 * Display modal if:
47 * plugin version has important changes,
48 * plugin settings have been reset before -> this is not fresh install,
49 * Whitelabel > Documentation, Tutorials and What’s New Modal > checked Show tab OR Whitelabel is disabled.
50 *
51 * @param string $key The feature slug to check.
52 *
53 * @return bool
54 */
55 protected function display_last_modal( $key ): bool {
56 $info = defender_white_label_status();
57
58 return (bool) get_site_option( $key ) && ! $info['hide_doc_link'];
59 }
60
61 /**
62 * Upgrades site options related to feature modals based on the database version.
63 */
64 public function upgrade_site_options(): void {
65 $db_version = get_site_option( 'wd_db_version' );
66 $feature_slugs = array(
67 // Important slugs to display Onboarding, e.g. after the click on Reset settings.
68 array(
69 'slug' => 'wp_defender_shown_activator',
70 'vers' => '2.4.0',
71 ),
72 array(
73 'slug' => 'wp_defender_is_free_activated',
74 'vers' => '2.4.0',
75 ),
76 // The latest feature.
77 array(
78 'slug' => 'wd_show_feature_turnstile',
79 'vers' => '5.7.0',
80 ),
81 // The current feature.
82 array(
83 'slug' => self::FEATURE_SLUG,
84 'vers' => self::FEATURE_VERSION,
85 ),
86 );
87 foreach ( $feature_slugs as $feature ) {
88 if ( version_compare( $db_version, $feature['vers'], '==' ) ) {
89 // The current feature.
90 update_site_option( $feature['slug'], true );
91 } else {
92 // Old one.
93 delete_site_option( $feature['slug'] );
94 }
95 }
96 }
97
98 /**
99 * Get additional text.
100 *
101 * @return string
102 */
103 private function additional_text(): string {
104 return '';
105 }
106
107 /**
108 * Enable the welcome modal only when the installed plugin version matches the exact
109 * release the modal belongs to, so it does not re-appear on later patches/minors
110 * (e.g. 6.0.1, 6.1) that share the same DB version.
111 *
112 * @return void
113 */
114 public static function maybe_enable_welcome_modal(): void {
115 if ( defined( 'DEFENDER_VERSION' ) && version_compare( DEFENDER_VERSION, self::FEATURE_VERSION, '==' ) ) {
116 update_site_option( self::FEATURE_SLUG, true );
117 }
118 }
119
120 /**
121 * Delete welcome modal key.
122 *
123 * @return void
124 */
125 public static function delete_modal_key(): void {
126 delete_site_option( self::FEATURE_SLUG );
127 }
128 }
129