Make WordPress Core

Opened 11 years ago

Closed 10 years ago

Last modified 10 years ago

#25398 closed defect (bug) (fixed)

Multiple WordPress URL Parameters Causes Undefined ID and Nicename Errors

Reported by: chriscct7's profile chriscct7 Owned by: wonderboymusic's profile wonderboymusic
Milestone: 4.0 Priority: normal
Severity: normal Version: 3.6.1
Component: Query Keywords: has-patch
Focuses: Cc:

Description

So I was able to find an unexpected behavior in WordPress that looks like it was patched in #17662 11 months ago, since a closely related ticket, #20519, was closed and merged into that one.

Basically, to reproduce this you need a custom post type that supports authors.

So, let's say I have a cpt called 'download'. Let's say a known author ID is 1. It doesn't really matter what the author id is. Now, try going to:

mysite.com/?post_type=download&author=1

So what you'd expect to see, is the downloads archive template, with the posts written by author 1.

Instead what you get is undefined errors specifically undefined id and undefined nicename.

Not really sure where the bug comes from (my guess is maybe the templates for author and post type archives) so I've logged it under General.

Attachments (1)

25398.patch (429 bytes) - added by mordauk 11 years ago.
Add ! is_post_type_archive() to is_author() check

Download all attachments as: .zip

Change History (20)

#1 @helen
11 years ago

  • Keywords reporter-feedback added

What theme/template code?

#2 @chriscct7
11 years ago

I'm not sure specifically which ones, but what I presume is happening is:
is_admin() returns true for this query, and is_archive() also returns true, so WordPress is either loading the author template, the archives template or possibly both. Let me see if I can track down something for you

#3 @chriscct7
11 years ago

Notice: Undefined property: stdClass::$user_nicename in C:\wamp\www\edd\wp-includes\template.php on line 88
Call Stack
#	Time	Memory	Function	Location
1	0.0002	675064	{main}( )	..\index.php:0
2	0.0003	679880	require( 'C:\wamp\www\edd\wp-blog-header.php' )	..\index.php:17
3	0.2930	36454520	require_once( 'C:\wamp\www\edd\wp-includes\template-loader.php' )	..\wp-blog-header.php:16
4	0.2942	36455504	get_author_template( )	..\template-loader.php:38

Notice: Undefined property: stdClass::$ID in C:\wamp\www\edd\wp-includes\template.php on line 89
Call Stack
#	Time	Memory	Function	Location
1	0.0002	675064	{main}( )	..\index.php:0
2	0.0003	679880	require( 'C:\wamp\www\edd\wp-blog-header.php' )	..\index.php:17
3	0.2930	36454520	require_once( 'C:\wamp\www\edd\wp-includes\template-loader.php' )	..\wp-blog-header.php:16
4	0.2942	36455504	get_author_template( )	..\template-loader.php:38

Looks like the author template

Last edited 11 years ago by chriscct7 (previous) (diff)

#4 @chriscct7
11 years ago

  • Keywords reporter-feedback removed

#5 @chriscct7
11 years ago

So there's 2 ways this could affect a site.
The first way is you get the xdebug notices.

The second way, is if you've elected to hide those errors, you get back a totally blank page, like on photomatt's site, where:
http://ma.tt/?post_type=post&author=1
becomes
http://ma.tt/author/saxmatt/?post_type=post

which is a blank page

Version 0, edited 11 years ago by chriscct7 (next)

#6 @chriscct7
11 years ago

  • Keywords dev-feedback added

#7 @nacin
11 years ago

  • Component changed from General to Query

#8 @mordauk
11 years ago

get_queried_object() is returning the post type object but since the author query arg is set, is_author() returns true, which causes the undefined index error when the title is set to the author's name with $title = $author->display_name;.

This can be fixed by adding && ! is_post_type_archive() to the is_author() check.

I'm not sure if there are any repercussions of this though.

@mordauk
11 years ago

Add ! is_post_type_archive() to is_author() check

#9 @mordauk
11 years ago

  • Keywords has-patch added; needs-patch removed

#10 @wonderboymusic
11 years ago

  • Keywords close added; dev-feedback removed
  • Milestone changed from Awaiting Review to 3.9

Unless I'm missing something, this appears to be fixed....

Canonical redirection is kicking in:
http://wordpress-core-develop/?post_type=_type&post_author=1 redirects to
http://wordpress-core-develop/author/admin/?post_type=_type

+ no errors when when pretty permalinks are off

#11 @wonderboymusic
11 years ago

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

Someone reopen if I'm wrong about this working just fine now.

#12 @mordauk
11 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

Still throws notices for me:

http://trunk:8888/?post_type=download&author=1 redirects to http://trunk:8888/author/pippin/?post_type=download and shows the query results correctly, but there are still undefined notices in the header:

http://d.pr/i/DJcb

#13 @mordauk
11 years ago

  • Keywords 2nd-opinion added; close removed

This ticket was mentioned in IRC in #wordpress-dev by wonderboymusic. View the logs.


11 years ago

#15 follow-up: @wonderboymusic
11 years ago

  • Milestone changed from 3.9 to Future Release

I still can't reproduce this - @mordauk, what theme are you using?

#16 in reply to: ↑ 15 @mordauk
11 years ago

Replying to wonderboymusic:

I still can't reproduce this - @mordauk, what theme are you using?

I tested on multiple default themes, including Twenty Twelve and Twenty Thirteen.

#17 @wonderboymusic
10 years ago

  • Keywords 2nd-opinion removed
  • Milestone changed from Future Release to 4.0

Ah, I couldn't reproduce it because I was using post_author in the URL, not author. This is a valid concern. Post Type always beats Author when queried object is being determined. As such, we should avoid this notice by not trying to set author name as the title when we are in fact on a post type archive screen. The fact that author is in the path is meaningless as to precedence.

#18 @wonderboymusic
10 years ago

  • Owner set to wonderboymusic
  • Resolution set to fixed
  • Status changed from reopened to closed

In 28251:

Set the proper value for wp_title() when is_author() and is_post_type_archive() are both true. post_type should always win due to the precedence indicated in get_queried_object().

Props mordauk.
Fixes #25398.

#19 @mordauk
10 years ago

Excellent, thanks so much @wonderboymusic!

Note: See TracTickets for help on using tickets.