latest stable versions: v150827 (changelog)

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

choose role at registration

Home Forums Community Forum choose role at registration

This topic contains 7 replies, has 3 voices. Last updated by  Cristián Lávaque 3 years, 10 months ago.

Topic Author Topic
Posted: Sunday Mar 3rd, 2013 at 2:33 pm #43669
Oriol Boan
Username: orboan

Hi,
is there a way to show a dropdown menu, in registration and profile forms, where items are the diferents memberships (roles) levels? The idea is when the user registers (or modifying the profile) he chooses the role (s2member Level 0, Level 1, etc.). All membership levels are free in my business model, no paid, so user should have to be able to choose the role freely upon registration.
I tried custom registration fields to define a new feature (called role, with different profiles in a dropdown box) for the user profile, but they are only informative and not bound to real wordpress roles, thus the real role for the user can only be reassigned manually from the default role, in the backend by an admin, and this is not an option when there are thousands of users.

Thank you.

List Of Topic Replies

Viewing 7 replies - 1 through 7 (of 7 total)
Author Replies
Author Replies
Posted: Tuesday Mar 5th, 2013 at 3:28 am #43740
Oriol Boan
Username: orboan

Any hints on how to integrate the role selection in the registration and profile forms?

Posted: Wednesday Mar 6th, 2013 at 1:10 pm #43894
Eduan
Username: Eduan
Moderator

Hello Oriol,

I’m afraid this is not currently possible with s2Member, you would need to modify the pro-forms in order to achieve this. And probably s2Member as well. :/

However if you use buttons instead of pro-forms this is very possible. You would just implement something similar to this hack of mine: http://eduantech.com/2012/09/donation-button-that-gives-access/

– Eduan

Posted: Wednesday Mar 6th, 2013 at 5:34 pm #43906
Oriol Boan
Username: orboan

Hi Eduan,
I still don’t know how things with buttons exactly work, so I have some doubts:

Can I put a donation button (the one you describe in you blog), then, one for each of the membership levels I want to make available to users for choosing, and let the user choose one button or another depending on the role he/she wants to subscribe to?

Are these buttons to be added besides the other fields on registration form and be selected while registering, or before or after registration?

Can the donation be $0.00 or has to be a minimum amount?

ty

Posted: Thursday Mar 7th, 2013 at 8:36 am #43949

Any hints on how to integrate the role selection in the registration and profile forms?

Well, you could modify the pro-form to add your own field, or use an s2Member custom profile field, and then catch it after the form is submitted to change the user role. Knowledge Base » s2Member® Pro Forms

You can probably use the [hilite mono]set_user_role[/hilite] hook in a hack to change the role to the one the user chose in his custom profile field.
Knowledge Base » Hacking s2Member® Via Hooks/Filters
http://adambrown.info/p/wp_hooks/hook/set_user_role
http://www.s2member.com/codex/stable/s2member/api_functions/package-functions/#src_doc_get_user_field%28%29

I hope that helps. :)

Posted: Monday Mar 11th, 2013 at 9:19 am #44249
Oriol Boan
Username: orboan

Hello Cristián,
I’ve spent almost all day trying to add a combo box to registration form to let the user select the role. I’ve achieved it in wp registration form, but not in s2Member regostration form. To achieve this goal (select the role at registration) in wp registration form, I’ve used the next code:

function wp_choose_roles_registration_form() {
  global $wp_roles;
  if ( !isset( $wp_roles ) ) $wp_roles = new WP_Roles();
  $default_role = get_option("default_role");
  if($_POST['wp_rar_user_role']) {
    $selected_role = $_POST['wp_rar_user_role'];
  } else {
    $selected_role = $default_role;
  }
  if(count($this->wp_selected_rar_roles) < 2) return true;
  ?>
  <style type="text/css">
  <!--
  select.input {
    background: #FFF;
    border: 1px solid #E5E5E5;
    font-size: 16px;
    margin-bottom: 16px;
    margin-right: 6px;
    margin-top: 2px;
    padding: 3px;
    width: 100%;
  }
  -->
  </style>
  <p>
  <label for="wp_rar_user_role"><?php echo $this->wp_rar_role_label; ?><br />
    <select id="wp_rar_user_role" name="wp_rar_user_role" class="input select">
  <?php 
  foreach($this->wp_selected_rar_roles as $role) {
    ?>
    <option value="<?php echo $role; ?>"<?php echo ($selected_role == $role) ? ' selected="selected"' : ''; ?>>
      <?php echo $wp_roles->roles[$role]['name'];?>
    </option>
    <?php
  }
  ?>
    </select>
  </label>
  </p>
  <?php
}

  function set_roles_at_registration($user_ID) {
  if( in_array($_POST['wp_rar_user_role'], $this->wp_selected_rar_roles) ) {
    $wp_rar_user_role = $_POST['wp_rar_user_role'];
  } else {
    $wp_rar_user_role = get_option("default_role");
  }
  if(isset($wp_rar_user_role) and $user_ID) {
    wp_update_user( array ('ID' => $user_ID, 'role' => $wp_rar_user_role) );
  }
}

function init_rar() {
$wp_rar_plugin = new WPRolesAtRegistration;
add_action('register_form', array($wp_rar_plugin, 'wp_choose_roles_registration_form'));
add_action('user_register', array($wp_rar_plugin, 'set_roles_at_registration'));
}

add_action('init', 'init_rar');

where WPRolesAtRegistration is the class that contains the functions.
This is working ok in the wp rgistration form, but the combo box does not even appear in the s2Member registration form. Therefore my question is what hook may I have to try to add this combo box to the s2Member registration form.
In http://www.s2member.com/kb/pro-forms/ mentions a hook which is:

add_action('ws_plugin__s2member_during_configure_user_registration', 'store_my_custom_input_fields');

but if I add inside the function init_rar() the next:

add_action('ws_plugin__s2member_during_configure_user_registration', array($wp_rar_plugin, 'wp_choose_roles_registration_form'));

it’s useless, nothing new appears at s2member registration form. So, what am I missing? What’s the hook to use and how?
Please, help me, I’ve spent lots of hours.

Posted: Monday Mar 11th, 2013 at 9:30 am #44251
Oriol Boan
Username: orboan

It’s clear the hook “ws_plugin__s2member_during_configure_user_registration” does not work to add the combobox. What I need to know is what is the s2member equivalent hook to the “register_form” wp hook. Thanks.

Posted: Tuesday Mar 12th, 2013 at 12:27 pm #44397

it’s useless, nothing new appears at s2member registration form. So, what am I missing?

Pro-forms have templates which you can customize. See:

Knowledge Base » s2Member® Pro Forms » Customize
Knowledge Base » s2Member® Pro Forms » Custom Data

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

This topic is closed to new replies. Topics with no replies for 2 weeks are closed automatically.

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Contacting s2Member: Please use our Support Center for bug reports, pre-sale questions & technical assistance.