1

I can see that the 2 functions are almost identical. Only difference is in one line:

@is_admin() return $GLOBALS['current_screen']->in_admin();

@is_blog_admin() return $GLOBALS['current_screen']->in_admin( 'site' );

What is the practical purpose / reason behind this? Or where can i read more about it?

I can see that is_blog_admin() 'born' much later, and since it's giving the 'site' parameter to the in_admin() function that it calls internally, it works as a stricter condition, thus being more specific and probably not good idea to use it as an 'alias' to 'is_admin()' (since it's not). I just would like to see where this is used in practice?

4
  • Ok, now I also need to know... ...good find Viktor... ...the Codex shows literally no difference. Neither is listed as deprecated or perhaps set to be deprecated... it looks like is_blog_admin() was introduced in 3.1.0 where a bunch of network related functions were also introduced, so perhaps it relates to multi-site somehow. (That's just a guess.) Commented Feb 24, 2022 at 14:26
  • 1
    Yes, i added some more text to the question, please read it too. I'm sure we will find it out shortly. The extra param in in_admin() function is the key here. Would be happy to hear the devs who released it. (trac?, github logs?) Commented Feb 24, 2022 at 14:32
  • 1
    Are you familiar with WordPress Multisite? Just from the names I'd guess that is_blog_admin() is a bit stricter, checking if the user is an admin for the given site of the network.
    – kero
    Commented Feb 24, 2022 at 14:41
  • 1
    What i found is the Screen class class-wp-screen.php, has some already deprecated variables like $is_network, $is_user, which now can be checked only direclty via the in_admin() function. I guess then is_blog_admin is a convenience wrapper. Plugins and some themes use it mostly (correct me if i'm wrong) to target the normal (blog level) admin screen and close out the user and network (superadmin) screens. (if i get this right:) Commented Feb 24, 2022 at 18:41

1 Answer 1

3

On a multisite network is_admin() is true for everything under /wp-admin, including the multisite network admin at /wp-admin/network, but is_blog_admin() is only true for the admin for an individual site/blog on the network, and is not true for /wp-admin/network.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.