background.png
2 years ago
banner-sample.php
2 years ago
class-get-values.php
2 years ago
includes.php
2 years ago
pisol.class.form.php
2 years ago
pisol.class.promotion.php
2 years ago
review-icon.svg
2 years ago
review.php
2 years ago
review.php
115 lines
| 1 | <?php |
| 2 | /* |
| 3 | v1.0.0 |
| 4 | */ |
| 5 | if(!class_exists('pisol_dtt_delivery_date_time_review')){ |
| 6 | class pisol_dtt_delivery_date_time_review{ |
| 7 | |
| 8 | public $title; |
| 9 | public $slug; |
| 10 | public $activation_date; |
| 11 | public $saved_value; |
| 12 | public $review_url; |
| 13 | public $review_after; |
| 14 | |
| 15 | function __construct($title, $slug ){ |
| 16 | if(function_exists('is_admin') && is_admin()){ |
| 17 | $this->title = $title; |
| 18 | $this->slug = $slug; |
| 19 | $this->activation_date = "pi_review_activation_date_{$this->slug}"; |
| 20 | $this->saved_value = "pi_review_saved_value_{$this->slug}"; |
| 21 | $this->review_url = "https://wordpress.org/support/plugin/{$this->slug}/reviews/?rate=5#new-post"; |
| 22 | $this->review_after = 6; |
| 23 | |
| 24 | //update_option($this->saved_value, array('preference'=> 'later', 'update_at'=>'2021/06/10')); |
| 25 | //delete_option($this->saved_value); |
| 26 | |
| 27 | add_action( 'admin_notices', array($this, 'display_admin_notice'),20 ); |
| 28 | add_action( "admin_post_pi_save_review_preference_{$this->slug}", array($this, 'savePreference'),20 ); |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | function display_admin_notice() { |
| 33 | |
| 34 | $options = get_option($this->saved_value); |
| 35 | |
| 36 | $activation_time = $this->getInstallationDate(); |
| 37 | |
| 38 | $notice = '<div class="notice notice-success is-dismissible">'; |
| 39 | $notice .= '<div style="display:flex;">'; |
| 40 | $notice .= '<img style="max-width:90px; height:auto;" src="'.plugin_dir_url( __FILE__ ).'review-icon.svg" alt="pi web solution">'; |
| 41 | $notice .= '<div style="margin-left:20px;">'; |
| 42 | $notice .= '<p><b>'.__("We have worked hard to develop the plugin and it would really appreciate us if you dropped a short review about the plugin. Your review means a lot to us and we are working to make the plugin more awesome. Thanks for using {$this->title}").'</b></p>'; |
| 43 | $notice .= '<ul style="display: inline-grid; |
| 44 | grid-template-columns: 1fr 1fr 1fr; |
| 45 | grid-column-gap: 20px; |
| 46 | text-align: center;">'; |
| 47 | $notice .= '<li><a val="later" href="'.add_query_arg(array('action' => "pi_save_review_preference_{$this->slug}", 'preference'=>'later', '_wpnonce'=>wp_create_nonce( "pi_save_review_preference_{$this->slug}" )), admin_url('admin-post.php')).'">'.__("Remind me later").'</a></li>'; |
| 48 | $notice .= '<li><a style="font-weight:bold;" val="given" href="'.add_query_arg(array('action' => "pi_save_review_preference_{$this->slug}", 'preference'=>'now','_wpnonce'=>wp_create_nonce( "pi_save_review_preference_{$this->slug}" )), admin_url('admin-post.php')).'" target="_blank">'.__("Review Here").'</a></li>'; |
| 49 | $notice .= '<li><a val="never" href="'.add_query_arg(array('action' => "pi_save_review_preference_{$this->slug}", 'preference'=>'never', '_wpnonce'=>wp_create_nonce( "pi_save_review_preference_{$this->slug}" )), admin_url('admin-post.php')).'">'.__("I would not").'</a></li>'; |
| 50 | $notice .= '</ul>'; |
| 51 | $notice .= '</div>'; |
| 52 | $notice .= '</div>'; |
| 53 | $notice .= '</div>'; |
| 54 | |
| 55 | if(!$options && current_time('timestamp') >= strtotime($activation_time." +{$this->review_after} days")){ |
| 56 | echo $notice; |
| 57 | } else if(is_array($options)) { |
| 58 | if( array_key_exists('preference', $options) && array_key_exists('update_at', $options) && $options['preference'] =='later'){ |
| 59 | if($this->validateDate($options['update_at']) && current_time('timestamp') >= strtotime($options['update_at']." +{$this->review_after} days")){ |
| 60 | echo $notice; |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | function savePreference(){ |
| 67 | $nonce = isset($_GET['_wpnonce']) ? sanitize_text_field($_GET['_wpnonce']) : '' ; |
| 68 | $preference = isset($_GET['preference']) ? sanitize_text_field($_GET['preference']) : 'later'; |
| 69 | |
| 70 | if(!isset($_GET['_wpnonce']) || !wp_verify_nonce($nonce,"pi_save_review_preference_{$this->slug}")){ |
| 71 | wp_die(__('Link has expired'), '', array('response' => 403)); |
| 72 | } |
| 73 | |
| 74 | $values['update_at'] = current_time('Y/m/d'); |
| 75 | switch($preference){ |
| 76 | case 'later': |
| 77 | $values['preference'] = 'later'; |
| 78 | $redirect = admin_url('index.php'); |
| 79 | break; |
| 80 | |
| 81 | case 'now': |
| 82 | $values['preference'] = 'now'; |
| 83 | $redirect = $this->review_url; |
| 84 | break; |
| 85 | |
| 86 | case 'never': |
| 87 | $values['preference'] = 'never'; |
| 88 | $redirect = admin_url('index.php'); |
| 89 | break; |
| 90 | } |
| 91 | update_option($this->saved_value, $values); |
| 92 | wp_redirect($redirect); |
| 93 | } |
| 94 | |
| 95 | function getInstallationDate(){ |
| 96 | $get_install_date = get_option($this->activation_date); |
| 97 | if(empty($get_install_date) || !$this->validateDate($get_install_date)){ |
| 98 | $now = current_time( "Y/m/d" ); |
| 99 | add_option( $this->activation_date, $now ); |
| 100 | return $now; |
| 101 | } |
| 102 | return $get_install_date; |
| 103 | } |
| 104 | |
| 105 | function validateDate($date, $format = 'Y/m/d'){ |
| 106 | if ( empty($date) ) return false; |
| 107 | |
| 108 | $d = DateTime::createFromFormat($format, $date); |
| 109 | // The Y ( 4 digits year ) returns TRUE for any integer with any number of digits so changing the comparison from == to === fixes the issue. |
| 110 | return $d && $d->format($format) === $date; |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | new pisol_dtt_delivery_date_time_review('Delivery date and time pickup location plugin', 'pi-woocommerce-order-date-time-and-type'); |
| 115 | } |