Title: arbitrage's Replies | WordPress.org

---

# arbitrage

  [  ](https://wordpress.org/support/users/arbitrage/)

 *   [Profile](https://wordpress.org/support/users/arbitrage/)
 *   [Topics Started](https://wordpress.org/support/users/arbitrage/topics/)
 *   [Replies Created](https://wordpress.org/support/users/arbitrage/replies/)
 *   [Reviews Written](https://wordpress.org/support/users/arbitrage/reviews/)
 *   [Topics Replied To](https://wordpress.org/support/users/arbitrage/replied-to/)
 *   [Engagements](https://wordpress.org/support/users/arbitrage/engagements/)
 *   [Favorites](https://wordpress.org/support/users/arbitrage/favorites/)

 Search replies:

## Forum Replies Created

Viewing 13 replies - 1 through 13 (of 13 total)

 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[Post From Site] [Plugin: Post From Site] Error following post](https://wordpress.org/support/topic/plugin-post-from-site-error-following-post/)
 *  [arbitrage](https://wordpress.org/support/users/arbitrage/)
 * (@arbitrage)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/plugin-post-from-site-error-following-post/#post-1763699)
 * Did the re-ordering of the JS files solve the issue? If yes, where can I impact
   the order, since most of the files are loaded via wp_head.
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[Plugin: Theme My Login] How to add role based user notifications](https://wordpress.org/support/topic/plugin-theme-my-login-how-to-add-role-based-user-notifications/)
 *  Thread Starter [arbitrage](https://wordpress.org/support/users/arbitrage/)
 * (@arbitrage)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/plugin-theme-my-login-how-to-add-role-based-user-notifications/#post-1878865)
 * Ok. I could consider this. I contact you via your website.
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[Plugin: Theme My Login] How to add role based user notifications](https://wordpress.org/support/topic/plugin-theme-my-login-how-to-add-role-based-user-notifications/)
 *  Thread Starter [arbitrage](https://wordpress.org/support/users/arbitrage/)
 * (@arbitrage)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/plugin-theme-my-login-how-to-add-role-based-user-notifications/#post-1878850)
 * Yes, exactly. Depending on the user role wordpress shall send specific new user
   and account activation mail.
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[Plugin: Theme My Login] add_action user_register does not work](https://wordpress.org/support/topic/plugin-theme-my-login-add_action-user_register-does-not-work/)
 *  Thread Starter [arbitrage](https://wordpress.org/support/users/arbitrage/)
 * (@arbitrage)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/plugin-theme-my-login-add_action-user_register-does-not-work/page/2/#post-1850580)
 * Hi Jeff, many thanks for the support. I found the origin for the problem of passing
   the value from the POST variable role. It was a mistake in the form validation
   check.
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[Plugin: Theme My Login] add_action user_register does not work](https://wordpress.org/support/topic/plugin-theme-my-login-add_action-user_register-does-not-work/)
 *  Thread Starter [arbitrage](https://wordpress.org/support/users/arbitrage/)
 * (@arbitrage)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/plugin-theme-my-login-add_action-user_register-does-not-work/page/2/#post-1850579)
 * Maybe there is one more thing, you could help me. Do have any idea how to implement
   role based User Notification mails e.g. “New User” and “Account Activated” to
   the Theme My Login plugin?
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[Plugin: Theme My Login] add_action user_register does not work](https://wordpress.org/support/topic/plugin-theme-my-login-add_action-user_register-does-not-work/)
 *  Thread Starter [arbitrage](https://wordpress.org/support/users/arbitrage/)
 * (@arbitrage)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/plugin-theme-my-login-add_action-user_register-does-not-work/#post-1850578)
 * I could not find where it is buffered. But when I directly set the value of role
   instead of _$\_POST[‘role’]_ the role is correctly defined after email confirmation
   of the user.
 *     ```
       //$role = sanitize_text_field( $_POST['role'] );
       $role = 'bdonator';
       ```
   
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[Plugin: Theme My Login] add_action user_register does not work](https://wordpress.org/support/topic/plugin-theme-my-login-add_action-user_register-does-not-work/)
 *  Thread Starter [arbitrage](https://wordpress.org/support/users/arbitrage/)
 * (@arbitrage)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/plugin-theme-my-login-add_action-user_register-does-not-work/#post-1850576)
 * Sorry, my last response did confuse you. Here is the actual code with which I
   got the problem.
 * In the regsiter form:
 * `<input type="hidden" name="role" value="bdonator" />`
 * In functions.php:
 *     ```
       function set_role_on_registration( $user_id ) {
   
       	//$role = sanitize_text_field( $_POST['role'] );
       	$role = 'bdonator';
   
       	if ( in_array( $role, array( 'bdonator', 'bprofessional' ) ) )
       		add_user_meta( $user_id, 'pending_role', $role );
       }
       add_action( 'tml_new_user_registered', 'set_role_on_registration' );
   
       function set_role_on_activation( $user_id ) {
       	if ( $pending_role = get_user_meta( $user_id, 'pending_role', true ) ) {
   
       		if ( !in_array( $pending_role, array( 'bdonator', 'bprofessional' ) ) )
       			return;
   
       		$user = new WP_User( $user_id );
   
       		$user->set_role( $pending_role );
   
       		unset( $user );
   
       	}
       }
       add_action( 'tml_new_user_activated', 'set_role_on_activation' );
       ```
   
 * Thanks in advance for your patience 🙂
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[Plugin: Theme My Login] add_action user_register does not work](https://wordpress.org/support/topic/plugin-theme-my-login-add_action-user_register-does-not-work/)
 *  Thread Starter [arbitrage](https://wordpress.org/support/users/arbitrage/)
 * (@arbitrage)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/plugin-theme-my-login-add_action-user_register-does-not-work/#post-1850574)
 * Thanks for the quick reaction. I did.
 * Since it functions when I just put
 * `$role = 'my_role1';`
 * I am sure that the POST is the problem.
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[Plugin: Theme My Login] add_action user_register does not work](https://wordpress.org/support/topic/plugin-theme-my-login-add_action-user_register-does-not-work/)
 *  Thread Starter [arbitrage](https://wordpress.org/support/users/arbitrage/)
 * (@arbitrage)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/plugin-theme-my-login-add_action-user_register-does-not-work/#post-1850572)
 * Guess so, either. However, it does not. I checked if the hidden field actually
   exists and put it into the register form. But still nothing. I attached to action
   tag of the register form &role=myrole to get the value via GET. But still nothing!
 * In the register form and before the submit button I put:
 * `<input type="hidden" name="role" value="bdonator" />`
 * and removed _add\_action(‘register\_form’,’show\_role\_field’);_.
 * In the function _set\_role\_on\_registration_ I put:
 *     ```
       $role = sanitize_text_field( $_POST['role'] );
       // $role = sanitize_text_field( $_GET['role'] );
       ```
   
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[Plugin: Theme My Login] add_action user_register does not work](https://wordpress.org/support/topic/plugin-theme-my-login-add_action-user_register-does-not-work/)
 *  Thread Starter [arbitrage](https://wordpress.org/support/users/arbitrage/)
 * (@arbitrage)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/plugin-theme-my-login-add_action-user_register-does-not-work/#post-1850569)
 * Thank you very much for the revised solution. I have now more detailed view on
   the hooks of WordPress and Theme My Login plugin.
 * But anyhow I cannot receive the _$\_POST[‘role’]_ in function _set\_role\_on\
   _registration_.
 *     ```
       function show_role_field(){
           ?>
           <input id="role" type="hidden" tabindex="20" size="25" value="my_role1" name="role"/>
           <?php
       }
       add_action('register_form','show_role_field');
   
       function set_role_on_registration( $user_id ) {
   
       	$role = 'my_role1'; // Works fine
               $role = sanitize_text_field( $_POST['role'] ); // Does not work
   
       	if ( in_array( $role, array( 'my_role1', 'my_role2' ) ) )
       		add_user_meta( $user_id, 'pending_role', $role );
       }
       add_action( 'tml_new_user_registered', 'set_role_on_registration' );
   
       function set_role_on_activation( $user_id ) {
       	if ( $pending_role = get_user_meta( $user_id, 'pending_role', true ) ) {
   
       		if ( !in_array( $pending_role, array( 'my_role1', 'my_role2' ) ) )
       			return;
   
       		$user = new WP_User( $user_id );
   
       		$user->set_role( $pending_role );
   
       		unset( $user );
       	}
       }
       add_action( 'tml_new_user_activated', 'set_role_on_activation' );;
   
       //end set user role at registration
       ```
   
 * Do you any hint for me what I am doing wrong? Thanks in advance.
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[Plugin: Theme My Login] add_action user_register does not work](https://wordpress.org/support/topic/plugin-theme-my-login-add_action-user_register-does-not-work/)
 *  Thread Starter [arbitrage](https://wordpress.org/support/users/arbitrage/)
 * (@arbitrage)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/plugin-theme-my-login-add_action-user_register-does-not-work/#post-1850538)
 * Yes. Seems that this was the reason. Due to the user moderation option “email
   verifcation”, registering a individual role on registration does not work.
 * Line 271 in user-moderation.php:
 *     ```
       $user_object = new WP_User( $user->ID );
       $user_object->set_role( get_option( 'default_role' ) );
       unset( $user_object );
       ```
   
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[Plugin: Theme My Login] add_action user_register does not work](https://wordpress.org/support/topic/plugin-theme-my-login-add_action-user_register-does-not-work/)
 *  Thread Starter [arbitrage](https://wordpress.org/support/users/arbitrage/)
 * (@arbitrage)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/plugin-theme-my-login-add_action-user_register-does-not-work/#post-1850537)
 * Thanks. But, doesn’t work either. Could it be because of the user moderation 
   by email verifcation? Because the role is “Pending” after registration and after
   email confirmation the role is set to the default role.
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[Plugin: Theme My Login] add_action user_register does not work](https://wordpress.org/support/topic/plugin-theme-my-login-add_action-user_register-does-not-work/)
 *  Thread Starter [arbitrage](https://wordpress.org/support/users/arbitrage/)
 * (@arbitrage)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/plugin-theme-my-login-add_action-user_register-does-not-work/#post-1850519)
 * Thanks for the post. It is still not working. In my opinion it’s not about the
   function, its about the failed calling of the function during registration.
 * It seems that _add\_action( ‘user\_register’, ‘set\_role\_on\_registration’ );_
   does not work! I’ve tried to output an echo or alert in the function _set\_role\
   _on\_registration_, but nothing happens.
 * My current approach in functions.php:
 *     ```
       //create custom user role at registration
       ## example link: http://example.com/wp-login.php?action=register&role=my_role1
       //
   
       function show_role_field(){
       	?>
           <input id="role" type="hidden" tabindex="20" size="25" value="<?php if (isset($_GET['role'])){echo $_GET['role'];} ?>"  name="role"/>
       	<?php
       }
       add_action('register_form','show_role_field');
   
       function set_role_on_registration( $user_id ) {
   
       	$new_role = sanitize_text_field( $_POST['role'] );
   
       	//only allow if user role is one of defined roles
   
       	if (
       		($new_role == "my_role1") or
       		($new_role == "my_role2") )
       	{
       		// Instantiate a user object
       		$user = new WP_User( $user_id );
   
       		// Set your role
       		$user->set_role( $new_role );
   
       		// Destroy user object
       		unset( $user );	}
       }
       add_action( 'user_register', 'set_role_on_registration' );
   
       //end create user role at registration
       ```
   

Viewing 13 replies - 1 through 13 (of 13 total)