review.php
3.89 KB
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
<?php
if ( ! class_exists( 'NjtCF7MLSReview' ) ) {
class NjtCF7MLSReview {
public function __construct() {
$this->doHooks();
}
private function doHooks() {
add_action( 'wp_ajax_cf7mls_save_review', array( $this, 'cf7mls_save_review' ) );
$option = get_option( 'cf7mls_review' );
if ( time() >= (int) $option && $option !== '0' ) {
add_action( 'admin_notices', array( $this, 'give_review' ) );
}
}
public function checkNonce( $nonce ) {
if ( ! wp_verify_nonce( $nonce, 'cf7mls_review_nonce' ) ) {
wp_send_json_error( array( 'status' => 'Wrong nonce validate!' ) );
exit();
}
}
public function hasField( $field, $request ) {
return isset( $request[ $field ] ) ? sanitize_text_field( $request[ $field ] ) : null;
}
public function cf7mls_save_review() {
if ( count( $_REQUEST ) ) {
$nonce = $this->hasField( 'nonce', $_REQUEST );
$field = $this->hasField( 'field', $_REQUEST );
$this->checkNonce( $nonce );
if ( $field == 'later' ) {
update_option( 'cf7mls_review', time() + 3 * 60 * 60 * 24 ); // After 3 days show
} elseif ( $field == 'alreadyDid' ) {
update_option( 'cf7mls_review', 0 );
}
wp_send_json_success();
}
wp_send_json_error( array( 'message' => 'Update fail!' ) );
}
public function give_review() {
if ( function_exists( 'get_current_screen' ) ) {
if ( get_current_screen()->id == 'dashboard' || get_current_screen()->id == 'toplevel_page_wpcf7' || strpos( get_current_screen()->id, 'contact_page_wpcf7' ) !== false || get_current_screen()->id == 'upload' || get_current_screen()->id == 'plugins' ) {
?>
<div class="notice notice-success is-dismissible" id="njt-cf7mls-review">
<h3 style="margin: 1em 0;"><?php _e( 'Give Multi Step for Contact Form 7 a review', 'cf7mls' ); ?></h3>
<p>
<?php _e( 'Thank you for choosing Multi Step for Contact Form 7. We hope you love it. Could you take a couple of seconds posting a nice review to share your happy experience?', 'cf7mls' ); ?>
</p>
<p>
<?php _e( 'We will be forever grateful. Thank you in advance ;)', 'cf7mls' ); ?>
</p>
<p>
<a href="javascript:;" data="rateNow" class="button button-primary" style="margin-right: 5px"><?php _e( 'Rate now', 'cf7mls' ); ?></a>
<a href="javascript:;" data="later" class="button" style="margin-right: 5px"><?php _e( 'Later', 'cf7mls' ); ?></a>
<a href="javascript:;" data="alreadyDid" class="button"><?php _e( 'Already did', 'cf7mls' ); ?></a>
</p>
</div>
<script>
jQuery(document).ready(function () {
jQuery("#njt-cf7mls-review a").on("click", function () {
var thisElement = this;
var fieldValue = jQuery(thisElement).attr("data");
var proLink = "https://codecanyon.net/item/contact-form-7-multistep/reviews/15232990";
var freeLink = "https://wordpress.org/support/plugin/cf7-multi-step/reviews/?filter=5#new-post";
var hidePopup = false;
if (fieldValue == "rateNow") {
window.open(freeLink, "_blank");
} else {
hidePopup = true;
}
jQuery
.ajax({
dataType: 'json',
url: '<?php echo admin_url( 'admin-ajax.php' ); ?>',
type: "post",
data: {
action: "cf7mls_save_review",
field: fieldValue,
nonce: '<?php echo wp_create_nonce( 'cf7mls_review_nonce' ); ?>',
},
})
.done(function (result) {
if (result.success) {
if (hidePopup == true) {
jQuery("#njt-cf7mls-review").hide("slow");
}
} else {
console.log("Error", result.message);
if (hidePopup == true) {
jQuery("#njt-cf7mls-review").hide("slow");
}
}
})
.fail(function (res) {
console.log(res.responseText);
if (hidePopup == true) {
jQuery("#njt-cf7mls-review").hide("slow");
}
});
});
});
</script>
<?php
}
}
}
}
new NjtCF7MLSReview();
}