_storage = FS_Option_Manager::get_manager( WP_FS__GDPR_OPTION_NAME, true, true ); $this->_wp_user_id = Freemius::get_current_wp_user_id(); $this->_option_name = "u{$this->_wp_user_id}"; $this->_data = $this->_storage->get_option( $this->_option_name, array() ); $this->_notices = FS_Admin_Notices::instance( 'all_admins', '', '', true ); if ( ! is_array( $this->_data ) ) { $this->_data = array(); } } /** * Update a GDPR option for the current admin and store it. * * @author Vova Feldman (@svovaf) * @since 2.1.0 * * @param string $name * @param mixed $value */ private function update_option( $name, $value ) { $this->_data[ $name ] = $value; $this->_storage->set_option( $this->_option_name, $this->_data, true ); } /** * @author Leo Fajardo (@leorw) * @since 2.1.0 * * @return bool|null */ public function is_required() { return isset( $this->_data['required'] ) ? $this->_data['required'] : null; } /** * @author Leo Fajardo (@leorw) * @since 2.1.0 * * @param bool $is_required */ public function store_is_required( $is_required ) { $this->update_option( 'required', $is_required ); } /** * Checks if the GDPR opt-in sticky notice is currently shown. * * @author Vova Feldman (@svovaf) * @since 2.1.0 * * @return bool */ public function is_opt_in_notice_shown() { return $this->_notices->has_sticky( "gdpr_optin_actions_{$this->_wp_user_id}", true ); } /** * Remove the GDPR opt-in sticky notice. * * @author Vova Feldman (@svovaf) * @since 2.1.0 */ public function remove_opt_in_notice() { $this->_notices->remove_sticky( "gdpr_optin_actions_{$this->_wp_user_id}", true ); $this->disable_opt_in_notice(); } /** * Prevents the opt-in message from being added/shown. * * @author Leo Fajardo (@leorw) * @since 2.1.0 */ public function disable_opt_in_notice() { $this->update_option( 'show_opt_in_notice', false ); } /** * Checks if a GDPR opt-in message needs to be shown to the current admin. * * @author Vova Feldman (@svovaf) * @since 2.1.0 * * @return bool */ public function should_show_opt_in_notice() { return ( ! isset( $this->_data['show_opt_in_notice'] ) || true === $this->_data['show_opt_in_notice'] ); } /** * Get the last time the GDPR opt-in notice was shown. * * @author Vova Feldman (@svovaf) * @since 2.1.0 * * @return false|int */ public function last_time_notice_was_shown() { return isset( $this->_data['notice_shown_at'] ) ? $this->_data['notice_shown_at'] : false; } /** * Update the timestamp of the last time the GDPR opt-in message was shown to now. * * @author Vova Feldman (@svovaf) * @since 2.1.0 */ public function notice_was_just_shown() { $this->update_option( 'notice_shown_at', WP_FS__SCRIPT_START_TIME ); } /** * @param string $message * @param string|null $plugin_title * * @author Vova Feldman (@svovaf) * @since 2.1.0 */ public function add_opt_in_sticky_notice( $message, $plugin_title = null ) { $this->_notices->add_sticky( $message, "gdpr_optin_actions_{$this->_wp_user_id}", '', 'promotion', true, $this->_wp_user_id, $plugin_title, true ); } }