Network-Wide Dashboard Announcement
Adds an "Announcement" box to Network Admin > Settings; whatever a super admin writes there appears as a dismissible notice on every site's dashboard.
Opens WPIDE on
Code
if ( ! is_multisite() ) {
return;
}
add_action( 'wpmu_options', function () {
?>
<h2><?php esc_html_e( 'Network announcement' ); ?></h2>
<table class="form-table" role="presentation">
<tr>
<th scope="row"><label for="wpide_network_announcement"><?php esc_html_e( 'Announcement' ); ?></label></th>
<td>
<textarea name="wpide_network_announcement" id="wpide_network_announcement" rows="3" class="large-text"><?php echo esc_textarea( get_site_option( 'wpide_network_announcement', '' ) ); ?></textarea>
<p class="description"><?php esc_html_e( 'Shown on the dashboard of every site to users who can edit posts.' ); ?></p>
</td>
</tr>
</table>
<?php
} );
// Network Settings already verifies its own nonce and capability before this runs.
add_action( 'update_wpmu_options', function () {
if ( isset( $_POST['wpide_network_announcement'] ) && current_user_can( 'manage_network_options' ) ) {
update_site_option( 'wpide_network_announcement', wp_kses_post( wp_unslash( $_POST['wpide_network_announcement'] ) ) );
}
} );
add_action( 'admin_notices', function () {
$message = get_site_option( 'wpide_network_announcement', '' );
$screen = get_current_screen();
if ( '' === trim( $message ) || ! current_user_can( 'edit_posts' ) || ! $screen || 'dashboard' !== $screen->id ) {
return;
}
echo '<div class="notice notice-info is-dismissible"><p>' . wp_kses_post( $message ) . '</p></div>';
} );
Notes
Basic HTML (links, bold) is allowed. Clear the field to remove the notice.
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.