1

我的目标是导入一个包含待售房屋的 csv 文件,并生成房地产经纪人作为 wordpress/buddypress 用户(如果它们尚不存在)。我想通过在 WP all import 中使用自定义函数来做到这一点。另外,我想将内部用户的 buddypress 成员类型设置为“房地产经纪人”

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

在我的情况下[create_realtor{properties[1]/property[2]/value[1]}]

由于它是用于内部目的的用户,我不需要实际的房地产经纪人联系方式,因此用户电子邮件将是 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,
     'nickname'    =>    $email_address  
    )
  );

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

我如何将所有内容包装在一个函数中,该函数将根据我的提要中的房地产经纪人名称生成用户,它会像下面这样吗?


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




}

我在上面尝试过,但它导致一条消息说“自定义字段值模板无效:意外的令牌 XPATH,需要声明。”

我在这里有点迷失了如何进行

4

1 回答 1

0

您的问题是您没有正确调用自定义函数。函数调用应该有这样的圆括号:

[create_realtor({properties[1]/property[2]/value[1]})]

总是从简单开始:

  • 通读下面的示例 2
  • 首先获得一个简单的功能
  • 然后在其上构建并插入您的自定义逻辑

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

于 2020-07-21T14:20:33.350 回答