Make WordPress Core

Opened 9 years ago

Last modified 5 years ago

#30184 new defect (bug)

Author page and category

Reported by: dimitrovadrian's profile dimitrov.adrian Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.1
Component: Query Keywords: has-patch needs-unit-tests needs-testing
Focuses: Cc:

Description

Got errors like next in debug.log

PHP Notice: Undefined property: stdClass::$ID in /www/test1/wp-includes/query.php on line 4074
PHP Notice: Undefined property: stdClass::$nickname in /www/test1/wp-includes/query.php on line 4076
PHP Notice: Undefined property: stdClass::$user_nicename in /www/test1/wp-includes/query.php on line 4078

In wp-includes/query.php we have the method

public function is_author( $author = '' ) {
        if ( !$this->is_author )
            return false;

        if ( empty($author) )
            return true;

        $author_obj = $this->get_queried_object();

        $author = (array) $author;

        if ( in_array( $author_obj->ID, $author ) )
            return true;
        elseif ( in_array( $author_obj->nickname, $author ) )
            return true;
        elseif ( in_array( $author_obj->user_nicename, $author ) )
            return true;

        return false;
    }

But if we query a author page with category param queried_object actually will be the category term object, so next patch prevent such problems

public function is_author( $author = '' ) {
        if ( !$this->is_author )
            return false;

        if ( empty($author) )
            return true;

        $author_obj = $this->get_queried_object();
        
        if ( ! is_a( $author_obj, 'WP_User' ) )
            return false;

        $author = (array) $author;

        if ( in_array( $author_obj->ID, $author ) )
            return true;
        elseif ( in_array( $author_obj->nickname, $author ) )
            return true;
        elseif ( in_array( $author_obj->user_nicename, $author ) )
            return true;

        return false;
    }


Attachments (1)

30184.diff (1020 bytes) - added by MikeHansenMe 9 years ago.

Download all attachments as: .zip

Change History (7)

@MikeHansenMe
9 years ago

#1 @MikeHansenMe
9 years ago

  • Keywords has-patch added

#2 follow-up: @boonebgorges
9 years ago

  • Keywords reporter-feedback added

But if we query a author page with category param

How do you do this? example.com/author/boone?cat=foo?

#4 in reply to: ↑ 2 @dimitrov.adrian
9 years ago

Replying to boonebgorges:

But if we query a author page with category param

How do you do this? example.com/author/boone?cat=foo?

yes

#5 @johnbillion
9 years ago

  • Component changed from General to Query
  • Keywords needs-unit-tests added; reporter-feedback removed
  • Milestone changed from Awaiting Review to Future Release
  • Version changed from trunk to 3.1

Let's get a unit test in here please.

#6 @johnbillion
9 years ago

  • Keywords needs-testing added

Also I'm not sure the current patch is correct.

is_author() on example.com/author/boone?cat=foo should return true. The problem is that the queried object for a query such as this could be either a user or a term. Which should it be?

Note: See TracTickets for help on using tickets.