Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- add_action( 'user_register', 'myplugin_add_warrior_role', 10, 1 );
- function myplugin_add_warrior_role( $user_id ) {
- error_log( 'Action rodou!', 1, 'seu-email@exemplo.com' );
- $user = get_user_by( 'id', $user_id );
- error_log( print_r( $user, true ), 1, 'seu-email@exemplo.com' );
- $roles = (array) $user->roles;
- if ( in_array( 'customer', $roles ) ) {
- error_log( 'Entrou no IF', 1, 'seu-email@exemplo.com' );
- $result = wp_update_user( array(
- 'ID' => $user_id,
- 'role' => array_push( $roles, 'guerreiro' ),
- ) );
- if (is_wp_error( $result )) {
- error_log( 'Erro: ' $result->get_error_message(), 1, 'seu-email@exemplo.com' );
- } else {
- error_log( 'UsuΓ‘rio salvo com sucesso: ' . $result, 1, 'seu-email@exemplo.com' );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement