-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuserfeedback.php
348 lines (303 loc) · 9.63 KB
/
userfeedback.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
<?php
/**
* Plugin Name: UserFeedback Lite
* Plugin URI: https://www.userfeedback.com/lite?utm_source=liteplugin&utm_medium=pluginlist
* Description: See what your analytics software isn’t telling you with powerful UserFeedback surveys.
* Author: UserFeedback Team
* Version: 1.0.17
* Requires PHP: 5.6
* Requires at least: 5.9.0
* Author URI: https://userfeedback.com/lite
* Text Domain: userfeedback
* Domain Path: /languages
*
* @category Plugin
* @copyright Copyright © 2022 UserFeedback
* @author David Paternina
* @package UserFeedback
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
require_once 'userfeedback-base.php';
/**
* Main plugin class
*
* @since 1.0.0
*
* @package UserFeedback
* @author David Paternina
* @access public
*/
final class UserFeedback_Lite extends UserFeedback_Base {
/**
* @inheritdoc
*/
public $plugin_name = 'UserFeedback Lite';
/**
* @inheritdoc
*/
public $plugin_slug = 'userfeedback-lite';
/**
*
*/
public function __construct() {
$this->file = __FILE__;
add_filter( 'userfeedback_vue_notices', array( $this, 'add_vue_notices' ) );
add_filter( 'userfeedback_vue_wp_notices', array( $this, 'add_vue_wp_notices' ) );
add_action( 'wp_logout', array( $this, 'handle_user_logout' ) );
// Admin footer text.
add_filter( 'admin_footer_text', [ $this, 'admin_footer' ], 1, 2 );
}
/**
* Run tasks before user is logged out.
*
* @param $notices
* @return mixed
*/
public function handle_user_logout( $user_id ) {
$upgrade_notice_id = 'lite-upgrade-prompt';
delete_user_meta( $user_id, userfeedback_get_notice_hide_opt_prefix() . $upgrade_notice_id );
}
/**
* Add Vue notices for Lite plugin
*
* @param $notices
* @return mixed
*/
public function add_vue_notices( $notices ) {
// Lite Upgrade prompt
$upgrade_notice_id = 'lite-upgrade-prompt';
$user_upgrade_prompt = get_user_meta( get_current_user_id(), userfeedback_get_notice_hide_opt_prefix() . $upgrade_notice_id, true );
// $show_upgrade_prompt = get_option( userfeedback_get_notice_hide_opt_prefix() . $upgrade_notice_id, 0 );
$show_upgrade_prompt = ( $user_upgrade_prompt == '' ) ? 0 : $user_upgrade_prompt;
if ( time() - $show_upgrade_prompt > 14 * DAY_IN_SECONDS ) {
$show_upgrade_prompt = true;
} else {
$show_upgrade_prompt = false;
}
if ( $show_upgrade_prompt ) {
$upgrade_link = userfeedback_get_upgrade_link( 'floatbar', 'upgrade' );
$notices[] = array(
'id' => $upgrade_notice_id,
'content' =>
sprintf(
__( "%1\$sYou're using UserFeedback Lite%2\$s. To unlock all our features, consider %3\$supgrading to PRO%4\$s for 50% off.", 'userfeedback' ),
'<b>',
'</b>',
'<a target="_blank" rel="noopener" href="' . $upgrade_link . '">',
'</a>'
),
'icon' => 'exclamation-circle'
);
}
return $notices;
}
/**
* Add Vue Wp notices
*
* @param $notices
* @return mixed
*/
public function add_vue_wp_notices( $notices ) {
$notices = [];
// show complete onboarding notice
$onboarding_step = userfeedback_get_option( 'userfeedback_onboarding_step', false );
$onboarding_complete = get_option( 'userfeedback_onboarding_complete', false );
$surveys = UserFeedback_Survey::all();
// bail if onboarding is complete
if( $onboarding_complete ){
return $notices;
}
// bail if published surveys exist
if( !empty($surveys) ){
return $notices;
}
$button_text = __('Launch Wizard', 'userfeedback');
$button_link = admin_url('admin.php?page=userfeedback_onboarding');
if( 'install-complete' === $onboarding_step && empty($surveys) ) {
$button_text = __('Create Survey', 'userfeedback');
$button_link = admin_url('admin.php?page=userfeedback_surveys#/new');
}
if( 'install-complete' !== $onboarding_step ) {
$notices[] = array(
'id' => 'complete-onboarding',
'content' => sprintf(
__('<p><strong>Welcome to UserFeedback!</strong><br>Thanks for installing UserFeedback to collect real user feedback from your website visitors. Now that you’ve installed our plugin, you’re less than 2 minutes away from launching a survey.</p>
<p><a href="%s" class="button user-feedback-button" rel="noopener">%s</a></p>', 'userfeedback'),
$button_link,
$button_text
),
'dismissable' => false,
'type' => 'info'
);
}
foreach ( $notices as $key => $notice ) {
if ( ! empty( $notice['id'] ) ) {
$hide_notice = get_user_meta( get_current_user_id(), userfeedback_get_wp_notice_hide_opt_prefix() . $notice['id'], true );
if ( $hide_notice ) {
unset( $notices[ $key ] );
}
}
}
return $notices;
}
/**
* @inheritdoc
*/
public function define_globals() {
parent::define_globals();
if ( ! defined( 'USERFEEDBACK_LITE_VERSION' ) ) {
define( 'USERFEEDBACK_LITE_VERSION', USERFEEDBACK_VERSION );
}
}
/**
* @inheritdoc
*/
public function check_for_dual_installation() {
// Detect Pro version and return early
if ( class_exists( 'UserFeedback_Pro' ) ) {
add_action( 'admin_notices', array( self::$instance, 'userfeedback_pro_notice' ) );
return true;
}
return false;
}
/**
* @inheritdoc
*/
public function load_instance_properties() {
if ( is_admin() ) {
require_once USERFEEDBACK_PLUGIN_DIR . 'lite/includes/admin/class-userfeedback-connect.php';
}
}
/**
* @inheritdoc
*/
public function define_instance_globals() {
}
/**
* Output a nag notice if the user has both Lite and Pro activated
*
* @access public
* @since 1.0.0
*
* @return void
*/
public function userfeedback_pro_notice() {
$url = admin_url( 'plugins.php' );
// Check for MS dashboard
if ( is_network_admin() ) {
$url = network_admin_url( 'plugins.php' );
}
?>
<div class="error">
<p><?php echo sprintf( esc_html__( 'Please %1$suninstall%2$s the UserFeedback Lite Plugin. Your Pro version of UserFeedback may not work as expected until the Lite version is uninstalled.', 'userfeedback' ), '<a href="' . esc_url_raw($url) . '">', '</a>' ); ?></p>
</div>
<?php
}
/**
* When user is on a UserFeedback related admin page, display footer text
* that graciously asks them to rate us.
*
* @since 1.0.5
*
* @param string $text Footer text.
*
* @return string
*/
public function admin_footer($text){
global $current_screen;
if ( ! empty( $current_screen->id ) && strpos( $current_screen->id, 'userfeedback' ) !== false ) {
$url = 'https://wordpress.org/support/plugin/userfeedback-lite/reviews/?filter=5#new-post';
$text = sprintf(
wp_kses( /* translators: $1$s - UserFeedback plugin name; $2$s - WP.org review link; $3$s - WP.org review link. */
__( 'Please rate %1$s <a href="%2$s" target="_blank" rel="noopener noreferrer">★★★★★</a> on <a href="%3$s" target="_blank" rel="noopener">WordPress.org</a> to help us spread the word.', 'userfeedback' ),
[
'a' => [
'href' => [],
'target' => [],
'rel' => [],
],
]
),
'<strong>UserFeedback</strong>',
$url,
$url
);
}
return $text;
}
}
/**
* Fired when the plugin is activated.
*
* @access public
* @since 1.0.0
*
* @global int $wp_version The version of WordPress for this install.
* @global object $wpdb The WordPress database object.
* @param boolean $network_wide True if WPMU superadmin uses "Network Activate" action, false otherwise.
*
* @return void
*/
function userfeedback_lite_activation_hook( $network_wide ) {
$url = admin_url( 'plugins.php' );
// Check for MS dashboard
if ( is_network_admin() ) {
$url = network_admin_url( 'plugins.php' );
}
if ( class_exists( 'UserFeedback' ) ) {
deactivate_plugins( plugin_basename( __FILE__ ) );
wp_die( sprintf( esc_html__( 'Please uninstall and remove UserFeedback Premium before activating UserFeedback Lite. The Lite version has not been activated. %1$sClick here to return to the Dashboard%2$s.', 'userfeedback' ), '<a href="' . esc_url_raw($url) . '">', '</a>' ) );
}
require_once plugin_dir_path( __FILE__ ) . 'includes/class-userfeedback-compatibility-check.php';
$compatibility = UserFeedback_Compatibility_Check::get_instance();
$compatibility->maybe_deactivate_plugin( plugin_basename( __FILE__ ) );
// Remove license key if saved.
delete_option( 'userfeedback_license' );
// Add transient to trigger redirect.
set_transient( '_userfeedback_activation_redirect', 1, 30 );
}
register_activation_hook( __FILE__, 'userfeedback_lite_activation_hook' );
/**
* Fired when the plugin is uninstalled.
*
* @access public
* @since 1.0.0
*
* @return void
*/
function userfeedback_uninstall_hook() {
wp_cache_flush();
$instance = UserFeedback();
// Don't delete any data if the PRO version is already active.
if ( userfeedback_is_pro_version() ) {
return;
}
// Remove email summaries cron jobs.
wp_clear_scheduled_hook( 'userfeedback_email_summaries_cron' );
// Delete the notifications data.
$instance->notifications->delete_notifications_data();
// Delete other options.
userfeedback_uninstall_remove_options();
}
register_uninstall_hook( __FILE__, 'userfeedback_uninstall_hook' );
/**
* The main function responsible for returning the one true UserFeedback_Lite
* Instance to functions everywhere.
*
* Use this function like you would a global variable, except without needing
* to declare the global.
*
* Example: <?php $userfeedback = UserFeedback_Lite(); ?>
*
* @since 1.0.0
*
* @uses UserFeedback_Lite::get_instance() Retrieve UserFeedback_Lite instance.
*
* @return UserFeedback_Lite The singleton UserFeedback_Lite instance.
*/
function UserFeedback_Lite() {
return UserFeedback_Lite::get_instance();
}