我的目标是导入一个带有待售房屋的csv文件,如果房产经纪人还不存在的话,生成wordpress/buddypress用户身份的房产经纪人。我想通过使用WP all import中的自定义函数来完成此操作。另外,我想将内部用户的buddypress成员类型设置为"realtor“
我将把源字段映射到导入配置[create_realtor{realtor_column}]中的自定义字段
在我的例子中,它是[create_realtor{properties[1]/property[2]/value[1]}]
由于它是一个内部用途的用户,我不需要实际的房地产经纪人联系方式,所以用户的电子邮件将是realtor@mydomain.com,通行证可以生成,电子邮件给房地产经纪人是不需要的。
我发现可以像下面这样生成一个用户source
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
}我尝试了上面的方法,但得到一条消息:"Custom Field Value template is invalid: expected XPATH,statement is expected“。
我在这里有点迷惑,不知道如何继续
发布于 2020-07-21 22:20:33
你的问题是你没有正确地调用你的自定义函数。函数调用应该使用圆括号,如下所示:
[create_realtor({properties[1]/property[2]/value[1]})]始终从简单开始:
https://www.wpallimport.com/documentation/developers/custom-code/inline-php/
https://stackoverflow.com/questions/63013109
复制相似问题