• Resolved jimario

    (@jimario)


    HI, this topic was originally created 1 year ago and it was marked “Resolved” but didn’t have any sort of resolution or answer to it. Your last response to the OP was an inquiry as to how he was registering people with user roles different than his site’s default role. He didn’t answer but the post was still marked resolved.

    So I’d like to ask the same question. Can the approval process in your plugin be configured to moderate approvals for only 1 user role at registration?

    In my BuddyPress registration form, I have a hidden dropdown select containing only one value which is the user role I want the user to register as. The role is different than the default role in my WordPress installation. I accomplish this by using the following code in my functions.php file:

    ///* this forces "female" user role at registration via a hidden radio field on the buddypress registration form *//
    add_action('bp_core_activated_user', 'bp_custom_registration_role',10 , 3);
    function bp_custom_registration_role($user_id, $key, $user) {
       $userdata = array();
       $userdata['ID'] = $user_id;
       $userdata['role'] = xprofile_get_field_data('Gender', $user_id);
    
       if ($userdata['role'] == 'Female')
          $userdata['role'] = 'female';
          //only allow if user role is my_role
       if (($userdata['role'] == "female"))
          wp_update_user($userdata);
    
      }

    As it stands the plugin still forces Approval moderation for all users who register regardless of which user role is bestowed upon them during registration (I have multiple registration forms with different user roles based on different registration plugins).

    https://www.ads-software.com/plugins/bp-registration-options/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Michael Beckwith

    (@tw2113)

    The BenchPresser

    I guess I’m not completely clear what behavior you’re hoping to change with regards to the moderation process, or what your end goal is with this.

    Are you wanting users with the “female” role to be able to skip moderation, for example?

    Thread Starter jimario

    (@jimario)

    I actually want “Male” to skip your plugin’s Approval process but if it’s easier to have the Female role skip it, then that’s okay. Right now the Male user role is the wordpress default and the Female role is the one that is forced at registration.

    Michael Beckwith

    (@tw2113)

    The BenchPresser

    I’m not completely sure when the best place would be to have this execute, because I set the user meta we check for on the user_register hook, which I’m sure is different than the bp_core_activated_user hook. However, it may work as expected in your callback above, since I am sure the activation hook is run after the registration.

    I’d use this:

    bp_registration_set_moderation_status( $user_id, 'false' );

    We pass in the user ID and the 2nd parameter defaults to true, but this would set it to false and thus gets interpreted as not moderated. We do the same call when someone is getting approved.

    Thread Starter jimario

    (@jimario)

    I’ve attempted to use this with my code above but can’t seem to get it to work. Here’s where I put it:

    ///* this forces "female" user role at registration via a hidden radio field on the buddypress registration form *//
    add_action('bp_core_activated_user', 'bp_custom_registration_role',10 , 3);
    function bp_custom_registration_role($user_id, $key, $user) {
       $userdata = array();
       $userdata['ID'] = $user_id;
       $userdata['role'] = xprofile_get_field_data('Gender', $user_id);
    
       if ($userdata['role'] == 'Female')
          $userdata['role'] = 'female';
          //only allow if user role is my_role
       if (($userdata['role'] == "female"))
          wp_update_user($userdata);
    //* Your code below *//
          bp_registration_set_moderation_status( $user_id, 'false' );
      }

    Am I being too simplistic with my use of your code?

    Michael Beckwith

    (@tw2113)

    The BenchPresser

    Personally, I’d wrap your if statements in {}’s to be sure it’s executing all as expected in the appropriate conditions. Otherwise the function use is correct, and the $user_id should hold the current ID being checked on.

    As is, it’s going to run regardless of role/gender setting.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Approval by Role’ is closed to new replies.