PluginProbe ʕ •ᴥ•ʔ
WP Chat App / 3.4.2
WP Chat App v3.4.2
3.8.1 3.8.2 trunk 2.6 3.4 3.4.1 3.4.2 3.4.4 3.4.5 3.4.6 3.5 3.6 3.6.1 3.6.2 3.6.3 3.6.4 3.6.5 3.6.6 3.6.7 3.6.8 3.6.9 3.7.0 3.7.1 3.7.2 3.7.3 3.7.4 3.8.0
wp-whatsapp / includes / Review.php
wp-whatsapp / includes Last commit date
Recommended 2 years ago Support 2 years ago Cross.php 2 years ago Fallback.php 2 years ago Fields.php 2 years ago Helper.php 2 years ago I18n.php 2 years ago Plugin.php 2 years ago Popup.php 2 years ago PostType.php 2 years ago Review.php 2 years ago Settings.php 2 years ago Shortcode.php 2 years ago Upgrade.php 2 years ago
Review.php
143 lines
1 <?php
2 defined( 'ABSPATH' ) || exit;
3
4 if ( ! class_exists( 'NjtReview' ) ) {
5 class NjtReview {
6
7 public $pluginPrefix = '';
8 public $pluginName = '';
9 public $textDomain = '';
10 public $pluginDirURL = '';
11
12 public $reviewed = false;
13
14 protected static $instance = null;
15
16 public function __construct( $pluginPrefix, $pluginName, $textDomain ) {
17 $this->pluginPrefix = $pluginPrefix;
18 $this->pluginName = $pluginName;
19 $this->textDomain = $textDomain;
20 }
21
22 public static function get_instance( $pluginPrefix, $pluginName, $textDomain ) {
23 if ( null == self::$instance ) {
24 self::$instance = new self( $pluginPrefix, $pluginName, $textDomain );
25 self::$instance->doHooks();
26 }
27 return self::$instance;
28 }
29
30 public function doHooks() {
31 $option = get_option( "{$this->pluginPrefix}_review" );
32 if ( time() >= (int) $option && $option !== '1' ) {
33 add_action( 'admin_notices', array( $this, 'add_notification' ) );
34 add_action( "wp_ajax_{$this->pluginPrefix}_save_review", array( $this, 'save_review' ) );
35 }
36
37 if ( $option == '1' ) {
38 $this->reviewed = true;
39 }
40 }
41
42 public function save_review() {
43 check_ajax_referer( 'njt_wa_review_nonce', 'nonce', true );
44
45 $field = sanitize_text_field( $_POST['field'] );
46
47 if ( $field == 'later' ) {
48 $this->need_update_option( 3 );
49 } elseif ( $field == 'alreadyDid' || 'rateNow' == $field ) {
50 update_option( "{$this->pluginPrefix}_review", 1 );
51 }
52 wp_send_json_success();
53 }
54
55 public function need_update_option( $days = null, $now = false ) {
56 if ( $this->reviewed ) {
57 return;
58 }
59 $time = $now === true ? time() : ( time() + ( $days * 60 * 60 * 24 ) );
60 update_option( "{$this->pluginPrefix}_review", $time );
61 }
62
63 public function add_notification() {
64 if ( function_exists( 'get_current_screen' ) ) {
65 if ( get_current_screen()->id == 'plugins' || get_post_type() == 'whatsapp-accounts' ) {
66 $selector = esc_attr( $this->pluginPrefix ) . '-review';
67 ?>
68 <div class="notice notice-success is-dismissible" id="<?php echo $selector; ?>">
69 <h3><?php _e( "Give {$this->pluginName} a review" ); ?></h3>
70 <p>
71 <?php _e( "Thank you for choosing {$this->pluginName}. We hope you love it. Could you take a couple of seconds posting a nice review to share your happy experience?" ); ?>
72 </p>
73 <p>
74 We will be forever grateful. Thank you in advance.
75 </p>
76 <p>
77 <a href="javascript:;" data="rateNow" class="button button-primary" style="margin-right: 5px"><?php esc_html_e( 'Rate now', 'ninjateam-whatsapp' ); ?></a>
78 <a href="javascript:;" data="later" class="button" style="margin-right: 5px"><?php esc_html_e( 'Later', 'ninjateam-whatsapp' ); ?></a>
79 <a href="javascript:;" data="alreadyDid" class="button"><?php esc_html_e( 'No, thanks', 'ninjateam-whatsapp' ); ?></a>
80 </p>
81 </div>
82 <script>
83 jQuery(document).ready(function () {
84 jQuery('body').on('click', '#njt_wa-review a,#njt_wa-review button.notice-dismiss', function() {
85 var thisElement = this;
86 var fieldValue = jQuery(thisElement).attr("data");
87 var link = "https://wordpress.org/support/plugin/wp-whatsapp/reviews/#new-post";
88 var hidePopup = false;
89 if (fieldValue == "rateNow") {
90 window.open(link, "_blank");
91 } else {
92 hidePopup = true;
93 }
94
95 if (jQuery(thisElement).hasClass('notice-dismiss')) {
96 fieldValue = 'later'
97 }
98
99 jQuery.ajax({
100 dataType: 'json',
101 url: window.ajaxurl,
102 type: "post",
103 data: {
104 action: 'njt_wa_save_review',
105 field: fieldValue,
106 nonce: '<?php echo esc_attr( wp_create_nonce( 'njt_wa_review_nonce' ) ); ?>',
107 },
108 }).done(function (result) {
109 if (result.success) {
110 if (hidePopup == true) {
111 jQuery('#njt_wa-review').hide("slow");
112 }
113 } else {
114 console.log("Error", result.message);
115 if (hidePopup == true) {
116 jQuery('#njt_wa-review').hide("slow");
117 }
118 }
119 }).fail(function (res) {
120 console.log(res.responseText);
121
122 if (hidePopup == true) {
123 jQuery('#njt_wa-review').hide("slow");
124 }
125 });
126 })
127 });
128 </script>
129 <?php
130 }
131 }
132 }
133 }
134 }
135
136 if ( ! class_exists( 'NJTWhatsAppReview' ) ) {
137 class NJTWhatsAppReview extends NjtReview {}
138 NJTWhatsAppReview::get_instance( 'njt_wa', 'WhatsApp Plugin', 'ninjateam-whatsapp' );
139 }
140
141
142
143