diff --git a/inc/class-wooviet-notices.php b/inc/class-wooviet-notices.php new file mode 100644 index 0000000..830d66e --- /dev/null +++ b/inc/class-wooviet-notices.php @@ -0,0 +1,107 @@ + 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 = 'tiếng Việt - English'; + $line5 = __( 'Dismiss this notice', 'woo-viet' ); + $link = admin_url( 'admin.php?page=woo-viet&wooviet_dismiss=displaying_survey_after_4_weeks' ); + + printf( ' +
+

%1$s

+

+ %2$s %3$s %4$s +

+

+ %5$s +

+
+ ', $line1, $line2, $line3, $line4, $line5, $link ); + } + +} \ No newline at end of file diff --git a/woo-viet.php b/woo-viet.php index 0c03111..820d66b 100644 --- a/woo-viet.php +++ b/woo-viet.php @@ -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();