Make WordPress Core

Opened 22 months ago

Closed 22 months ago

Last modified 22 months ago

#56296 closed defect (bug) (invalid)

is_network_admin() function does not work correctly on multisite

Reported by: stefanowp2021's profile stefanowp2021 Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Administration Keywords: reporter-feedback
Focuses: multisite Cc:

Description

I'm trying to execute this simple function on a wordpress 6.0 multisite:

function network_admin_check() {
    
    if ( is_network_admin() ) {
        echo __( 'You are viewing a WordPress network administration page', 'textdomain' );
    } else {
        echo __( 'You are not viewing a WordPress network administration page', 'textdomain' );
    }
      
}

add_action( 'admin_init', 'network_admin_check');

Reference: https://developer.wordpress.org/reference/functions/is_network_admin/

It partially works. I want to show a message when I'm in website.com/wp-admin/network/ but it only works on the else condition, example when I'm in a subsite backend like website.com/de/wp-admin it shows the message "You are not viewing a WordPress network administration page".

Change History (5)

#1 @SergeyBiryukov
22 months ago

  • Focuses multisite added

#2 follow-up: @johnbillion
22 months ago

  • Keywords reporter-feedback added

Thanks for the report @stefanowp2021 and welcome to WordPress Trac. I'm unable to reproduce this problem on a fresh installation of WordPress Multisite. The is_network_admin() function is working as expected in the network admin area.

Can you confirm whether the problem persists if you deactivate your plugins and switch to a default theme such as Twenty Twenty One? Don't forget to check for any plugins in wp-content/mu-plugins or a wp-content/sunrise.php file too.

#3 in reply to: ↑ 2 @stefanowp2021
22 months ago

Replying to johnbillion:

Thanks for the report @stefanowp2021 and welcome to WordPress Trac. I'm unable to reproduce this problem on a fresh installation of WordPress Multisite. The is_network_admin() function is working as expected in the network admin area.

Can you confirm whether the problem persists if you deactivate your plugins and switch to a default theme such as Twenty Twenty One? Don't forget to check for any plugins in wp-content/mu-plugins or a wp-content/sunrise.php file too.

Hi John,
I've tried on another wordpress installation and it works ok for me too.
I need to investigate further to fix the issue.
We can close this ticket considering is not a wordpress bug. Thank you.

Last edited 22 months ago by stefanowp2021 (previous) (diff)

#4 @stefanowp2021
22 months ago

  • Resolution set to invalid
  • Status changed from new to closed

#5 @johnbillion
22 months ago

  • Milestone Awaiting Review deleted

Thanks for letting us know 👍

Note: See TracTickets for help on using tickets.