Created
September 1, 2021 09:45
-
-
Save wp-user-manager/6d845fd9bf0d6f0e2c665b1f9d38bd74 to your computer and use it in GitHub Desktop.
WP User Manager - Conditional user role at registration based on a custom field
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'wpum_after_registration', 'wpum_conditional_role', 20, 2 ); | |
function wpum_conditional_role( $user_id, $values ) { | |
$field_key = 'wpum_field_14'; // Change this to your field key | |
if ( ! isset( $values['register'][ $field_key ] ) ) { | |
return; | |
} | |
$value = $values['register'][ $field_key ]; | |
if ( $value == 'food' ) { // Change logic to be what you need based on value | |
$user = new WP_User( $user_id ); | |
$user->set_role( 'editor' ); // Change role | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Save this file to your /wp-content/mu-plugins/ directory (you might need to create the mu-plugins directory).