weDevsOfficial/wp-user-frontend

Attempt to read property "roles.... warning

kabirbd89 opened this issue · 2 comments

I am getting the following error for some of my post (single.post). I don't know from when its started but page are indexing.

Warning: Attempt to read property "roles" on bool in /************/wp-content/plugins/wp-user-frontend/wpuf-functions.php on line 4561

In page element the error is in

<div class="entry-the-content"> <br> <b>Warning</b>: Attempt to read property "roles" on bool in <b>/************/wp-content/plugins/wp-user-frontend/wpuf-functions.php</b> on line <b>4561</b><br>

Few of my post are showing this error.

Need a solution before indexing all the post with this error.

Please make a backup before making below changes. You need to very careful before changing any code, cause it might break your site. Please contact support if you are not comfortable about changing the code.

Replace line no 4554 to 4562 of this file: wp-content/plugins/wp-user-frontend/wpuf-functions.php with below code:

function wpuf_get_single_user_roles( $user_id ) {
    if ( ! is_numeric( $user_id ) ) {
        return false;
    }

    $user = get_user_by( 'id', $user_id );

    if ( ! $user ) {
        return false;
    }

    return ( array ) $user->roles;
}

@sapayth Thank you for your fast response. Its seems problem solved for now.