humanmade / humanmade/authorship

Undefined property: stdClass::$role warning before headers are sent causes issue when saving my profile.

Open
#174 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
PHP
Stars
68
Forks
11
PR merge metrics
No merged PRs in 30d

Description

If `error_reporting` includes Warnings, then when I save my profile ( from wp-admin/profile.php ), there is a Warning emitted before headers are sent, causing the page to whitescreen ( except for the error ) when it tries to send headers.

The warning is:

```
Warning: Undefined property: stdClass::$role in /var/www/html/wp-content/plugins/authorship/inc/admin.php on line 42 Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-content/plugins/authorship/inc/admin.php:42) in /var/www/html/wp/wp-includes/pluggable.php on line 1531 Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-content/plugins/authorship/inc/admin.php:42) in /var/www/html/wp/wp-includes/pluggable.php on line 1534
```

Fix, I think, is to change this:

```php
if ( $user->role !== GUEST_ROLE ) {
return;
}
```

... to this:

```php
if ( ! isset( $user->role ) || ( $user->role !== GUEST_ROLE ) ) {
return;
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.