Files
rangerhq-logbook/inc/wp-notes-display.php
T
ranger 71df974a93 ux: make the "No notes found" empty-state notice dismissible
The inline notice on the My Notes page rendered with class="notice
notice-info" but no is-dismissible modifier, so WordPress's core
common.js never attached an X close button. Users had no way to
clear the empty-state message for the current view.

Audited every notice the plugin emits while I was in there — the
migration notice and the settings_errors() calls were already
correctly dismissible AND only fired in their intended state. The
empty-state notice was the only laggard. All four notice paths now
share the same contract: dismissible by the user, AND only rendered
when the underlying state warrants it.

Dismissal is per-page-load (WP core's default behavior — clicking X
hides the element for the current view only). Cross-page-load
persistence would need user_meta or a transient and isn't built
yet; flagged in the changelog for a future enhancement.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-25 07:51:39 +01:00

123 lines
6.2 KiB
PHP

<?php
// inc/wp-notes-display.php
if (!defined('ABSPATH')) {
exit;
}
/**
* Display notes list with consistent styling and functionality
*
* @param string $type Either 'active' or 'completed'
* @return void
*/
function wp_notes_display_notes($type = 'active') {
// Get notes and validate user permissions
if (!current_user_can('edit_posts')) {
return;
}
$notes = ($type === 'active') ? get_option('wp_notes', array()) : get_option('wp_done_notes', array());
$page_anchor = ($type === 'active') ? '#active-notes' : '#completed-notes';
$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>';
return;
}
// Section header with status count
$status_class = ($type === 'active') ? 'status-active' : 'status-completed';
echo '<div class="wp-notes-section">';
echo '<h2 class="wp-notes-section-title">';
echo '<span class="' . $status_class . '">' . esc_html($section_title) . '</span>';
echo '<span class="note-count">(' . count($notes) . ')</span>';
echo '</h2>';
echo '<div class="wp-notes-list" id="' . esc_attr($type . '-notes') . '">';
echo '<table class="wp-list-table widefat fixed striped has-hover">';
echo '<thead><tr>';
/* No checkbox column — bulk actions are not wired up. Re-add this <th>
and the matching <td> below when bulk select/delete/done is built. */
echo '<th scope="col" class="manage-column column-primary">' . esc_html__('Note', 'a-wp-notes') . '</th>';
echo '<th scope="col" class="manage-column">' . esc_html__('Author', 'a-wp-notes') . '</th>';
echo '<th scope="col" class="manage-column">' . esc_html__('Created', 'a-wp-notes') . '</th>';
if ($type === 'completed') {
echo '<th scope="col" class="manage-column">' . esc_html__('Completed By', 'a-wp-notes') . '</th>';
echo '<th scope="col" class="manage-column">' . esc_html__('Completed On', 'a-wp-notes') . '</th>';
}
echo '<th scope="col" class="manage-column">' . esc_html__('Actions', 'a-wp-notes') . '</th>';
echo '</tr></thead><tbody>';
foreach ($notes as $key => $note) {
$text = esc_html($note['text']);
$color = esc_attr($note['color'] ?? '#000000');
$size = esc_attr($note['size'] ?? '14');
$font = esc_attr($note['font'] ?? 'Arial');
$timestamp = esc_html($note['timestamp'] ?? current_time('mysql'));
$author = esc_html($note['author_name'] ?? 'Unknown');
echo '<tr>';
echo '<td style="color: ' . $color . '; font-size: ' . $size . 'px; font-family: ' . $font . ';">' . $text . '</td>';
echo '<td>' . $author . '</td>';
echo '<td>' . $timestamp . '</td>';
if ($type === 'completed') {
echo '<td>' . esc_html($note['completed_by'] ?? 'Unknown') . '</td>';
echo '<td>' . esc_html($note['completed_on'] ?? 'Unknown') . '</td>';
}
echo '<td class="actions">';
if ($type === 'active') {
echo '<button type="button" class="button edit-note" data-note-id="' . esc_attr($key) . '">' .
esc_html__('Edit', 'a-wp-notes') . '</button> ';
echo '<form method="post" style="display:inline;">';
echo '<input type="hidden" name="note_id" value="' . esc_attr($key) . '">';
echo '<button type="submit" name="mark_done" class="button">' .
esc_html__('Mark as Done', 'a-wp-notes') . '</button>';
echo '</form>';
} else {
echo '<form method="post" style="display:inline;">';
echo '<input type="hidden" name="note_id" value="' . esc_attr($key) . '">';
echo '<button type="submit" name="restore_note" class="button">' .
esc_html__('Restore', 'a-wp-notes') . '</button>';
echo '</form>';
}
echo '</td></tr>';
// Edit form (for active notes only)
if ($type === 'active') {
/* Active rows have 4 columns: Note, Author, Created, Actions
(no longer a checkbox column). Edit form spans all 4. */
echo '<tr id="edit-note-' . esc_attr($key) . '" style="display:none;"><td colspan="4">';
echo '<form class="edit-note-form" data-note-id="' . esc_attr($key) . '">';
wp_nonce_field('wp_notes_nonce', '_wpnonce');
echo '<input type="hidden" name="note_id" value="' . esc_attr($key) . '">';
echo '<textarea name="new_text" class="large-text">' . esc_textarea($text) . '</textarea><br>';
echo '<div class="formatting-options">';
echo '<input type="color" name="edit_color" value="' . esc_attr($color) . '">';
echo '<input type="number" name="edit_size" value="' . esc_attr($size) . '" min="8" max="72">';
echo '<select name="edit_font">';
echo '<option value="Arial" ' . selected('Arial', $font, false) . '>Arial</option>';
echo '<option value="Helvetica" ' . selected('Helvetica', $font, false) . '>Helvetica</option>';
echo '<option value="Times New Roman" ' . selected('Times New Roman', $font, false) . '>Times New Roman</option>';
echo '<option value="Verdana" ' . selected('Verdana', $font, false) . '>Verdana</option>';
echo '</select>';
echo '</div>';
echo '<button type="submit" class="button button-primary">' . esc_html__('Save', 'a-wp-notes') . '</button>';
echo '<button type="button" class="button cancel-edit">' . esc_html__('Cancel', 'a-wp-notes') . '</button>';
echo '</form>';
echo '</td></tr>';
}
}
echo '</tbody></table></div>';
}