Skip to:
Content
Pages
Categories
Search
Top
Bottom

bbp_set_user_role doesn’t change role


  • marcosmodop
    Participant

    @marcosmodop

    WP version: 5.8.3
    bbpress version: 2.6.9
    site is in a local environment at the moment.

    I’m trying to update the role for the users once they enroll in course. I manage to found an entry point for this with “learndash_update_course_access” once there is an update in the user courses list. This part works. What is giving me troubles is the update of the user bbpress roles.
    This is the most raw code I try:

    add_action( 'learndash_update_course_access', 'updatebbpressrole', 20, 4 );
    function updatebbpressrole ($user_id, $course_id, $course_access_list, $remove) {
    	$new_role_forum_role = "bbp_blocked";
    	bbp_set_user_role( $user_id, $new_role_forum_role );
    }

    I try with a pair of custom roles I have, but it also happens with the basics bbpres roles too, so is not related to the new roles.
    Also I try with the update in the root of functions.php this works, sort of, because the update is done, but the select dropdown in the user profile in the admin page get stuck in the old one, but in code the selected one is the updated, if I get out and enter again is fixed.
    Any idea about why bbp_set_user_role is not working this way ?

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

  • Robin W
    Moderator

    @robin-w

    hmmm… that code looks fine.

    I’m not quite sure what you mean in

    Also I try with the update in the root of functions.php this works, sort of, because the update is done, but the select dropdown in the user profile in the admin page get stuck in the old one, but in code the selected one is the updated, if I get out and enter again is fixed.

    have you access to the database?


    marcosmodop
    Participant

    @marcosmodop

    What I mean with that part is: I use just bbp_set_user_role( $bbpres_user_id, “bbp_blocked” ); on a function with add_action (‘init’.
    If I use only bbp_set_user_role it seems it does change in the select tag and make the bbp_blocked the selected one but in the front page the html show to old one in the select field. If I get out of the user page and re-enter is fixed, this occur in the admin page.
    Yes I have access to the DataBase.


    Robin W
    Moderator

    @robin-w

    ok, since this is a php change, it will not reflect on the browser unless the screen is refreshed – ie the page is re-downloaded.

    I can’t say why the learndash hook isn’t working, except that it may not be the appropriate hook – there may be better ones

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