Skip to:
Content
Pages
Categories
Search
Top
Bottom

Friends list not showing members


  • Robert D Payne
    Participant

    @rpayne7264

    WordPress version: 5.2.1
    Budddypress version: 4.4.0

    I am coding a friends import page, and everything is working as expected, except that when I go to view the imported friends under Friendships, no members show up. Instead there is an info box that says no members found. The friends count on the nav bar is correct. Does anyone have any idea about what might be the issue?

    Here is the function I wrote to upload and parse a csv file with php.

    function handleFriendsImportPostback() {
        $msg = [
            'message'   => '',
            'has_error' => false,
            'friends_added' => 0,
            'row_count' => 0
        ];
        
        
            //if there was an error uploading the file
        if ($_FILES["csv"]["error"] > 0) {
            
            $msg['message'] = "Return Code: " . $_FILES["csv"]["error"] . "<br />";
            $msg['has_error'] = true;
    
        }
        else {
            
            $currentUserID = get_current_user_id();
            $tmpName = $_FILES['csv']['tmp_name'];
            $csvAsArray = array_map('str_getcsv', file($tmpName));
            
            foreach ($csvAsArray as $friend) {
                $fname = $friend[0];
                $lname = $friend[1];
                $email = $friend[2];
                $msg['row_count']++;
                
                $user = get_user_by('email', $email);
                if(empty($user)) $user = get_user_by('login', $email);
                
                if(!empty($user)) continue;
    
                $userdata = array(
                    'first_name'    =>  $fname,
                    'last_name'    =>  $lname,
                    'user_email' => $email,
                    'user_url'  =>  '',                 
                    'display_name' => trim($fname . ' ' . $lname),
                    'user_login' => $email,
                    'user_pass' => wp_generate_password( $length=8, $include_standard_special_chars=false ),
                    'show_admin_bar_front' => 'false',
                    'description' => ''
                );
    
                $userID = wp_insert_user($userdata,true);
                if(is_wp_error($userID)){
                    continue;
                }else{
                    $msg['friends_added']++;
                }
                
                $user = new WP_User($userID);
                $user->add_role('rdp_unverified');
                $user->remove_role( 'subscriber' );                
    
                
                friends_add_friend( $currentUserID, $userID, true);
            }
            
            $msg['message'] = __('Import completed.');
    
        }
        
        return $msg;
    }//handleFriendsImportPostback
  • You must be logged in to reply to this topic.
Skip to toolbar