#14886 closed defect (bug) (fixed)
current_screen object lies because of unspecified post_type parameter
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 3.3 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Posts, Post Types | Keywords: | has-patch dev-feedback |
Focuses: | Cc: |
Description
When editing a page, you don't usually end up with post_type in the URL. That should be fine. But in admin.php, we assume that if no post type is specified, then typenow and current_screen ends up with incorrect information, and it's difficult to properly detect what's going on.
One fix would be to detect the post type based on the ID. Or, we can force a redirect and force all URLs to contain the proper post_type parameter except for post_type = post.
Attachments (4)
Change History (24)
#2
follow-up:
↓ 3
@
13 years ago
Extracting the post type from the ID seems like the right way to go.
#4
follow-up:
↓ 6
@
13 years ago
Another instance of the current_screen object being ill-informed.
The object on edit-tags.php provides no information about the parent screen. Specifically, the value of $typenow. But if $typenow isn't set it should default to 'post' on screens where that is indeed valid. For example, edit-tags.php?taxnomy=post_tag where post_type is omitted. This also makes it pretty much impossible to check $typenow unless of course you know the default. While the default isn't going to change, it also isn't intuitive.
I think we need to be more explicit in how this object's properties get set, and prevent the need for it to be manipulated later with more accurate information.
#6
in reply to:
↑ 4
@
13 years ago
Replying to nacin:
I think we need to be more explicit in how this object's properties get set, and prevent the need for it to be manipulated later with more accurate information.
A big +1.
The object on edit-tags.php provides no information about the parent screen. Specifically, the value of $typenow. But if $typenow isn't set it should default to 'post' on screens where that is indeed valid. For example, edit-tags.php?taxnomy=post_tag where post_type is omitted. This also makes it pretty much impossible to check $typenow unless of course you know the default. While the default isn't going to change, it also isn't intuitive.
I think pages like edit-tags.php should set $typenow to a known "not applicable" value. If we can trust null
to always be set when not applicable then maybe null
otherwise maybe something like n/a
. It's important to be able to know that there is no post so that code that requires a post should not run on those pages.
-Mike
#7
follow-up:
↓ 11
@
13 years ago
- Keywords needs-patch added
@mikeschinkel: any chance you could take a stab at writing the patch to fix this bug, since you're interested and no one else has yet? Freeze is coming up, would be good to get it fixed for 3.1.
#8
@
13 years ago
For reference, the top of post.php has a lot of code that corrects the current_screen object. We should either move that up and out, or well, I'm not really sure the best way to fix this. Someone will have to dig in.
#11
in reply to:
↑ 7
@
13 years ago
Replying to jane:
@mikeschinkel: any chance you could take a stab at writing the patch to fix this bug, since you're interested and no one else has yet? Freeze is coming up, would be good to get it fixed for 3.1.
Sorry I was unable to look at this in v3.1 timeframe. Clients were demanding all my waking time around the time you posted that. Still are.
#13
@
12 years ago
- Keywords has-patch dev-feedback added; needs-patch removed
I must admit I'm not very familiar with how $current_screen
works with other admin pages. But I'd like to get the ball rolling for this ticket.
I moved the correcting code in post.php
to set_current_screen()
, and set the default $typenow
for edit-tag
to post
. Am I going in the right direction? Is there anything in this patch that I can improve?
Hopefully this will set the motion for this issue to get fixed in 3.2 .
#18
@
12 years ago
18785.2.diff:ticket:18785 fixes this ticket, and then some.
Okay, this is then corrected in post.php. It won't work on the load-$pagenow hook, however.