This snippet enhances the WordPress Multisite network by introducing a dedicated notes column in the Sites table within the Network Admin dashboard. This feature allows network administrators to add, view, and edit custom notes for each site in the network, facilitating better communication and management. Notes are edited through a tab in the edit sites page.
__( 'Notes', 'textdomain' ),
'url' => 'admin.php?page=site-notes',
'cap' => 'manage_network_options',
);
return $links;
}
add_filter( 'network_edit_site_nav_links', 'site_notes_tab' );
/**
* Register hidden submenu page for Site Notes.
*/
function site_notes_page() {
add_submenu_page(
'', // Hidden from menus
__( 'Site Notes', 'textdomain' ),
__( 'Notes', 'textdomain' ),
'manage_network_options',
'site-notes',
'site_notes_page_callback'
);
}
add_action( 'network_admin_menu', 'site_notes_page' );
/**
* Render a page on the blog settings for updating Site Notes
*/
function site_notes_page_callback() {
$id = isset( $_GET['id'] ) ? absint( $_GET['id'] ) : 0;
$blog = $id ? get_site( $id ) : false;
if ( ! $id || ! $blog ) {
wp_die( esc_html__( 'Invalid site ID.', 'textdomain' ) );
}
?>
'site-notes',
'id' => $id,
'updated' => true,
),
network_admin_url( 'admin.php' )
)
);
exit;
}
add_action( 'network_admin_edit_notes_save', 'site_notes_save' );
/**
* Add Site Notes column to Network Sites list.
*
* @param array $sites_columns
*
* @return array $new_columns
*/
function notes_col( $sites_columns ) {
$new_columns = [];
foreach ( $sites_columns as $key => $label ) {
$new_columns[ $key ] = $label;
// Insert column after lastupdated
if ( 'lastupdated' === $key ) {
$new_columns['site_notes'] = __( 'Notes', 'textdomain' );
}
}
// If lastupdated wasn’t found, stick it at the end
if ( ! isset( $new_columns['site_notes'] ) ) {
$new_columns['site_notes'] = __( 'Notes', 'textdomain' );
}
return $new_columns;
}
add_filter( 'wpmu_blogs_columns', 'notes_col' );
/**
*Populate data to Notes column
*
* @param string $column_name
* @param int $blog_id
*/
function notes_col_data( $column_name, $blog_id ) {
if ( 'site_notes' === $column_name ) {
$notes = get_blog_option( $blog_id, 'site_notes' );
echo esc_html( $notes );
}
}
add_action( 'manage_sites_custom_column', 'notes_col_data', 10, 2 );
?>