close
Skip to content

Check if $authordata is not false before trying to read property#3141

Open
remyperona wants to merge 2 commits intoWordPress:trunkfrom
wp-media:56229
Open

Check if $authordata is not false before trying to read property#3141
remyperona wants to merge 2 commits intoWordPress:trunkfrom
wp-media:56229

Conversation

@remyperona
Copy link

Prevent PHP warning when reading user_nicename property from $authordata variable

Trac ticket: https://core.trac.wordpress.org/ticket/56229


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

$authordata = get_userdata( $post->post_author );
$author = $authordata->user_nicename;

if ( false !== $authordata ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if ( false !== $authordata ) {
if ( $authordata instanceof WP_User ) {

Always better to verify that the type if the type want, rather than comparing against one of the many types you don't want.

Would also be good to see a test covering this change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants