Advertisement
NiTeWuRX

WP Change User Role on Gravity Form Complete

Apr 2nd, 2013
301
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //add_action('gform_post_submission_7', 'my_update_user_role');
  2. add_action('gform_after_submission_7', 'my_update_user_role', 10, 2);
  3. function my_update_user_role($entry) {
  4.  
  5.     //$user_id = get_current_user_id();  
  6.     //$user_id = (int) $_GET['user'];
  7.     //$user_id = wp_get_current_user();
  8.     // trying this as suggested by Chris Hajer
  9.     global $current_user;
  10.     get_currentuserinfo();
  11.     $user_id = $current_user->ID;
  12.    
  13.     echo $user_id;
  14.     if(!$user_id)
  15.         return;
  16.    
  17.     $user = new WP_User($user_id);
  18.     //$user->set_role('editor'); // update "editor" to the name of the role you'd like to update the user too
  19.     $user->remove_role( 'subscriber' );
  20.  
  21. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement