mirror of
https://github.com/10h30/woo-viet.git
synced 2026-06-05 15:09:49 +09:00
Add the questionnaire after 4 weeks - the coding part - #29
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage the notices of the plugin
|
||||
*
|
||||
* @author htdat
|
||||
* @since 1.3.1
|
||||
*
|
||||
*/
|
||||
class WooViet_Notices {
|
||||
|
||||
var $settings = '';
|
||||
|
||||
var $default_settings = array(
|
||||
'installation_time' => 0,
|
||||
'displaying_survey_after_4_weeks' => 'not_yet',
|
||||
);
|
||||
|
||||
/**
|
||||
* WooViet_Notices constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->settings = self::get_settings();
|
||||
$this->set_installation_time();
|
||||
$this->manage_displaying_survey_after_4_weeks();
|
||||
|
||||
}
|
||||
|
||||
public function get_settings() {
|
||||
$settings = get_option( 'woo-viet_notices', self::$default_settings );
|
||||
$settings = wp_parse_args( $settings, self::$default_settings );
|
||||
|
||||
return $settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the installation time
|
||||
*/
|
||||
public function set_installation_time() {
|
||||
if ( ! $this->settings['installation_time'] ) {
|
||||
$this->settings['installation_time'] = time();
|
||||
$this->save_settings();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save settings for this classe
|
||||
*/
|
||||
public function save_settings() {
|
||||
update_option( 'woo-viet_notices', $this->settings );
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage the notice 'displaying_survey_after_4_weeks'
|
||||
*/
|
||||
public function manage_displaying_survey_after_4_weeks() {
|
||||
$display_time = $this->settings['installation_time'] + ( 4 * 7 * 24 * 60 * 60 ); // 4 weeks; 7 days; 24 hours; 60 mins; 60 secs
|
||||
|
||||
// Manage the dismiss action
|
||||
if ( isset( $_GET['wooviet_dismiss'] )
|
||||
&&
|
||||
( 'displaying_survey_after_4_weeks' == $_GET['wooviet_dismiss'] )
|
||||
) {
|
||||
$this->settings['displaying_survey_after_4_weeks'] = 'done';
|
||||
$this->save_settings();
|
||||
}
|
||||
|
||||
// Display the message
|
||||
if ( $display_time < time() &&
|
||||
'not_yet' == $this->settings['displaying_survey_after_4_weeks']
|
||||
) {
|
||||
|
||||
add_action( 'admin_notices', array( $this, 'add_displaying_survey_after_4_weeks' ) );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The HTML code to display in the admin notice
|
||||
*/
|
||||
public function add_displaying_survey_after_4_weeks() {
|
||||
|
||||
$line1 = __( 'Please help us to improve Woo Viet.', 'woo-viet' );
|
||||
$line2 = __( 'Rate us!', 'woo-viet' );
|
||||
$line3 = __( 'Or run a short survery:', 'woo-viet' );
|
||||
$line4 = '<a href="http://vn.com" target="_blank">tiếng Việt</a> - <a href="http://en.com" target="_blank">English</a>';
|
||||
$line5 = __( 'Dismiss this notice', 'woo-viet' );
|
||||
$link = admin_url( 'admin.php?page=woo-viet&wooviet_dismiss=displaying_survey_after_4_weeks' );
|
||||
|
||||
printf( '
|
||||
<div class="notice notice-success">
|
||||
<p><strong>%1$s</strong></p>
|
||||
<p><strong>
|
||||
<a href="https://wordpress.org/support/plugin/woo-viet/reviews/?filter=5#new-post" target="_blank">%2$s</a> %3$s %4$s
|
||||
</strong></p>
|
||||
<p>
|
||||
<a href="%6$s">%5$s</a>
|
||||
</p>
|
||||
</div>
|
||||
', $line1, $line2, $line3, $line4, $line5, $link );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -133,6 +133,10 @@ class WooViet {
|
||||
include( WOO_VIET_DIR . 'inc/class-wooviet-admin-page.php' );
|
||||
$this->Admin_Page = new WooViet_Admin_Page();
|
||||
|
||||
// Add the notices class
|
||||
include( WOO_VIET_DIR . 'inc/class-wooviet-notices.php' );
|
||||
new WooViet_Notices();
|
||||
|
||||
}
|
||||
|
||||
$settings = self::get_settings();
|
||||
|
||||
Reference in New Issue
Block a user