notice_display_decision !== null) { return $this->notice_display_decision; } $user_id = get_current_user_id(); $dismissed_time = get_user_meta($user_id, self::NOTICE_USER_META_KEY, true); if (empty($dismissed_time) || !is_numeric($dismissed_time)) { $this->notice_display_decision = true; return $this->notice_display_decision; } // Use WP's current_time for consistency with stored timestamp $days_passed = (current_time('timestamp') - $dismissed_time) / DAY_IN_SECONDS; $this->notice_display_decision = ($days_passed >= self::NOTICE_REAPPEAR_DAYS); return $this->notice_display_decision; } /** * Render Theme Notification (if allowed and needed) * * @return void */ public function render_theme_notification() { if (!current_user_can('edit_theme_options')) { return; } if ($this->should_display_notice()) { $template = get_theme_file_path('admin/theme-notice-template.php'); if (file_exists($template)) { require $template; } } } /** * Enqueue Notice Script * * @return void */ public function enqueue_notice_script() { if (!current_user_can('edit_theme_options') || !$this->should_display_notice()) { return; } wp_enqueue_script( 'book-store-lite-admin-notice', get_theme_file_uri('admin/admin-notice.js'), array('jquery'), $this->get_theme_version(), true ); wp_localize_script( 'book-store-lite-admin-notice', 'book_store_lite_notice', array( 'nonce' => wp_create_nonce('book_store_lite_notification_nonce'), 'action' => 'book_store_lite_notification_dismissal', 'ajax_url' => admin_url('admin-ajax.php'), 'notice_class' => self::NOTICE_CSS_CLASS, ) ); } /** * Get Theme Version * * @return string */ private function get_theme_version() { $theme = wp_get_theme(); return $theme->get('Version'); } /** * Theme Notification Ajax Callback * * @return void */ public function theme_notification_ajax_callback() { check_ajax_referer('book_store_lite_notification_nonce', 'nonce'); if (!current_user_can('edit_theme_options')) { wp_send_json_error( array('message' => esc_html__('Unauthorized access.', 'book-store-lite')), 403 ); } $user_id = get_current_user_id(); // Store using current_time('timestamp') for consistency with should_display_notice() update_user_meta($user_id, self::NOTICE_USER_META_KEY, current_time('timestamp')); wp_send_json_success( array('message' => esc_html__('Notice dismissed successfully.', 'book-store-lite')) ); } } // Instantiate singleton Book_Store_Lite_Theme_Info::get_instance(); }