If this is being run when you register a user, then you could just grab the email used in creating the user as it is contained in the second argument that is passed to user_register
which is $userdata
. See https://developer.wordpress.org/reference/hooks/user_register/
Note that to provide you with an example that would actually result in something useable, I also added sanitize_title
which is going to make the result “URL safe”. A raw email address is not a URL-safe value as the “@” is not a useable value.
add_action('user_register', 'add_form_link', 10, 2);
function add_form_link( $user_id, $userdata ) {
$emailurl="https://www.ourwebsite.com/" . sanitize_title( $userdata['user_email'] ) . '/form/';
add_user_meta( $user_id, 'Form_URL', $emailurl );
}
To make this more portable, I would recommend NOT saving the full URL, but rather everything after the domain. Then when using, you can append the local domain by using home_url()
. Otherwise, by putting in a complete URL, you can’t make adjustments to the saved value later without manipulating the string result itself.