My goal is to import a csv file with houses for sale and generate realtors as wordpress/buddypress user if they don't exist yet. I want to do so by using a custom function in WP all import. Addtitionally i would like to set the buddypress membertype to "realtor" for internal user
I will map the source field to a custom field in the import config
[create_realtor{realtor_column}]
in my case that is [create_realtor{properties[1]/property[2]/value[1]}]
As it is a user for internal purposes, i don't need the actual realtor contact details, so the user email will be realtor@mydomain.com, pass can generated, email to realtor not needed.
I found that a user can be generated as below 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
How can i wrap all in a function that will generate the user based on the realtor name in my feed would it be like below?
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
}
I tried above, but it results in a message saying "Custom Field Value template is invalid: Unexpected token XPATH, statement was expected."
I am a bit lost here on how to procede