Discussion:
Detect Network Admin in admin_init?
Jeff Rose
2013-11-22 22:43:03 UTC
Permalink
I have a plugin that's doing register_settings on the admin_init hook and
that is apparently running database queries (to populate some options) even
on the Network Admin page where it's not necessary.

Is there any way to detect that we're on a Network page (Network Admin
dashboard etc) during this hook? The $current_screen global doesn't seem to
be set yet and URL hacking seems... hacky.

Any advice is appreciated as always.
--
Jeff Rose
------------------
http://www.jeffrose.ca/twitter
http://www.jeffrose.ca/facebook
Shea Bunge
2013-11-22 22:46:43 UTC
Permalink
Have a look at the is_network_admin() function (
http://queryposts.com/function/is_network_admin/). If the current screen
global is not yet set, it checks the WP_NETWORK_ADMIN constant.
Post by Jeff Rose
I have a plugin that's doing register_settings on the admin_init hook and
that is apparently running database queries (to populate some options) even
on the Network Admin page where it's not necessary.
Is there any way to detect that we're on a Network page (Network Admin
dashboard etc) during this hook? The $current_screen global doesn't seem to
be set yet and URL hacking seems... hacky.
Any advice is appreciated as always.
--
Jeff Rose
------------------
http://www.jeffrose.ca/twitter
http://www.jeffrose.ca/facebook
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
--
Regards,

Shea Bunge
http://bungeshea.com
Jeff Rose
2013-11-23 19:05:39 UTC
Permalink
Thanks Shea, that's the function I was looking for but somehow it wasn't
coming up for me. Works perfectly!
Message: 2
Date: Sat, 23 Nov 2013 09:46:43 +1100
Subject: Re: [wp-hackers] Detect Network Admin in admin_init?
<
Content-Type: text/plain; charset=ISO-8859-1
Have a look at the is_network_admin() function (
http://queryposts.com/function/is_network_admin/). If the current screen
global is not yet set, it checks the WP_NETWORK_ADMIN constant.
Frank Bueltge
2013-11-23 19:45:03 UTC
Permalink
small hint.
Use the plugin Debug Objects (http://wordpress.org/plugins/debug-objects/)
to understand and see the right conditionals, see the example screen
http://awesomescreenshot.com/0b9200gt62

Best wishes
Post by Jeff Rose
Thanks Shea, that's the function I was looking for but somehow it wasn't
coming up for me. Works perfectly!
Message: 2
Date: Sat, 23 Nov 2013 09:46:43 +1100
Subject: Re: [wp-hackers] Detect Network Admin in admin_init?
<
Content-Type: text/plain; charset=ISO-8859-1
Have a look at the is_network_admin() function (
http://queryposts.com/function/is_network_admin/). If the current screen
global is not yet set, it checks the WP_NETWORK_ADMIN constant.
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
Loading...