title = $title; $this->slug = $slug; $this->activation_date = "pi_review_activation_date_{$this->slug}"; $this->saved_value = "pi_review_saved_value_{$this->slug}"; $this->review_url = "https://wordpress.org/support/plugin/{$this->slug}/reviews/?rate=5#new-post"; $this->review_after = 3; $this->buy_url = $buy_url; $this->price = $price; $allowed_atts = array( 'align' => array(), 'class' => array(), 'selected' => array(), 'multiple' => array(), 'checked' => array(), 'type' => array(), 'id' => array(), 'dir' => array(), 'lang' => array(), 'style' => array(), 'xml:lang' => array(), 'src' => array(), 'alt' => array(), 'href' => array(), 'rel' => array(), 'rev' => array(), 'target' => array(), 'novalidate' => array(), 'type' => array(), 'value' => array(), 'name' => array(), 'tabindex' => array(), 'action' => array(), 'method' => array(), 'for' => array(), 'width' => array(), 'height' => array(), 'data' => array(), 'title' => array(), 'min' => array(), 'max' => array(), 'step' => array(), 'required' => array(), 'readonly' => array(), ); $this->allowed_tags['form'] = $allowed_atts; $this->allowed_tags['br'] = $allowed_atts; $this->allowed_tags['label'] = $allowed_atts; $this->allowed_tags['input'] = $allowed_atts; $this->allowed_tags['select'] = $allowed_atts; $this->allowed_tags['option'] = $allowed_atts; $this->allowed_tags['textarea'] = $allowed_atts; $this->allowed_tags['iframe'] = $allowed_atts; $this->allowed_tags['script'] = $allowed_atts; $this->allowed_tags['style'] = $allowed_atts; $this->allowed_tags['strong'] = $allowed_atts; $this->allowed_tags['small'] = $allowed_atts; $this->allowed_tags['table'] = $allowed_atts; $this->allowed_tags['span'] = $allowed_atts; $this->allowed_tags['abbr'] = $allowed_atts; $this->allowed_tags['code'] = $allowed_atts; $this->allowed_tags['pre'] = $allowed_atts; $this->allowed_tags['div'] = $allowed_atts; $this->allowed_tags['img'] = $allowed_atts; $this->allowed_tags['h1'] = $allowed_atts; $this->allowed_tags['h2'] = $allowed_atts; $this->allowed_tags['h3'] = $allowed_atts; $this->allowed_tags['h4'] = $allowed_atts; $this->allowed_tags['h5'] = $allowed_atts; $this->allowed_tags['h6'] = $allowed_atts; $this->allowed_tags['ol'] = $allowed_atts; $this->allowed_tags['ul'] = $allowed_atts; $this->allowed_tags['li'] = $allowed_atts; $this->allowed_tags['em'] = $allowed_atts; $this->allowed_tags['hr'] = $allowed_atts; $this->allowed_tags['br'] = $allowed_atts; $this->allowed_tags['tr'] = $allowed_atts; $this->allowed_tags['td'] = $allowed_atts; $this->allowed_tags['p'] = $allowed_atts; $this->allowed_tags['a'] = $allowed_atts; $this->allowed_tags['b'] = $allowed_atts; $this->allowed_tags['i'] = $allowed_atts; //update_option($this->saved_value, array('preference'=> 'later', 'update_at'=>'2021/06/10')); //delete_option($this->saved_value); add_action( 'admin_notices', array($this, 'display_admin_notice'),20 ); add_action( "admin_post_pi_save_review_preference_{$this->slug}", array($this, 'savePreference'),20 ); } } function display_admin_notice() { $options = get_option($this->saved_value); $activation_time = $this->getInstallationDate(); $notice = '
'; $notice .= ''; $notice .= '
'; $notice .= 'pi web solution'; $notice .= '
'; /* translators: Plugin title */ $notice .= '

'.sprintf(__("Hi there, You've been using %s on your site for a few days
- I hope it's been helpful. If you're enjoying my plugin, would you mind rating it 5-stars to help spread the word?", 'advanced-wallet-for-woocommerce'), $this->title).'

'; $notice .= ''; $notice .= '
'; $notice .= '
'; $notice .= '
'; if(!$options && current_time('timestamp') >= strtotime($activation_time." +{$this->review_after} days")){ echo wp_kses($notice, $this->allowed_tags); } else if(is_array($options)) { if( array_key_exists('preference', $options) && array_key_exists('update_at', $options) && $options['preference'] =='later'){ if($this->validateDate($options['update_at']) && current_time('timestamp') >= strtotime($options['update_at']." +{$this->review_after} days")){ echo wp_kses($notice, $this->allowed_tags); } } } } function savePreference(){ $nonce = isset($_GET['_wpnonce']) ? $_GET['_wpnonce'] : '' ; $preference = isset($_GET['preference']) ? $_GET['preference'] : 'later'; if(!isset($_GET['_wpnonce']) || !wp_verify_nonce($nonce,"pi_save_review_preference_{$this->slug}")){ wp_die(esc_html('Link has expired'), '', array('response' => 403)); } $values['update_at'] = current_time('Y/m/d'); switch($preference){ case 'later': $values['preference'] = 'later'; $redirect = admin_url('index.php'); break; case 'now': $values['preference'] = 'now'; $redirect = $this->review_url; break; case 'never': $values['preference'] = 'never'; $redirect = admin_url('index.php'); break; } update_option($this->saved_value, $values); wp_redirect($redirect); } function getInstallationDate(){ $get_install_date = get_option($this->activation_date); if(empty($get_install_date) || !$this->validateDate($get_install_date)){ $now = current_time( "Y/m/d" ); add_option( $this->activation_date, $now ); return $now; } return $get_install_date; } function validateDate($date, $format = 'Y/m/d'){ if ( empty($date) ) return false; $d = \DateTime::createFromFormat($format, $date); // The Y ( 4 digits year ) returns TRUE for any integer with any number of digits so changing the comparison from == to === fixes the issue. return $d && $d->format($format) === $date; } }