Skip to:
Content
Pages
Categories
Search
Top
Bottom

Codex topic fails in Buddypress 5?


  • markbildner
    Participant

    @markbildner

    How to Add Members to a Group via WP Users Screen

    This does not seem to work in buddypress (I’m on 5.5). Can anyone spot the problem? It’s a REALLY important feature because adding users to groups from the Groups screen is super-slow if you have to do a lot of names.

    My guess is that the group_id is not making it back from the popup, but I’m not smart enough to know if that’s true or how to fix it.

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

  • markbildner
    Participant

    @markbildner

    Sorry I meant buddypress 6.2, WordPress 5.5 Not sure how I fix this post.


    shanebp
    Moderator

    @shanebp

    Please check your php error log.
    And open your browser’s inspection tool and check the console for javascript errors.
    Then post the error(s) here.


    markbildner
    Participant

    @markbildner

    Thanks for your offer of help! I am not seeing php errors. As for the javascript, it pops up the box and I submit. But then the page reloads but no action occurs. I put some logging into the code (see below) It looks to me like $_REQUEST is not set and so the loop never executes at all. This returns false false false

    function console_log($data){
      echo '<script>';
      echo 'console.log('. json_encode( $data ) .')';
      echo '</script>';
    }
    
    function add_users_to_bpgroup() {   
        if( bp_is_active('groups') ):
                  console_log(isset( $_REQUEST['action'] ));
                  console_log(isset( $_REQUEST['bp_gid'] ));
                  console_log(isset( $_REQUEST['allusers'] ));
            if( isset( $_REQUEST['action'] ) && isset( $_REQUEST['bp_gid'] ) && isset( $_REQUEST['allusers'] ) ) {
                $group_id = $_REQUEST['bp_gid'];
                $users = $_REQUEST['allusers'];
    
                foreach ( $users as $user_id ) {
                    groups_join_group( $group_id, $user_id );
                }
            }
            //form submission
            add_action( 'admin_footer', function() { ?>
                <script type="text/javascript" charset="utf-8">
                    jQuery("select[name='action']").append(jQuery('<option value="groupadd">Add to BP Group</option>'));
                    jQuery("#doaction").click(function(e){
                        if(jQuery("select[name='action'] :selected").val()=="groupadd") { e.preventDefault();
                            gid=prompt("Enter a Group ID","1");
                            jQuery(".wrap form").append('<input type="hidden" name="bp_gid" value="'+gid+'" />').submit();
                        }
                    });
                </script>
            <?php
            });
             
        endif;
    }

    markbildner
    Participant

    @markbildner

    If it helps, I did a clean wordpress installation (5.5), with the twentytwenty theme, and the only two plugins were Loginizer and Buddypress. PHP is 7.4

    I still got the same result. It ran, didn’t create any errors, but it didn’t join the user to the group.

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