Skip to:
Content
Pages
Categories
Search
Top
Bottom

Setting New Role Upon Login with iMember360 Plugin


  • davellan
    Participant

    @davellan

    So iMember360 has a hook that I am trying to attach with to bbPress that I am struggling to do.

    I want to set it up so that when a user logins, and they contain certain tags (detected by iMember360), to change bbPress roles.

    Below is the hook I am trying to use.

    function my_i4w_authenticated_lremote_ogin($wp_user, $arrINFU) {
      //
      // $wp_user is the user object (same as the standard $current_user)
      //
      // $contact is an array with all contact record fields.
      // add your code to perform any desired action, such as sending an email notification
      // or updating contact record to reflect the login that just took place
    
      $your_code_goes_here = true;
    
    }
    
    add_action('i4w_authenticated_remote_login', 'my_i4w_authenticated_remote_login',10,2);
    

    Here is what I tried to do:

    function i4w_authenticated_remote_login_action($user, $contact) {
      global $SESSION;
      IF ($arrTAGS = explode(',', $SESSION['i4wuser']['Groups'])) :
        IF (in_array(38181, $arrTAGS) || in_array(38185, $arrTAGS) || in_array(38193, $arrTAGS)) :
          $bbp = bbpress();
          $bbp->current_user = new WP_User($user->ID);
    	  $new_role_forum_role=”bbp_participant”;
    	  bbp_set_user_role( $bbp->current_user, $new_role_forum_role );
        ELSEIF (in_array(38177, $arrTAGS) || in_array(38195, $arrTAGS) || in_array(38183, $arrTAGS) || in_array(38187, $arrTAGS) || in_array(38189, $arrTAGS)) :
          $bbp = bbpress();
          $bbp->current_user = new WP_User($user->ID);
    	  $new_role_forum_role=”bbp_spectator”;
    	  bbp_set_user_role( $bbp->current_user, $new_role_forum_role );
        ENDIF;
      ENDIF;
    }
    add_action('i4w_authenticated_remote_login', 'i4w_authenticated_remote_login_action', 10, 2);
    

    However, nothing happens. I am not sure what I am missing here, but I suspect it is my lack of understanding with bbPress that is the issue.

Viewing 1 replies (of 1 total)

  • davellan
    Participant

    @davellan

    Stackoverflow came to the rescue, and I have this question to thank for it.

    If you read all the comments, it gets to the solution, which in my case was this code.

    function i4w_authenticated_remote_login_action($user, $contact) {
      global $SESSION;
      IF ($arrTAGS = explode(',', $SESSION['i4wuser']['Groups'])) :
        IF (in_array(38181, $arrTAGS) || in_array(38185, $arrTAGS) || in_array(38193, $arrTAGS)) :
          $user_id = get_current_user_id();      
          $new_role_forum_role="bbp_participant";
          bbp_set_user_role( $user_id, $new_role_forum_role );
          $wp_user_capabilities_arr = array("subscriber" => true, "bbp_participant" => true, "bbp_spectator" => false);
          update_user_meta($user_id, "wp_capabilities", $wp_user_capabilities_arr);
        ELSEIF (in_array(38177, $arrTAGS) || in_array(38195, $arrTAGS) || in_array(38183, $arrTAGS) || in_array(38187, $arrTAGS) || in_array(38189, $arrTAGS)) :
          $user_id = get_current_user_id();      
          $new_role_forum_role=”bbp_spectator”;
          bbp_set_user_role( $user_id, $new_role_forum_role );
          $wp_user_capabilities_arr = array("subscriber" => true, "bbp_spectator" => false);
          update_user_meta($user_id, "wp_capabilities", $wp_user_capabilities_arr);
        ENDIF;
      ENDIF;
    }
    add_filter('i4w_authenticated_remote_login', 'i4w_authenticated_remote_login_action', 1, 2);

    I am a bit confused as to why I needed to use the update_user_meta to remove the additional capabilities (or why I would have had additional capabilities generated from the bbp_set_user_role function). If someone could answer that it would be greatly appreciated, as I am sure this code is not 100% efficient.

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.
Skip to toolbar