Halloween Sale 15% off Ends in See the plans
PHP

Shared Notes Dashboard Widget

A notepad on the dashboard that every editor can read and update, for handover notes, to-dos or reminders.

Don’t have WPIDE yet? Install it on your site

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

  1. Install WPIDE on your WordPress site (it is free) and open Code Snippets.
  2. Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
  3. It is added inactive: review the code and settings, then switch it on.

Have a snippet worth sharing?

Publish it to the library from WPIDE or right here. Sign in with any WordPress site that runs WPIDE, free or Pro. Public snippets are reviewed by the WPIDE team before they appear.

Which site should get this snippet?

Enter the address of your WordPress site. WPIDE opens there in a new tab with the snippet ready to review and save.

Remembered in this browser only, so you are asked once.

Report this snippet

Tell the WPIDE team what is wrong: broken code, something harmful, spam or copied work.