feat: persist empty-state notice dismissal via user_meta
The "No active/completed notes found" notice was already dismissible per-page-load (WP core's X button hides it), but pressing X only cleared it for the current view — it returned on the next refresh. The dismissal is now persisted to user_meta per-user-per-list-type, so once closed it stays closed across page loads until the flag is reset. MECHANICS - inc/wp-notes-display.php now checks get_user_meta(uid, 'wp_notes_dismissed_empty_<type>') before rendering and skips the notice render entirely when set. - New AJAX handler wp_ajax_wp_notes_dismiss_empty validates a nonce and the edit_posts capability, then writes the flag via update_user_meta(). type=active|completed; anything else 400s. - An inline jQuery handler in wp_notes_add_inline_scripts() listens for clicks on .wp-notes-empty .notice-dismiss (WP core's auto- injected X button) and fires the AJAX call. The visual hide is still WP core's job. - The notice element carries data-wp-notes-empty-type and a fresh per-render data-wp-notes-nonce for the round trip. RESET The flag is per-user-meta keyed wp_notes_dismissed_empty_active / wp_notes_dismissed_empty_completed. wp_delete_user removes them automatically. A UI button to reset dismissed notices is not built yet — flagged in the changelog as a future enhancement. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -22,14 +22,24 @@ function wp_notes_display_notes($type = 'active') {
|
||||
$section_title = ($type === 'active') ? 'Active Notes' : 'Completed Notes';
|
||||
|
||||
if (empty($notes)) {
|
||||
/* is-dismissible adds an X button via WP core's common.js so
|
||||
users can clear the empty-state message for the current view.
|
||||
Dismissal is per-page-load (the message reappears on next
|
||||
refresh if the list is still empty) — persistence across
|
||||
reloads would need user_meta tracking and isn't built yet. */
|
||||
echo '<div class="wp-notes-empty notice notice-info is-dismissible">';
|
||||
echo '<p>' . esc_html__('No ' . ($type === 'active' ? 'active' : 'completed') . ' notes found.', 'a-wp-notes') . '</p>';
|
||||
echo '</div>';
|
||||
/* Per-user persistent dismissal: if the current user has
|
||||
dismissed the empty-state notice for this list type before,
|
||||
we skip rendering it entirely. The flag stays set until they
|
||||
explicitly reset it (or until we extend this to auto-clear
|
||||
when a note is created — Option B for a future iteration).
|
||||
Flag key: wp_notes_dismissed_empty_active / _completed. */
|
||||
$dismiss_meta_key = 'wp_notes_dismissed_empty_' . $type;
|
||||
if (get_user_meta(get_current_user_id(), $dismiss_meta_key, true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$nonce = wp_create_nonce('wp_notes_dismiss_empty');
|
||||
printf(
|
||||
'<div class="wp-notes-empty notice notice-info is-dismissible" data-wp-notes-empty-type="%1$s" data-wp-notes-nonce="%2$s"><p>%3$s</p></div>',
|
||||
esc_attr($type),
|
||||
esc_attr($nonce),
|
||||
esc_html__('No ' . ($type === 'active' ? 'active' : 'completed') . ' notes found.', 'a-wp-notes')
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user