Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
07/15/2021 09:58:42 AM (3 years ago)
Author:
imath
Message:

Avoid a PHP8 warning when xProfile user visibility levels are empty

When the record does not exist yet into the usermeta table, getting the 'bp_xprofile_visibility_levels' usermeta returns an empty string while we're expecting an array. As we use the expected array to reset the visibility level if the administrator enforced a specific visibility to the field, it's causing the PHP8 warning. To fix it, we are now casting the 'bp_xprofile_visibility_levels' usermeta as soon as we get it.

Props johnjamesjacoby

Fixes #8503 (trunk)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-xprofile/bp-xprofile-functions.php

    r12981 r13012  
    13031303    }
    13041304
    1305     $user_visibility_levels = bp_get_user_meta( $user_id, 'bp_xprofile_visibility_levels', true );
     1305    $user_visibility_levels = (array) bp_get_user_meta( $user_id, 'bp_xprofile_visibility_levels', true );
    13061306
    13071307    // Parse the user-provided visibility levels with the default levels, which may take
     
    13181318
    13191319    $field_ids = array();
    1320     foreach( (array) $user_visibility_levels as $field_id => $field_visibility ) {
     1320    foreach( $user_visibility_levels as $field_id => $field_visibility ) {
    13211321        if ( in_array( $field_visibility, $levels ) ) {
    13221322            $field_ids[] = $field_id;
Note: See TracChangeset for help on using the changeset viewer.