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/#wp-bbp_topic_content-wrap"; $this->review_after = 6; $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_filter('allowed_redirect_hosts', function($hosts){ $hosts[] = 'wordpress.org'; return $hosts; }); 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: %s: the plugin title shown to users. */ $notice .= '

' . sprintf( __( 'Is this plugin helping you control your shipping costs?', 'advanced-free-flat-shipping-woocommerce' ), esc_html( $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']) ? sanitize_text_field(wp_unslash($_GET['_wpnonce'])) : '' ; $preference = isset($_GET['preference']) ? sanitize_text_field(wp_unslash($_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_safe_redirect($redirect); exit; } 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; } } new pisol_affsw_advance_shipping_review('Advance conditional shipping method plugin', 'advanced-free-flat-shipping-woocommerce'); }