Private Notes on Each Network Site
Adds a "Notes" box to Network Admin > Sites > Edit Site where super admins can record the client, contract details or quirks of a site, and shows the note in the sites list.
Opens WPIDE on
Code
if ( ! is_multisite() ) {
return;
}
add_action( 'network_site_info_form', function ( $blog_id ) {
?>
<table class="form-table" role="presentation">
<tr>
<th scope="row"><label for="wpide_site_note"><?php esc_html_e( 'Notes' ); ?></label></th>
<td><textarea name="wpide_site_note" id="wpide_site_note" rows="4" class="large-text"><?php echo esc_textarea( (string) get_site_meta( $blog_id, 'wpide_site_note', true ) ); ?></textarea></td>
</tr>
</table>
<?php
} );
// Runs inside site-info.php after WordPress has checked the edit-site nonce and the manage_sites capability.
add_action( 'wp_update_site', function ( $new_site ) {
if ( ! isset( $_POST['wpide_site_note'] ) || ! current_user_can( 'manage_sites' ) || ! is_network_admin() ) {
return;
}
check_admin_referer( 'edit-site' );
update_site_meta( $new_site->blog_id, 'wpide_site_note', sanitize_textarea_field( wp_unslash( $_POST['wpide_site_note'] ) ) );
} );
add_filter( 'wpmu_blogs_columns', function ( $columns ) {
$columns['wpide_site_note'] = __( 'Notes' );
return $columns;
} );
add_action( 'manage_sites_custom_column', function ( $column, $blog_id ) {
if ( 'wpide_site_note' === $column ) {
$note = (string) get_site_meta( $blog_id, 'wpide_site_note', true );
echo $note ? '<span title="' . esc_attr( $note ) . '">' . esc_html( wp_trim_words( $note, 12 ) ) . '</span>' : '—';
}
}, 10, 2 );
Notes
Notes are stored in site meta and only visible in Network Admin.
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.