PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 5.8.1
Defender Security – Malware Scanner, Login Security & Firewall v5.8.1
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 / controller / class-data-tracking.php

class-data-tracking.php in Defender Security – Malware Scanner, Login Security & Firewall 5.8.1, at src/controller/class-data-tracking.php

188 lines 5.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Handles data tracking functionalities.
4 *
5 * @package WP_Defender\Controller
6 */
7
8 namespace WP_Defender\Controller;
9
10 use Exception;
11 use WP_Defender\Event;
12 use Calotes\Component\Response;
13 use WP_Defender\Model\Setting\Main_Setting;
14 use WP_Defender\Component\Config\Config_Hub_Helper;
15
16 /**
17 * Handles data tracking functionalities.
18 *
19 * @since 4.2.0
20 */
21 class Data_Tracking extends Event {
22
23 public const TRACKING_SLUG = 'wd_show_usage_data';
24
25 /**
26 * Initializes the model and service, registers routes, and sets up scheduled events if the model is active.
27 */
28 public function __construct() {
29 $this->register_routes();
30 }
31
32 /**
33 * Get the Tracking modal that is displayed on all plugin pages.
34 *
35 * @return array
36 */
37 public function get_tracking_modal(): array {
38 $title = esc_html__( 'Help Us Enhance Your Site\'s Security', 'defender-security' );
39
40 $current_user = wp_get_current_user();
41
42 $desc = sprintf(
43 /* translators: %s: user display name */
44 esc_html__(
45 'Hey there! %s, Defender is dedicated to protecting your WordPress website from hackers and malware. However, our mission is more effective with your collaboration. By opting in to share anonymous usage data, you help us refine and enhance our plugin for everyone\'s benefit.',
46 'defender-security'
47 ),
48 '<strong>' . esc_html( $current_user->display_name ) . '</strong>'
49 );
50 $desc .= '<br/><br/>';
51 $desc .= sprintf(
52 /* translators: %s: Link. */
53 esc_html__(
54 'Your privacy is important to us. We guarantee that your data stays anonymous and your identity stays secure. Learn more about our usage tracking %s.',
55 'defender-security'
56 ),
57 '<a href="' . Main_Setting::PRIVACY_LINK . '" target="_blank">' . esc_html__( 'here', 'defender-security' ) . '<a>'
58 );
59 $result = $this->dump_routes_and_nonces();
60
61 return array(
62 'title' => $title,
63 'desc' => $desc,
64 'banner_1x' => defender_asset_url( '/assets/img/modal/tracking-modal.png' ),
65 'banner_2x' => defender_asset_url( '/assets/img/modal/[email protected]' ),
66 'banner_alt' => esc_html__( 'Help us improve Defender', 'defender-security' ),
67 'optin_button_title' => esc_html__( 'OPT IN', 'defender-security' ),
68 'skip_button_title' => esc_html__( 'Skip for now', 'defender-security' ),
69 'state_usage_tracking' => wd_di()->get( Main_Setting::class )->usage_tracking,
70 'routes' => $result['routes'],
71 'nonces' => $result['nonces'],
72 );
73 }
74
75 /**
76 * Handles the closing of the tracking modal.
77 *
78 * @return Response Response object indicating success.
79 * @defender_route
80 */
81 public function close_track_modal(): Response {
82 // Track.
83 $this->track_feature( 'def_tracking_modal', array( 'Modal Action' => 'closed' ) );
84 self::delete_modal_key();
85
86 return new Response( true, array() );
87 }
88
89 /**
90 * Save Enabled tracking state.
91 *
92 * @return Response
93 * @defender_route
94 */
95 public function save_track_modal(): Response {
96 $model_settings = wd_di()->get( Main_Setting::class );
97 // Update the value if it's changed.
98 if ( true !== $model_settings->usage_tracking ) {
99 $model_settings->toggle_tracking( true );
100 // Changes for Hub.
101 Config_Hub_Helper::set_clear_active_flag();
102 // Track#1.
103 $this->track_opt_toggle( true, 'Tracking modal' );
104 // Track#2.
105 $this->track_feature( 'def_tracking_modal', array( 'Modal Action' => 'cta_clicked' ) );
106 }
107 // Hide the modal.
108 self::delete_modal_key();
109
110 return new Response( true, array() );
111 }
112
113 /**
114 * Deletes the site option that controls the visibility of the tracking modal.
115 */
116 public static function delete_modal_key(): void {
117 delete_site_option( self::TRACKING_SLUG );
118 }
119
120 /**
121 * Conditions of the Tracking modal:
122 * 1)show on all Defender pages.
123 * 2)show to users upgrading from older versions.
124 * 3)should have higher priority than a Welcome modal on the Defender > Dashboard page.
125 * 4)if user closes or clicks on the Save button on one plugin page, we don't itl on another plugin page.
126 * 5)no display after the updated Onboarding with Opt-in.
127 * 6)no display when Whitelabel > Documentation, Tutorials and What’s New Modal is set to “Hide”
128 *
129 * @return bool
130 */
131 public function show_tracking_modal() {
132 $info = defender_white_label_status();
133
134 $white_label_is_hide = isset( $info['hide_doc_link'] ) && $info['hide_doc_link'];
135
136 return (bool) get_site_option( self::TRACKING_SLUG ) && ! $white_label_is_hide;
137 }
138
139 /**
140 * Delete all the data & the cache.
141 */
142 public function remove_data() {
143 }
144
145 /**
146 * Exports strings.
147 *
148 * @return array An array of strings.
149 */
150 public function export_strings(): array {
151 return array();
152 }
153
154 /**
155 * Converts the object data to an array.
156 *
157 * @return array An array representation of the object.
158 */
159 public function to_array(): array {
160 return array();
161 }
162
163 /**
164 * Imports data into the model.
165 *
166 * @param array $data Data to be imported into the model.
167 *
168 * @throws Exception If table is not defined.
169 */
170 public function import_data( array $data ) {
171 }
172
173 /**
174 * Removes settings for all submodules.
175 */
176 public function remove_settings(): void {
177 }
178
179 /**
180 * Provides data for the frontend.
181 *
182 * @return array An array of data for the frontend.
183 */
184 public function data_frontend(): array {
185 return array();
186 }
187 }
188