Support
2 months ago
Cross.php
2 months ago
Fallback.php
2 months ago
Fields.php
2 months ago
Helper.php
2 months ago
I18n.php
2 months ago
Plugin.php
2 months ago
Popup.php
2 months ago
PostType.php
2 months ago
Review.php
2 months ago
Settings.php
2 months ago
Shortcode.php
2 months ago
Upgrade.php
2 months 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 && '1' !== $option ) { |
| 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 ( '1' === $option ) { |
| 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 = isset( $_POST['field'] ) ? sanitize_text_field( $_POST['field'] ) : ''; |
| 46 | |
| 47 | if ( 'later' === $field ) { |
| 48 | $this->need_update_option( 3 ); |
| 49 | } elseif ( 'alreadyDid' === $field || '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 ? 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 esc_attr( $selector ); ?>"> |
| 69 | <h3><?php echo esc_html( "Give {$this->pluginName} a review" ); ?></h3> |
| 70 | <p> |
| 71 | <?php echo esc_html( "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 | <?php echo esc_html__( 'We will be forever grateful. Thank you in advance.', 'wp-whatsapp' ); ?> |
| 75 | </p> |
| 76 | <p> |
| 77 | <a href="javascript:;" data="rateNow" class="button button-primary" style="margin-right: 5px"><?php esc_html_e( 'Rate now', 'wp-whatsapp' ); ?></a> |
| 78 | <a href="javascript:;" data="later" class="button" style="margin-right: 5px"><?php esc_html_e( 'Later', 'wp-whatsapp' ); ?></a> |
| 79 | <a href="javascript:;" data="alreadyDid" class="button"><?php esc_html_e( 'No, thanks', 'wp-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', 'wp-whatsapp' ); |
| 139 | } |
| 140 | |
| 141 | |
| 142 | |
| 143 |