首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用于从csv列创建用户的WPallimport函数

用于从csv列创建用户的WPallimport函数
EN

Stack Overflow用户
提问于 2020-07-21 19:04:01
回答 1查看 141关注 0票数 1

我的目标是导入一个带有待售房屋的csv文件,如果房产经纪人还不存在的话,生成wordpress/buddypress用户身份的房产经纪人。我想通过使用WP all import中的自定义函数来完成此操作。另外,我想将内部用户的buddypress成员类型设置为"realtor“

我将把源字段映射到导入配置[create_realtor{realtor_column}]中的自定义字段

在我的例子中,它是[create_realtor{properties[1]/property[2]/value[1]}]

由于它是一个内部用途的用户,我不需要实际的房地产经纪人联系方式,所以用户的电子邮件将是realtor@mydomain.com,通行证可以生成,电子邮件给房地产经纪人是不需要的。

我发现可以像下面这样生成一个用户source

代码语言:javascript
复制
if( null == username_exists( $email_address ) ) {

  // Generate the password and create the user
  $password = wp_generate_password( 12, false );
  $user_id = wp_create_user( $email_address, $password, $email_address );
 
  // Set the nickname
  wp_update_user(
    array(
     'ID'          =>    $user_id,
     'nickname'    =>    $email_address  
    )
  );

 
  // Set the role
  $user = new WP_User( $user_id );
  $user->set_role( 'subscriber' );
 
 
} // end if

我怎样才能把所有这些都封装在一个函数中,这个函数将根据我提要中的房地产经纪人姓名生成用户,它会像下面这样吗?

代码语言:javascript
复制
function create_realtor($realtor) {

$emailadress = $realtor . '@mydomain.com' ;

if( null == username_exists( $email_address ) ) {

  // Generate the password and create the user
  $password = wp_generate_password( 12, false );
  $user_id = wp_create_user( $email_address, $password, $email_address );
 
  // Set the nickname
  wp_update_user(
    array(
     'ID'          =>    $user_id,
     'nicename'    =>    $nicename,  //realtor
     'nickname'    =>    $email_address  //realtor@mydomain.com
    )
  );

 

  // Set the role
  $user = new WP_User( $user_id );
  $user->set_role( 'subscriber' );

// Set the member type of user to 'realtor'.
$member_type = bp_set_member_type( $user_id, 'realtor' );
 
 
} // end if




}

我尝试了上面的方法,但得到一条消息:"Custom Field Value template is invalid: expected XPATH,statement is expected“。

我在这里有点迷惑,不知道如何继续

EN

回答 1

Stack Overflow用户

发布于 2020-07-21 22:20:33

你的问题是你没有正确地调用你的自定义函数。函数调用应该使用圆括号,如下所示:

代码语言:javascript
复制
[create_realtor({properties[1]/property[2]/value[1]})]

始终从简单开始:

  • 通读下面的示例2
  • 先让一个简单的函数运行
  • ,然后在其上构建并插入您的自定义逻辑

https://www.wpallimport.com/documentation/developers/custom-code/inline-php/

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63013109

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档