PluginProbe ʕ •ᴥ•ʔ
Code Manager / 1.0.20
Code Manager v1.0.20
1.0.48 1.0.47 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.2 1.0.20 1.0.21 1.0.22 1.0.23 1.0.24 1.0.25 1.0.26 1.0.27 1.0.28 1.0.3 1.0.30 1.0.31 1.0.32 1.0.33 1.0.34 1.0.35 1.0.36 1.0.37 1.0.38 1.0.39 1.0.4 1.0.40 1.0.41 1.0.42 1.0.43 1.0.44 1.0.45 1.0.46 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9
code-manager / freemius / includes / managers / class-fs-gdpr-manager.php
code-manager / freemius / includes / managers Last commit date
class-fs-admin-menu-manager.php 3 years ago class-fs-admin-notice-manager.php 3 years ago class-fs-cache-manager.php 3 years ago class-fs-clone-manager.php 3 years ago class-fs-gdpr-manager.php 3 years ago class-fs-key-value-storage.php 3 years ago class-fs-license-manager.php 3 years ago class-fs-option-manager.php 3 years ago class-fs-permission-manager.php 3 years ago class-fs-plan-manager.php 3 years ago class-fs-plugin-manager.php 3 years ago index.php 3 years ago
class-fs-gdpr-manager.php
202 lines
1 <?php
2 /**
3 * @package Freemius
4 * @copyright Copyright (c) 2015, Freemius, Inc.
5 * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
6 * @since 2.1.0
7 */
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit;
11 }
12
13 class FS_GDPR_Manager {
14 /**
15 * @var FS_Option_Manager
16 */
17 private $_storage;
18 /**
19 * @var array {
20 * @type bool $required Are GDPR rules apply on the current context admin.
21 * @type bool $show_opt_in_notice Should the marketing and offers opt-in message be shown to the admin or not. If not set, defaults to `true`.
22 * @type int $notice_shown_at Last time the special GDPR opt-in message was shown to the current admin.
23 * }
24 */
25 private $_data;
26 /**
27 * @var int
28 */
29 private $_wp_user_id;
30 /**
31 * @var string
32 */
33 private $_option_name;
34 /**
35 * @var FS_Admin_Notices
36 */
37 private $_notices;
38
39 #--------------------------------------------------------------------------------
40 #region Singleton
41 #--------------------------------------------------------------------------------
42
43 /**
44 * @var FS_GDPR_Manager
45 */
46 private static $_instance;
47
48 /**
49 * @return FS_GDPR_Manager
50 */
51 public static function instance() {
52 if ( ! isset( self::$_instance ) ) {
53 self::$_instance = new self();
54 }
55
56 return self::$_instance;
57 }
58
59 #endregion
60
61 private function __construct() {
62 $this->_storage = FS_Option_Manager::get_manager( WP_FS__GDPR_OPTION_NAME, true, true );
63 $this->_wp_user_id = Freemius::get_current_wp_user_id();
64 $this->_option_name = "u{$this->_wp_user_id}";
65 $this->_data = $this->_storage->get_option( $this->_option_name, array() );
66 $this->_notices = FS_Admin_Notices::instance( 'all_admins', '', '', true );
67
68 if ( ! is_array( $this->_data ) ) {
69 $this->_data = array();
70 }
71 }
72
73 /**
74 * Update a GDPR option for the current admin and store it.
75 *
76 * @author Vova Feldman (@svovaf)
77 * @since 2.1.0
78 *
79 * @param string $name
80 * @param mixed $value
81 */
82 private function update_option( $name, $value ) {
83 $this->_data[ $name ] = $value;
84
85 $this->_storage->set_option( $this->_option_name, $this->_data, true );
86 }
87
88 /**
89 * @author Leo Fajardo (@leorw)
90 * @since 2.1.0
91 *
92 * @return bool|null
93 */
94 public function is_required() {
95 return isset( $this->_data['required'] ) ?
96 $this->_data['required'] :
97 null;
98 }
99
100 /**
101 * @author Leo Fajardo (@leorw)
102 * @since 2.1.0
103 *
104 * @param bool $is_required
105 */
106 public function store_is_required( $is_required ) {
107 $this->update_option( 'required', $is_required );
108 }
109
110 /**
111 * Checks if the GDPR opt-in sticky notice is currently shown.
112 *
113 * @author Vova Feldman (@svovaf)
114 * @since 2.1.0
115 *
116 * @return bool
117 */
118 public function is_opt_in_notice_shown() {
119 return $this->_notices->has_sticky( "gdpr_optin_actions_{$this->_wp_user_id}", true );
120 }
121
122 /**
123 * Remove the GDPR opt-in sticky notice.
124 *
125 * @author Vova Feldman (@svovaf)
126 * @since 2.1.0
127 */
128 public function remove_opt_in_notice() {
129 $this->_notices->remove_sticky( "gdpr_optin_actions_{$this->_wp_user_id}", true );
130
131 $this->disable_opt_in_notice();
132 }
133
134 /**
135 * Prevents the opt-in message from being added/shown.
136 *
137 * @author Leo Fajardo (@leorw)
138 * @since 2.1.0
139 */
140 public function disable_opt_in_notice() {
141 $this->update_option( 'show_opt_in_notice', false );
142 }
143
144 /**
145 * Checks if a GDPR opt-in message needs to be shown to the current admin.
146 *
147 * @author Vova Feldman (@svovaf)
148 * @since 2.1.0
149 *
150 * @return bool
151 */
152 public function should_show_opt_in_notice() {
153 return (
154 ! isset( $this->_data['show_opt_in_notice'] ) ||
155 true === $this->_data['show_opt_in_notice']
156 );
157 }
158
159 /**
160 * Get the last time the GDPR opt-in notice was shown.
161 *
162 * @author Vova Feldman (@svovaf)
163 * @since 2.1.0
164 *
165 * @return false|int
166 */
167 public function last_time_notice_was_shown() {
168 return isset( $this->_data['notice_shown_at'] ) ?
169 $this->_data['notice_shown_at'] :
170 false;
171 }
172
173 /**
174 * Update the timestamp of the last time the GDPR opt-in message was shown to now.
175 *
176 * @author Vova Feldman (@svovaf)
177 * @since 2.1.0
178 */
179 public function notice_was_just_shown() {
180 $this->update_option( 'notice_shown_at', WP_FS__SCRIPT_START_TIME );
181 }
182
183 /**
184 * @param string $message
185 * @param string|null $plugin_title
186 *
187 * @author Vova Feldman (@svovaf)
188 * @since 2.1.0
189 */
190 public function add_opt_in_sticky_notice( $message, $plugin_title = null ) {
191 $this->_notices->add_sticky(
192 $message,
193 "gdpr_optin_actions_{$this->_wp_user_id}",
194 '',
195 'promotion',
196 true,
197 $this->_wp_user_id,
198 $plugin_title,
199 true
200 );
201 }
202 }