最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

plugin development - Import user data using CSV

programmeradmin1浏览0评论

I want to import user information using a CSV file. I am using the BP Groups Import User plugin.

The challenge is to add the first name and last name columns in the CSV file but I cannot get the value to save.

My table is

| email      | first name | last name | moderator | admin |
+------------+------------+-----------+-----------+-------+
|[email protected] | max        | biagi     |      1    |   1   |

my code

}else if(isset($_POST['create_user'])) {

                    //Create new user
                    $usermeta = array();
                    $usermeta['first_name'] = ucfirst ($first_name);
                    $usermeta['last_name'] = ucfirst ($last_name); 
                    $usermeta['password'] = wp_hash_password( $email );
                    $user_login = strtok($email, '@');
                    $user_id = bp_core_signup_user( $user_login, $email, $email, $usermeta );

                    //Add user to group
                    groups_join_group($group_id, $user_id );

                    //Promote user to group moderator
                    if($mod){
                        groups_promote_member($user_id,$group_id,'mod');
                    }
                    //Promote user to group administrator
                    if($admin){
                        groups_promote_member($user_id,$group_id,'admin');
                    }
                }

I can only save email.

Is there another way to get the value from the CSV table?

I want to import user information using a CSV file. I am using the BP Groups Import User plugin.

The challenge is to add the first name and last name columns in the CSV file but I cannot get the value to save.

My table is

| email      | first name | last name | moderator | admin |
+------------+------------+-----------+-----------+-------+
|[email protected] | max        | biagi     |      1    |   1   |

my code

}else if(isset($_POST['create_user'])) {

                    //Create new user
                    $usermeta = array();
                    $usermeta['first_name'] = ucfirst ($first_name);
                    $usermeta['last_name'] = ucfirst ($last_name); 
                    $usermeta['password'] = wp_hash_password( $email );
                    $user_login = strtok($email, '@');
                    $user_id = bp_core_signup_user( $user_login, $email, $email, $usermeta );

                    //Add user to group
                    groups_join_group($group_id, $user_id );

                    //Promote user to group moderator
                    if($mod){
                        groups_promote_member($user_id,$group_id,'mod');
                    }
                    //Promote user to group administrator
                    if($admin){
                        groups_promote_member($user_id,$group_id,'admin');
                    }
                }

I can only save email.

Is there another way to get the value from the CSV table?

Share Improve this question edited Apr 30, 2019 at 0:05 butlerblog 5,1313 gold badges28 silver badges44 bronze badges asked Sep 19, 2017 at 5:49 Diana RiderDiana Rider 4911 bronze badges 2
  • Your column names appear incorrect. first name and last name probably need underscores: first_name, last_name. Are the underscores missing in your actual CSV. Does changing this help? – Jacob Peattie Commented Sep 19, 2017 at 6:00
  • thank you but is not get the data. – Diana Rider Commented Sep 19, 2017 at 6:18
Add a comment  | 

1 Answer 1

Reset to default 1

UPDATE SOLVED

I change my code to wp_insert_user beside bp_core_user_signup

$user_id = wp_insert_user(array(
                            'user_login' => $user_login,
                            'user_pass' => wp_hash_password( $email ),
                            'first_name' => $first_name,
                            'last_name' => $last_name,
                            'display_name' => $first_name . ' ' . $last_name,
                            'user_email' => $email,
                            'user_nicename' => $first_name
发布评论

评论列表(0)

  1. 暂无评论