简体   繁体   中英

Can I create a custom WordPress registration form?

I want to have in WordPress two kind of registration forms. The default one for let's say visitors users and a custom one for some more privileged users. How can I make the custom one? I especially need the part with the roles, the custom reg form will have another role for the users that will register to it. How can I do that? I think I need something like(it's just a fabulation, don't know the real functions from WordPress)

Example:

//the following variables will be a part of the form that will stand above this function
 add_user('$username','$mail','$location','$region','$role');
//where $role can be {1(subscribers),2(contrib.),3(authors),4(editor),5(admin)}

Can I do something like that?

You can use Gravity Forms to create your registration forms with the User Registration add-on and specify custom user meta (including roles.) If you would like to create a custom form without a plugin, you should not attempt to add users directly to the database, instead you should use the wp_create_user function. From the WordPress Codex :

The wp_create_user function allows you to insert a new user into the WordPress database. It uses the $wpdb class to escape the variable values, preparing it for insertion into the database. Then the PHP compact() function is used to create an array with these values. To create a user with additional parameters, use wp_insert_user().

You can install a webform module in wordpress. Selected an existing form and customize the fields as per your requirement.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM