Skip to content

Commit

Permalink
Merge pull request #16 from happyprime/fix/multisite-comments
Browse files Browse the repository at this point in the history
Only remove "Manage Comments" in multisite if network activated
  • Loading branch information
jeremyfelt authored Oct 26, 2023
2 parents fc877f8 + 64d08a1 commit 32418ac
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ function remove_admin_bar_comments_menu() {

/**
* Remove the "Manage Comments" node from each site's menu under My Sites.
*
* @since 1.3.0
*/
function remove_my_sites_comments_menu() {
global $wp_admin_bar;
Expand All @@ -187,20 +189,13 @@ function remove_my_sites_comments_menu() {
require_once ABSPATH . '/wp-admin/includes/plugin.php';
}

$network_active = is_plugin_active_for_network( plugin_basename( __FILE__ ) );
// We can't accurately remove the menu item if the plugin is not network activated.
if ( ! is_plugin_active_for_network( plugin_basename( __FILE__ ) ) ) {
return;
}

foreach ( $wp_admin_bar->user->blogs as $blog ) {
if ( ! $network_active ) {
switch_to_blog( $blog->userblog_id );
}

if ( $network_active || is_plugin_active( plugin_basename( __FILE__ ) ) ) {
$wp_admin_bar->remove_menu( 'blog-' . $blog->userblog_id . '-c' );
}

if ( ! $network_active ) {
restore_current_blog();
}
$wp_admin_bar->remove_menu( 'blog-' . $blog->userblog_id . '-c' );
}
}

Expand Down

0 comments on commit 32418ac

Please sign in to comment.