Make WordPress Core

Opened 13 years ago

Closed 12 years ago

Last modified 12 years ago

#14886 closed defect (bug) (fixed)

current_screen object lies because of unspecified post_type parameter

Reported by: nacin's profile nacin Owned by: nacin's profile nacin
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)

garyc40.14886.diff (2.9 KB) - added by garyc40 12 years ago.
1st attempt
garyc40.14886.2.diff (2.9 KB) - added by garyc40 12 years ago.
change the logic a bit to be more consistent with previous behavior
ticket.14886.diff (3.2 KB) - added by ptahdunbar 12 years ago.
screen.diff (23.9 KB) - added by nacin 12 years ago.

Download all attachments as: .zip

Change History (24)

#1 @nacin
13 years ago

  • Milestone changed from 3.0.2 to 3.1

Okay, this is then corrected in post.php. It won't work on the load-$pagenow hook, however.

#2 follow-up: @scribu
13 years ago

Extracting the post type from the ID seems like the right way to go.

#3 in reply to: ↑ 2 @mikeschinkel
13 years ago

  • Cc mikeschinkel@… added

Replying to scribu:

Extracting the post type from the ID seems like the right way to go.

Agreed.

#4 follow-up: @nacin
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.

#5 @nacin
13 years ago

(In [15664]) Apply [15661] to the edit-tags.php screens. fixes #14959. see #14886 for current_screen.

#6 in reply to: ↑ 4 @mikeschinkel
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: @jane
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 @nacin
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.

#9 @nacin
13 years ago

(In [16249]) Use the name of the corresponding post type in the edit-tags column. TODO, typenow should be accessible from the current_screen object on edit-tags. see #14886 for current_screen, [15664] for previous TODO note.

#10 @nacin
13 years ago

(In [16249]) Use the name of the corresponding post type in the edit-tags column. TODO, typenow should be accessible from the current_screen object on edit-tags. see #14886 for current_screen, [15664] for previous TODO note.

#11 in reply to: ↑ 7 @mikeschinkel
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.

#12 @ryan
12 years ago

  • Keywords 3.2-early added
  • Milestone changed from 3.1 to Future Release

@garyc40
12 years ago

1st attempt

#13 @garyc40
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 .

@garyc40
12 years ago

change the logic a bit to be more consistent with previous behavior

#14 @ptahdunbar
12 years ago

  • Cc trac@… added

I refreshed garyc40's patch and fixed the bug :)

#15 @nacin
12 years ago

In [19043]:

Fix [16249]. $typenow is considered empty on edit-tags screens, rather than displaying the parent post type. Switch to the $post_type global for now, which is set in the terms list table constructor. see #14886.

#16 @nacin
12 years ago

In [19047]:

Use get_current_screen() rather than a $current_screen global reference. Remove unused global reference. see #14886.

@nacin
12 years ago

#17 @ryan
12 years ago

screen.diff is nice.

#18 @nacin
12 years ago

18785.2.diff:ticket:18785 fixes this ticket, and then some.

#19 @nacin
12 years ago

  • Owner set to nacin
  • Resolution set to fixed
  • Status changed from new to closed

In [19052]:

Move WP_Screen to a full registry. Have convert_to_screen() return a WP_Screen object. Improve and verify values for post_type and taxonomy. see #18785. also fixes #14886.

#20 @nacin
12 years ago

  • Keywords 3.2-early removed
  • Milestone changed from Future Release to 3.3
Note: See TracTickets for help on using tickets.