| 1 | <?php |
|---|
| 2 | namespace FileBird\Classes; |
|---|
| 3 | |
|---|
| 4 | defined( 'ABSPATH' ) || exit; |
|---|
| 5 | |
|---|
| 6 | class Review { |
|---|
| 7 | public function __construct() { |
|---|
| 8 | add_action( 'wp_ajax_fbv_save_review', array( $this, 'fbv_save_review' ) ); |
|---|
| 9 | |
|---|
| 10 | $option = get_option( 'fbv_review', false ); |
|---|
| 11 | if ( time() >= intval( $option ) && '0' !== $option ) { |
|---|
| 12 | add_action( 'admin_notices', array( $this, 'give_review' ) ); |
|---|
| 13 | } |
|---|
| 14 | } |
|---|
| 15 | |
|---|
| 16 | public function enqueue_scripts() { |
|---|
| 17 | wp_enqueue_script( 'fbv-review', NJFB_PLUGIN_URL . 'assets/js/review.js', array( 'jquery' ), NJFB_VERSION, false ); |
|---|
| 18 | } |
|---|
| 19 | |
|---|
| 20 | public function checkNonce( $nonce ) { |
|---|
| 21 | if ( ! wp_verify_nonce( $nonce, 'fbv_nonce' ) ) { |
|---|
| 22 | wp_send_json_error( array( 'status' => 'Wrong nonce validate!' ) ); |
|---|
| 23 | exit(); |
|---|
| 24 | } |
|---|
| 25 | } |
|---|
| 26 | |
|---|
| 27 | public function hasField( $field, $request ) { |
|---|
| 28 | return isset( $request[ $field ] ) ? sanitize_text_field( $request[ $field ] ) : null; |
|---|
| 29 | } |
|---|
| 30 | |
|---|
| 31 | public function fbv_save_review() { |
|---|
| 32 | if ( ! current_user_can( 'manage_options' ) ) { |
|---|
| 33 | wp_send_json_error( |
|---|
| 34 | array( 'mess' => __( 'You do not have permission to perform this action.', 'filebird' ) ), |
|---|
| 35 | 403 |
|---|
| 36 | ); |
|---|
| 37 | } |
|---|
| 38 | |
|---|
| 39 | if ( count( $_REQUEST ) ) { |
|---|
| 40 | $nonce = $this->hasField( 'nonce', $_REQUEST ); |
|---|
| 41 | $field = $this->hasField( 'field', $_REQUEST ); |
|---|
| 42 | |
|---|
| 43 | $this->checkNonce( $nonce ); |
|---|
| 44 | |
|---|
| 45 | if ( 'later' == $field ) { |
|---|
| 46 | update_option( 'fbv_review', time() + 5 * 60 * 60 * 24 ); //After 3 days show |
|---|
| 47 | } elseif ( 'alreadyDid' == $field || 'rateNow' == $field ) { |
|---|
| 48 | update_option( 'fbv_review', 0 ); |
|---|
| 49 | } |
|---|
| 50 | wp_send_json_success(); |
|---|
| 51 | } |
|---|
| 52 | wp_send_json_error( array( 'message' => 'Update fail!' ) ); |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | public static function update_time_display() { |
|---|
| 56 | $option = get_option( 'fbv_review', false ); |
|---|
| 57 | if ( '0' !== $option ) { |
|---|
| 58 | update_option( 'fbv_review', time() + 3 * 60 * 60 * 24 ); //After 3 days show |
|---|
| 59 | } |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | public function give_review() { |
|---|
| 63 | if ( function_exists( 'get_current_screen' ) ) { |
|---|
| 64 | if ( get_current_screen()->id == 'upload' || get_current_screen()->id == 'plugins' ) { |
|---|
| 65 | $this->enqueue_scripts(); |
|---|
| 66 | ?> |
|---|
| 67 | <div class="notice notice-success is-dismissible filebird-notice" id="njt-FileBird-review"> |
|---|
| 68 | <h3><?php esc_html_e( 'Give FileBird a review', 'filebird' ); ?></h3> |
|---|
| 69 | <p> |
|---|
| 70 | <?php esc_html_e( 'Thank you for choosing FileBird. We hope you love it. Could you take a couple of seconds posting a nice review to share your happy experience?', 'filebird' ); ?> |
|---|
| 71 | </p> |
|---|
| 72 | <p> |
|---|
| 73 | <?php esc_html_e( 'We will be forever grateful. Thank you in advance ;)', 'filebird' ); ?> |
|---|
| 74 | </p> |
|---|
| 75 | <p> |
|---|
| 76 | <a href="javascript:;" data="rateNow" |
|---|
| 77 | class="button button-primary"><?php esc_html_e( 'Rate now', 'filebird' ); ?></a> |
|---|
| 78 | <a href="javascript:;" data="later" class="button"><?php esc_html_e( 'Later', 'filebird' ); ?></a> |
|---|
| 79 | <a href="javascript:;" data="alreadyDid" class="button"><?php esc_html_e( 'No, thanks', 'filebird' ); ?></a> |
|---|
| 80 | </p> |
|---|
| 81 | </div> |
|---|
| 82 | <?php |
|---|
| 83 | } |
|---|
| 84 | } |
|---|
| 85 | } |
|---|
| 86 | } |
|---|