{"id":761,"date":"2026-10-20T09:03:10","date_gmt":"2026-10-20T08:03:10","guid":{"rendered":"https:\/\/userswp.io\/documentation\/article\/userswp-registration-hooks\/"},"modified":"2026-10-20T09:03:10","modified_gmt":"2026-10-20T08:03:10","slug":"userswp-registration-hooks","status":"publish","type":"gd_place","link":"https:\/\/userswp.io\/documentation\/article\/code-snippets\/userswp-registration-hooks\/","title":{"rendered":"UsersWP registration hooks: run code after a user registers"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">UsersWP fires its own actions and filters while it processes the register form. To run code once registration has finished, for example to change the new user&#8217;s role or copy a field somewhere else, use the <code>uwp_after_process_register<\/code> action.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why user_register runs too early<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">WordPress fires <code>user_register<\/code> inside <code>wp_insert_user()<\/code>, as soon as the account exists. UsersWP saves the extra fields from your register form after that, in its own <code>uwp_usermeta<\/code> table. So when <code>user_register<\/code> runs, the values from your custom fields are not saved yet.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Registration hooks in the order they run<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>uwp_before_validate<\/code> (action) runs before the submitted fields are checked. It receives the form type, <code>register<\/code>.<\/li>\n\n\n\n<li><code>uwp_validate_result<\/code> (filter) lets you add your own checks. Return a <code>WP_Error<\/code> to stop the registration and show your message.<\/li>\n\n\n\n<li><code>uwp_after_validate<\/code> (action) runs once validation has passed, before the user is created.<\/li>\n\n\n\n<li><code>uwp_before_extra_fields_save<\/code> (filter) runs after the user is created and before the custom fields are saved, so you can change the values.<\/li>\n\n\n\n<li><code>uwp_after_extra_fields_save<\/code> (filter) runs straight after the custom fields are saved.<\/li>\n\n\n\n<li><code>uwp_after_custom_fields_save<\/code> (action) runs when the custom fields are saved and can be read back. It receives the form type, the posted data, the validated values and the user ID.<\/li>\n\n\n\n<li><code>uwp_after_process_register<\/code> (action) runs when registration is complete and the emails have gone out. It receives the validated values and the new user ID.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">The validation hooks also run for the login, forgot password, change password, reset and account forms. Check the form type in your callback so your code only runs for registration.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Example: change the role based on a field<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">This snippet reads a custom field after registration and gives the user the Author role when the field has a certain value. Replace <code>account_type<\/code> with the key of your own field, and use roles that exist on your site.<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-php\">add_action( &#039;uwp_after_process_register&#039;, &#039;my_uwp_after_register&#039;, 10, 2 );\nfunction my_uwp_after_register( $data, $user_id ) {\n\t$account_type = uwp_get_usermeta( $user_id, &#039;account_type&#039;, &#039;&#039; );\n\n\tif ( &#039;business&#039; === $account_type ) {\n\t\t$user = new WP_User( $user_id );\n\t\t$user-&gt;set_role( &#039;author&#039; );\n\t}\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Add the code to your child theme&#8217;s functions.php file or with a plugin such as Code Snippets. <a href=\"https:\/\/userswp.io\/documentation\/article\/userswp-functions\/userswp-function-uwp_get_usermetauser_id-field_key\/\">uwp_get_usermeta()<\/a> reads any UsersWP field for a user.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">A different role for each register form<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">If all you need is a different role per form, you can do it without code. Each register form in UsersWP is a user type with its own role. Go to UsersWP > User Types, edit the user type and choose the role in User Role to Assign.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">UsersWP also saves the ID of the form a user signed up with in the user meta key <code>_uwp_register_form_id<\/code>, so your own code can check which form was used with <code>get_user_meta( $user_id, &#039;_uwp_register_form_id&#039;, true )<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">These hooks belong to the UsersWP register form. Accounts that an admin adds in wp-admin, or that another plugin creates, do not pass through them.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>UsersWP fires its own actions and filters while it processes the register form. To run code once registration has finished, for example to change the new user&#8217;s role or copy a field somewhere else, use the uwp_after_process_register action. Why user_register runs too early WordPress fires user_register inside wp_insert_user(), as soon as the account exists. UsersWP [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"footnotes":""},"article\/tags":[],"article\/categories":[40,7],"class_list":["post-761","gd_place","type-gd_place","status-publish","hentry","gd_placecategory-code-snippets","gd_placecategory-tips-tricks-more"],"_links":{"self":[{"href":"https:\/\/userswp.io\/documentation\/wp-json\/wp\/v2\/article\/761","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/userswp.io\/documentation\/wp-json\/wp\/v2\/article"}],"about":[{"href":"https:\/\/userswp.io\/documentation\/wp-json\/wp\/v2\/types\/gd_place"}],"author":[{"embeddable":true,"href":"https:\/\/userswp.io\/documentation\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/userswp.io\/documentation\/wp-json\/wp\/v2\/comments?post=761"}],"version-history":[{"count":0,"href":"https:\/\/userswp.io\/documentation\/wp-json\/wp\/v2\/article\/761\/revisions"}],"wp:attachment":[{"href":"https:\/\/userswp.io\/documentation\/wp-json\/wp\/v2\/media?parent=761"}],"wp:term":[{"taxonomy":"gd_place_tags","embeddable":true,"href":"https:\/\/userswp.io\/documentation\/wp-json\/wp\/v2\/article\/tags?post=761"},{"taxonomy":"gd_placecategory","embeddable":true,"href":"https:\/\/userswp.io\/documentation\/wp-json\/wp\/v2\/article\/categories?post=761"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}