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.
Opens WPIDE on
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
- 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.