Halloween Sale 15% off Ends in See the plans
PHP

Private Notes on the Plugins Screen

Adds a "Note" link under each plugin on the Plugins screen where administrators can record why it is installed, who requested it or what to check after updates.

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

Code

add_filter( 'plugin_row_meta', function ( $meta, $file ) {
    if ( ! current_user_can( 'activate_plugins' ) ) {
        return $meta;
    }
    $notes = (array) get_option( 'wpide_plugin_notes', array() );
    $note  = $notes[ $file ] ?? '';

    $meta[] = sprintf(
        '<span class="wpide-plugin-note" data-plugin="%s" data-note="%s">%s<a href="#" class="wpide-edit-note">%s</a></span>',
        esc_attr( $file ),
        esc_attr( $note ),
        $note ? '<em style="color:#3c434a">' . esc_html( $note ) . '</em> · ' : '',
        $note ? 'Edit note' : 'Add note'
    );
    return $meta;
}, 10, 2 );

add_action( 'wp_ajax_wpide_plugin_note', function () {
    check_ajax_referer( 'wpide_plugin_note', 'nonce' );
    if ( ! current_user_can( 'activate_plugins' ) ) {
        wp_send_json_error( null, 403 );
    }
    $plugin = isset( $_POST['plugin'] ) ? sanitize_text_field( wp_unslash( $_POST['plugin'] ) ) : '';
    $note   = isset( $_POST['note'] ) ? sanitize_text_field( wp_unslash( $_POST['note'] ) ) : '';
    $notes  = (array) get_option( 'wpide_plugin_notes', array() );

    if ( '' === $note ) {
        unset( $notes[ $plugin ] );
    } else {
        $notes[ $plugin ] = $note;
    }
    update_option( 'wpide_plugin_notes', $notes, false );
    wp_send_json_success();
} );

add_action( 'admin_footer-plugins.php', function () {
    ?>
    <script>
    document.addEventListener( 'click', function ( event ) {
        var link = event.target.closest( '.wpide-edit-note' );
        if ( ! link ) { return; }
        event.preventDefault();
        var wrap = link.closest( '.wpide-plugin-note' );
        var note = window.prompt( 'Note for this plugin (leave empty to remove):', wrap.dataset.note );
        if ( null === note ) { return; }
        var body = new FormData();
        body.append( 'action', 'wpide_plugin_note' );
        body.append( 'nonce', <?php echo wp_json_encode( wp_create_nonce( 'wpide_plugin_note' ) ); ?> );
        body.append( 'plugin', wrap.dataset.plugin );
        body.append( 'note', note );
        fetch( ajaxurl, { method: 'POST', credentials: 'same-origin', body: body } ).then( function () { window.location.reload(); } );
    } );
    </script>
    <?php
} );

Notes

Notes are saved in one option and only visible to users who can manage plugins.

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.