set_vars(); add_action($this->activation_hook, array($this, 'on_activate')); add_action($this->deactivation_hook, array($this, 'on_deactivate')); if ($this->check_condition()) /* checks the banner is active now */ { $this->banner_message = sprintf(__("Hi there! We at %sWebToffee%s would like to thank you for using our plugin. We would really appreciate if you could take a moment to drop a quick review that will inspire us to keep going.", 'wt-woocommerce-related-products'), '', ''); /* button texts */ $this->later_btn_text = __("Remind me later", 'wt-woocommerce-related-products'); $this->never_btn_text = __("Not interested", 'wt-woocommerce-related-products'); $this->review_btn_text = __("Review now", 'wt-woocommerce-related-products'); add_action('admin_notices', array($this, 'show_banner')); /* show banner */ add_action('admin_print_footer_scripts', array($this, 'add_banner_scripts')); /* add banner scripts */ add_action('wp_ajax_' . $this->ajax_action_name, array($this, 'process_user_action')); /* process banner user action */ } } /** * Set config vars */ public function set_vars() { $this->ajax_action_name = $this->plugin_prefix . '_process_user_review_action'; $this->banner_state_option_name = $this->plugin_prefix . "_review_request"; $this->start_date_option_name = $this->plugin_prefix . "_start_date"; $this->banner_css_class = $this->plugin_prefix . "_review_request"; $this->start_date = absint(get_option($this->start_date_option_name)); $banner_state = absint(get_option($this->banner_state_option_name)); $this->current_banner_state = ($banner_state == 0 ? $this->current_banner_state : $banner_state); } /** * Actions on plugin activation * Saves activation date */ public function on_activate() { $this->reset_start_date(); } /** * Actions on plugin deactivation * Removes activation date */ public function on_deactivate() { delete_option($this->start_date_option_name); } /** * Reset the start date. */ private function reset_start_date() { update_option($this->start_date_option_name, time()); } /** * Update the banner state */ private function update_banner_state($val) { update_option($this->banner_state_option_name, $val); } /** * Prints the banner */ public function show_banner() { $this->update_banner_state(1); /* update banner active state */ ?>
webtoffee_logo_url != "") { ?>

plugin_title, 'wt-woocommerce-related-products'); ?>

banner_message; ?>

later_btn_text ); ?> review_btn_text ); ?>

plugin_prefix); if (isset($_POST['wt_review_action_type'])) { $action_type = sanitize_text_field($_POST['wt_review_action_type']); /* current action is in allowed action list */ if (in_array($action_type, $this->allowed_action_type_arr)) { if ($action_type == 'never' || $action_type == 'closed') { $new_banner_state = 3; } elseif ($action_type == 'review') { $new_banner_state = 4; } else { /* reset start date to current date */ $this->reset_start_date(); $new_banner_state = 5; /* remind me later */ } $this->update_banner_state($new_banner_state); } } exit(); } /** * Add banner JS to admin footer */ public function add_banner_scripts() { $ajax_url = admin_url('admin-ajax.php'); $nonce = wp_create_nonce($this->plugin_prefix); ?> current_banner_state == 1) /* currently showing then return true */ { return true; } if ($this->current_banner_state == 2 || $this->current_banner_state == 5) /* only waiting/remind later state */ { if ($this->start_date == 0) /* unable to get activated date */ { /* set current date as activation date*/ $this->reset_start_date(); return false; } $days = ($this->current_banner_state == 2 ? $this->days_to_show_banner : $this->remind_days); $date_to_check = $this->start_date + (86400 * $days); if ($date_to_check <= time()) /* time reached to show the banner */ { return true; } else { return false; } } return false; } } new WT_CRP_Review_Request();