Adding Custom Capability Based on a Field

Labels

This Discussion is public

Notifications

I'm using Formidable Pro with User Registration. Also, using S2member where I have two user roles "Applicant" and "Partner." I use custom capabilities to determine different parts of pages a partner can see (based on product, location, etc).

I'd would like to have other members of an organization that has already been approved to be a partner register using a special code given to them, so they can access the right pages automatically without having to be manually approved and have the capability added manually. This special code would translae to the custom capabilities.

Basically I'd like to do something like this:

add_filter('frmreg_new_role', 'frmreg_new_role', 10, 2);
function frmreg_new_role($role, $atts){
  extract($atts);
  if($form->id == 5){
    if($_POST['item_meta'][125] == 'Author') //change 125 to the ID of your field and 'Author' to the value of your radio button
      $role = 'author';
  }
  return $role;
}

But instead of assigning the role, assigning the custom capability..  $user = wp_get_current_user(); $user->add_cap('access_s2member_ccap_music'); 

Can anyone help?

This isn't a complete solution, just a thought:

How about creating custom roles? We use WP User Role Editor to create custom roles (with custom capabilities.) You could use conditional php or shortode to hide various sections on your page/post.  The form can use sections with conditions.  Something similar to:

 

function show_hide() {
if (!current_user_can('administrator') && !current_user_can('editor') && !is_admin()) {$print_style = '<div style="display:inline;">';}
else { $print_style = '<div style="display:none;">';}
return $print_style;
}
add_shortcode('div_display', 'show_hide');

Reply to this Discussion