WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 3 years ago

#18458 closed defect (bug) (fixed)

calling is_user_logged_in() when logged-out throws PHP notice

Reported by: wonderboymusic Owned by: dd32
Milestone: 3.3 Priority: normal
Severity: normal Version:
Component: Warnings/Notices Keywords: has-patch
Focuses: Cc:

Description

calling wp_get_current_user() when no user is logged in does not produce a User object, yet is_user_logged_in() tries to read the the id property of $user on every call to this function, whether an object exists or not.

This produces the following notice in the logs when error_reporting is set to -1

PHP Notice: Trying to get property of non-object in /Users/scott/Sites/emusic/trunk/wordpress/wp-includes/pluggable.php on line 758

The function is triggered by all calls to $WP_Query->get_posts() and will produce an obscene number of notices in error logs on high traffic sites. As an example, every XML-RPC made on eMusic.com produces this Notice in our logs.

Attachments (1)

patches-if-statement.diff (385 bytes) - added by wonderboymusic 3 years ago.
Patch for this ticket

Download all attachments as: .zip

Change History (3)

wonderboymusic3 years ago

Patch for this ticket

comment:1 dd323 years ago

  • Milestone changed from Awaiting Review to 3.3
  • Owner set to dd32
  • Status changed from new to accepted

On non-XML-RPC pageloads, That shouldn't produce a notice, as $current_user should be an object similar to this:

object(WP_User)[723]
  public 'data' => null
  public 'ID' => int 0
  public 'caps' => 
    array
      empty
  public 'cap_key' => null
  public 'roles' => 
    array
      empty
  public 'allcaps' => 
    array
      empty
  public 'filter' => null

However, XML-RPC does have that issue.

comment:2 dd323 years ago

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

In [18558]:

Harden up is_user_logged_in() against empty $current_user instances to prevent PHP Notices on XML-RPC requests. Fixes #18458

Note: See TracTickets for help on using tickets.