#16490 closed enhancement (wontfix)
Rename is_x_admin() functions to in_x_admin()
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.1 |
Component: | Administration | Keywords: | has-patch |
Focuses: | Cc: |
Description
The functions is_admin()
, is_blog_admin()
, is_network_admin()
and is_user_admin()
all share the same problem -- they read like they are checking user capabilities.
This is made worse with genuine user capability checking functions like is_super_admin()
.
When writing code utilizing these functions it's simple to confuse other developers since they'd automatically assume that if ( is_user_admin() ) {}
is checking if a user is an admin.
Since all of these functions other than is_admin()
are new in 3.1, I'm hoping we can avoid compounding the problem in the next release and change them all to in_x_admin()
since this more accurately reflects what the functions are doing -- checking if the request is inside an admin page.
I've attached a patch with the changes needed. I've also deprecated the is_admin()
function and replaced it with in_admin()
.
Attachments (3)
Change History (25)
#2
@
14 years ago
True westi, but it'll be fraction of the number compared with when 3.1 goes stable. I'm sure they won't mind a quick search and replace? I wish I could have flagged this earlier though, I've only come across it now.
#3
@
14 years ago
The patch also adds is_admin() into deprecated.php, so it's no hassle to move the others, just not ideal since they wouldn't even have made a final version.
#5
@
14 years ago
I might get behind moving all of the is_*_admin() functions to deprecated.php without a warning. We can't disappear these functions post RC4.
#7
@
14 years ago
The deprecated versions might need to stay in load.php for load order reasons. That would be safest for 3.1, anyhow.
#9
@
14 years ago
The other option, too, is we had discussed is_admin( $where = true )
with the option to specify 'user' or 'network'. Not that we plan on adding more admins beyond these, just throwing it out there.
I agree with scribu, also. Is it confusing? Yeah. But it's been building up to this for a while, so let's just sit on it.
is_admin() is actually in_admin()
is_blog_admin() is actually in_blog_admin()
is_site_admin() is actually is_super_admin()
is_network_admin() is actually in_network_admin()
is_super_admin() is the new name for is_site_admin()
#11
@
14 years ago
- Keywords 3.2-early added
- Milestone changed from Awaiting Review to Future Release
#13
@
14 years ago
If we're deprecating the functions anyway this can definitely wait. Although on the flip side it will expose functions that are possibly already deprecated to a significantly greater number of developers.
I'm not sure about is_admin( $where )
though. It doesn't fix the problem for me: if ( is_admin( 'user' ) ) {}
is just as confusing.
#16
@
14 years ago
-100 for in_admin( $where )
.
- We don't envisage adding any more $wheres in the near term
- It makes the code harder to read, scan for relevant checks etc.
- It doesn't really make things less confusing than
in_admin()
/in_user_admin()
/in_network_admin()
#18
in reply to:
↑ 15
@
12 years ago
- Cc bpetty added
- Keywords close added; 3.2-early removed
Replying to apeatling:
+1 for
in_admin( $where )
.
If you prefer this style, you can actually now use $current_screen->in_admin($where)
as WP_Screen
was changed to do exactly this in 3.5 (see #21742).
As for the is_*_admin()
methods, this ticket was totally ignored for 2 years, and those have been in use for a long time now, so now I really think this patch is completely pointless now, and not worth doing.
Proposing to close this ticket.
#19
@
12 years ago
- Milestone Future Release deleted
- Resolution set to wontfix
- Status changed from new to closed
Yeah, this ship has saled.
I'm on the fence for this change.
It is probably too late to do this now we are RC without adding the backcompat for the new functions in deprecated.php
Otherwise we are going to break any new code people have written during the beta/RC period which uses these functions.
So all those people who have updated there Multisite plugins to work with the network admin will be sad