Shared Notes Dashboard Widget
A notepad on the dashboard that every editor can read and update, for handover notes, to-dos or reminders.
Opens WPIDE on
Code
// Who can edit the notes (everyone with dashboard access can read them).
$wpide_notes_capability = 'edit_others_posts';
add_action( 'wp_dashboard_setup', function () use ( $wpide_notes_capability ) {
if ( ! current_user_can( 'edit_posts' ) ) {
return;
}
wp_add_dashboard_widget( 'wpide_shared_notes', 'Team Notes', function () use ( $wpide_notes_capability ) {
$notes = (string) get_option( 'wpide_dashboard_notes', '' );
if ( ! current_user_can( $wpide_notes_capability ) ) {
echo $notes ? wp_kses_post( wpautop( $notes ) ) : '<p>No notes yet.</p>';
return;
}
?>
<form method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>">
<input type="hidden" name="action" value="wpide_save_dashboard_notes">
<?php wp_nonce_field( 'wpide_save_dashboard_notes' ); ?>
<textarea name="wpide_notes" rows="8" style="width:100%"><?php echo esc_textarea( $notes ); ?></textarea>
<p><button type="submit" class="button button-primary">Save notes</button></p>
</form>
<?php
} );
} );
add_action( 'admin_post_wpide_save_dashboard_notes', function () use ( $wpide_notes_capability ) {
if ( ! current_user_can( $wpide_notes_capability ) ) {
wp_die( 'You are not allowed to edit these notes.' );
}
check_admin_referer( 'wpide_save_dashboard_notes' );
$notes = isset( $_POST['wpide_notes'] ) ? wp_kses_post( wp_unslash( $_POST['wpide_notes'] ) ) : '';
update_option( 'wpide_dashboard_notes', $notes, false );
wp_safe_redirect( admin_url( 'index.php' ) );
exit;
} );
Notes
Notes are stored in the wpide_dashboard_notes option.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.