Halloween Sale 15% off Ends in See the plans
PHP

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.

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

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

  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.