wordpress - Change current user role with form selection on update (not entry creation) -


i'm using formidable forms in wordpress , have form registers users. can use radio button in registration form determine role be. have hook that. need, however, hook change user role based on radio selection on form entry update. current code works on entry creation. here code assigns roles on registration:

add_filter('frmreg_new_role', 'frmreg_new_role', 10, 2);  function frmreg_new_role($role, $atts){   extract($atts);   if($form->id == 8){     if($_post['item_meta'][280] == 'job applicant')       $role = 'applicant';   }   return $role; } 

"8" id of form itself. "280" id of radio button field "job applicant" 1 of values. , "applicant" 1 of our site's user roles.

i need adaptation of change role after entry has been created, on update. closest thing can find hook changes user role after successful paypal payment. tried combine 2 couldn't work. here paypal generated user role changer:

add_action('frm_payment_paypal_ipn', 'change_paid_user_role');  function change_paid_user_role($args){     $new_role = 'contributor'; //change role paid users should have      if(!$args['pay_vars']['completed'])        return; //don't continue if payment not completed      if(!$args['entry']->user_id or !is_numeric($args['entry']->user_id))        return; //don't continue if not linked user      $user = get_userdata($args['entry']->user_id);     if(!$user)         return; //don't continue if user doesn't exist      $updated_user = (array)$user;      // highest/primary role user       $user_roles = $user->roles;     $user_role = array_shift($user_roles);     if ( $user_role == 'administrator' )          return; //make sure don't downgrade admins      $updated_user['role'] = $new_role;      wp_update_user($updated_user); } 

update: action hook should be: frm_after_create_entry according formidable forums.

many times, researching core files more productive google or manual. dropping whole plugin directory in code editor , researching string frm_after_create_entry takes create() method hook happens.

after that, there's update() method , provides action hook: frm_after_update_entry.

this hook passes 2 parameters: $id , $new_values['form_id']. cannot reproduce setup, testing hook you.

reference: actions , filters not same thing…

in example:

add_action( 'frm_after_update_entry', 'change_role_to_staff', 10, 2);   function change_role_to_staff( $form_id, $values ){      var_dump($values);     die(); } 
  • as action hook, nothing has returned.
  • there's no $roles or $atts, parameters form id , values.
  • what you're looking inside $values.
  • var_dump() , die() debugging purposes , must removed @ once after testing.
  • do wp_update_user values , adapting previous code.

Comments

Popular posts from this blog

java - JavaFX 2 slider labelFormatter not being used -

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -