-
Notifications
You must be signed in to change notification settings - Fork 3
/
class-review.php
188 lines (163 loc) · 5.69 KB
/
class-review.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
<?php
/*100% match*/
defined( 'ABSPATH' ) or die( "you do not have acces to this page!" );
if ( ! class_exists( "cmplz_tc_review" ) ) {
class cmplz_tc_review {
private static $_this;
function __construct() {
if ( isset( self::$_this ) ) {
wp_die( sprintf( '%s is a singleton class and you cannot create a second instance.',
get_class( $this ) ) );
}
self::$_this = $this;
//uncomment for testing
// update_option('cmplz_tc_review_notice_shown', false);
// update_option( 'cmplz_tc_activation_time', strtotime( "-2 month" ) );
//show review notice, only to free users
if ( ! defined( "cmplz_tc_premium" ) && ! is_multisite() ) {
if ( ! get_option( 'cmplz_tc_review_notice_shown' )
&& get_option( 'cmplz_tc_activation_time' )
&& get_option( 'cmplz_tc_activation_time' )
< strtotime( "-1 month" )
) {
add_action( 'wp_ajax_dismiss_review_notice',
array( $this, 'dismiss_review_notice_callback' ) );
add_action( 'admin_notices',
array( $this, 'show_leave_review_notice' ) );
add_action( 'admin_print_footer_scripts',
array( $this, 'insert_dismiss_review' ) );
}
//set a time for users who didn't have it set yet.
if ( ! get_option( 'cmplz_tc_activation_time' ) ) {
update_option( 'cmplz_tc_activation_time', time() );
}
}
add_action('admin_init', array($this, 'process_get_review_dismiss' ));
}
static function this() {
return self::$_this;
}
public function show_leave_review_notice() {
if (isset( $_GET['cmplz_tc_dismiss_review'] ) ) return;
/**
* Prevent notice from being shown on Gutenberg page, as it strips off the class we need for the ajax callback.
*
* */
$screen = get_current_screen();
if ( $screen->parent_base === 'edit' ) {
return;
}
?>
<style>
.cmplz-container {
display: flex;
padding: 12px;
}
.cmplz-container .dashicons {
margin-left: 10px;
margin-right: 5px;
}
.cmplz-review-image img {
margin-top: 0.5em;
}
.cmplz-buttons-row {
margin-top: 10px;
display: flex;
align-items: center;
}
</style>
<div id="message"
class="updated fade notice is-dismissible cmplz-review really-simple-plugins"
style="border-left:4px solid #333">
<div class="cmplz-container">
<div class="cmplz-review-image"><img width=80px"
src="<?php echo cmplz_tc_url ?>/assets/images/icon-128x128.png"
alt="review-logo">
</div>
<div style="margin-left:30px">
<p><?php printf( __( 'Hi, you have been using Complianz Terms & Conditions for a month now, awesome! If you have a moment, please consider leaving a review on WordPress.org to spread the word. We greatly appreciate it! If you have any questions or feedback, leave us a %smessage%s.',
'complianz-terms-conditions' ),
'<a href="https://complianz.io/contact" target="_blank">',
'</a>' ); ?></p>
<i>- Rogier</i>
<div class="cmplz-buttons-row">
<a class="button button-primary" target="_blank" href="https://wordpress.org/support/plugin/complianz-terms-conditions/reviews/#new-post"><?php _e( 'Leave a review', 'complianz-terms-conditions' ); ?></a>
<div class="dashicons dashicons-calendar"></div>
<a href="#" id="maybe-later"><?php _e( 'Maybe later', 'complianz-terms-conditions' ); ?></a>
<div class="dashicons dashicons-no-alt"></div>
<a href="<?php echo add_query_arg(array( 'cmplz_tc_dismiss_review'=>1), cmplz_tc_settings_page() )?>"><?php _e( 'Don\'t show again',
'complianz-terms-conditions' ); ?></a>
</div>
</div>
</div>
</div>
<?php
}
/**
* Insert some ajax script to dismiss the review notice, and stop nagging about it
*
* @since 2.0
*
* @access public
*
* type: dismiss, later
*
*/
public function insert_dismiss_review() {
$ajax_nonce = wp_create_nonce( "cmplz_tc_dismiss_review" );
?>
<script type='text/javascript'>
jQuery(document).ready(function ($) {
$(".cmplz-review.notice.is-dismissible").on("click", ".notice-dismiss", function (event) {
rsssl_dismiss_review('dismiss');
});
$(".cmplz-review.notice.is-dismissible").on("click", "#maybe-later", function (event) {
rsssl_dismiss_review('later');
$(this).closest('.cmplz-review').remove();
});
$(".cmplz-review.notice.is-dismissible").on("click", ".review-dismiss", function (event) {
rsssl_dismiss_review('dismiss');
$(this).closest('.cmplz-review').remove();
});
function rsssl_dismiss_review(type) {
var data = {
'action': 'dismiss_review_notice',
'type': type,
'token': '<?php echo $ajax_nonce; ?>'
};
$.post(ajaxurl, data, function (response) {
});
}
});
</script>
<?php
}
/**
* Process the ajax dismissal of the review message.
*
* @since 2.1
*
* @access public
*
*/
public function dismiss_review_notice_callback() {
$type = isset( $_POST['type'] ) ? $_POST['type'] : false;
if ( sanitize_title($type) === 'dismiss' ) {
update_option( 'cmplz_tc_review_notice_shown', true );
}
if ( sanitize_title($type) === 'later' ) {
//Reset activation timestamp, notice will show again in one month.
update_option( 'cmplz_tc_activation_time', time() );
}
wp_die(); // this is required to terminate immediately and return a proper response
}
/**
* Dismiss review notice with get, which is more stable
*/
public function process_get_review_dismiss(){
if (isset( $_GET['cmplz_tc_dismiss_review'] ) ){
update_option( 'cmplz_tc_review_notice_shown', true );
}
}
}
}