Skip to:
Content
Pages
Categories
Search
Top
Bottom

BUG in bp_remove_member_type

  • @sx1001

    Participant

    Hi all,

    there is a huge bug in bp_remove_member_type which can potentially break the page in PHP 8:

    This piece of code:

    
    // No need to continue if the member doesn't have the type.
    	$existing_types = bp_get_member_type( $user_id, false );
    	if ( ! in_array( $member_type, $existing_types, true ) ) {
    		return false;
    	}
    

    breaks if a user has NO membertype, because bp_get_member_type can return false instead of an empty array. So either check whether $existing_types is_array()…

    OR: Fix bp_get_member_type(), so that if $single=false, that it returns an empty array instead of false…

    Nasty BUG!
    In the meantime I fixed it using functions like this:

    
    add_filter('bp_get_member_type', function($type, $user_id, $single)
    {
        if(!$single && !is_array($type))
            return array($type);
    
        return $type;
    }, 99, 3);
Viewing 2 replies - 1 through 2 (of 2 total)
  • @imath

    Moderator

    Hi,

    Thanks for your feedback, this will be fixed in next minor release. See https://buddypress.trac.wordpress.org/ticket/8639

    @sx1001

    Participant

    Thank you Mathieu Viet!
    I think it would be even more “reliable” to fix it directly within bp_get_member_type to return an empty array instead of false, so that not every function using bp_get_member_type must add the check “is_array” – what do you think?

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Skip to toolbar