Advertisement
Guest User

Untitled

a guest
Apr 18th, 2017
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. <?php
  2.  
  3. add_action( 'user_register', 'myplugin_add_warrior_role', 10, 1 );
  4.  
  5. function myplugin_add_warrior_role( $user_id ) {
  6.  
  7. error_log( 'Action rodou!' );
  8.  
  9. $user = get_user_by( 'id', $user_id );
  10. error_log( print_r( $user, true ) );
  11.  
  12. $roles = (array) $user->roles;
  13. if ( in_array( 'customer', $roles ) ) {
  14. error_log( 'Entrou no IF' );
  15.  
  16. $result = wp_update_user( array(
  17. 'ID' => $user_id,
  18. 'role' => array_push( $roles, 'guerreiro' ),
  19. ) );
  20.  
  21. if (is_wp_error( $result )) {
  22. error_log( 'Erro: ' $result->get_error_message() );
  23. } else {
  24. error_log( 'Usuário salvo com sucesso: ' . $result );
  25. }
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement