PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 5.6.0
Defender Security – Malware Scanner, Login Security & Firewall v5.6.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 5.6.0, at src/component/class-feature-modal.php

121 lines 3.1 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_fake_bots';
25 public const FEATURE_VERSION = '5.6.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 'welcome_modal' => array(
43 'user_name' => esc_html( $current_user->display_name ),
44 'banner_1x' => defender_asset_url( '/assets/img/modal/welcome-modal.png' ),
45 'banner_2x' => defender_asset_url( '/assets/img/modal/[email protected]' ),
46 ),
47 );
48 }
49
50 /**
51 * Display modal if:
52 * plugin version has important changes,
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 The feature slug to check.
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( $key ) && ! $info['hide_doc_link'];
64 }
65
66 /**
67 * Upgrades site options related to feature modals based on the database version.
68 */
69 public function upgrade_site_options(): void {
70 $db_version = get_site_option( 'wd_db_version' );
71 $feature_slugs = array(
72 // Important slugs to display Onboarding, e.g. after the click on Reset settings.
73 array(
74 'slug' => 'wp_defender_shown_activator',
75 'vers' => '2.4.0',
76 ),
77 array(
78 'slug' => 'wp_defender_is_free_activated',
79 'vers' => '2.4.0',
80 ),
81 // The latest feature.
82 array(
83 'slug' => 'wd_show_feature_abandoned_plugin',
84 'vers' => '5.5.0',
85 ),
86 // The current feature.
87 array(
88 'slug' => self::FEATURE_SLUG,
89 'vers' => self::FEATURE_VERSION,
90 ),
91 );
92 foreach ( $feature_slugs as $feature ) {
93 if ( version_compare( $db_version, $feature['vers'], '==' ) ) {
94 // The current feature.
95 update_site_option( $feature['slug'], true );
96 } else {
97 // Old one.
98 delete_site_option( $feature['slug'] );
99 }
100 }
101 }
102
103 /**
104 * Get additional text.
105 *
106 * @return string
107 */
108 private function additional_text(): string {
109 return '';
110 }
111
112 /**
113 * Delete welcome modal key.
114 *
115 * @return void
116 */
117 public static function delete_modal_key(): void {
118 delete_site_option( self::FEATURE_SLUG );
119 }
120 }
121