Skip to:
Content
Pages
Categories
Search
Top
Bottom

Join group ajax not working


  • fullmetalworkshop
    Participant

    @fullmetalworkshop

    I’m getting an admin-ajax 403 error when clicking the Join Group button. It seems to be the switch case in the functions. It seems to be completely ignored somehow. Logging within any of the cases returns nothing at all. Also a quick note… it’s not every group. It’s only on random ones

    function bp_legacy_theme_ajax_joinleave_group() {
    
    	if ( ! bp_is_post_request() ) {
    		return;
    	}
    
    	// Cast gid as integer.
    	$group_id = (int) $_POST['gid'];
    
    	if ( groups_is_user_banned( bp_loggedin_user_id(), $group_id ) )
    		return;
    
    	if ( ! $group = groups_get_group( $group_id ) )
    		return;
    
    	// Client doesn't distinguish between different request types, so we infer from user status.
    	if ( groups_is_user_member( bp_loggedin_user_id(), $group->id ) ) {
    		$request_type = 'leave_group';
    	} elseif ( groups_check_user_has_invite( bp_loggedin_user_id(), $group->id ) ) {
    		$request_type = 'accept_invite';
    	} elseif ( 'private' === $group->status ) {
    		$request_type = 'request_membership';
    	} else {
    		$request_type = 'join_group';
    	}
    
    	// NOTE: WHY IS THIS BROKEN?!!?
    	switch ( $request_type ) {
    		case 'join_group' :
    			if ( ! bp_current_user_can( 'groups_join_group', array( 'group_id' => $group->id ) ) ) {
    				esc_html_e( 'Error joining group', 'buddypress' );
    			}
    
    			check_ajax_referer( 'groups_join_group' );
    
    			if ( ! groups_join_group( $group->id ) ) {
    				_e( 'Error joining group', 'buddypress' );
    			} else {
    				echo '<a id="group-' . esc_attr( $group->id ) . '" class="group-button leave-group" rel="leave" href="' . wp_nonce_url( bp_get_group_permalink( $group ) . 'leave-group', 'groups_leave_group' ) . '">' . __( 'Leave Group', 'buddypress' ) . '</a>';
    			}
    		break;
    
    		case 'accept_invite' :
    			if ( ! bp_current_user_can( 'groups_request_membership', array( 'group_id' => $group->id ) ) ) {
    				esc_html_e( 'Error accepting invitation', 'buddypress' );
    			}
    
    			check_ajax_referer( 'groups_accept_invite' );
    			if ( ! groups_accept_invite( bp_loggedin_user_id(), $group->id ) ) {
    				_e( 'Error requesting membership', 'buddypress' );
    			} else {
    				echo '<a id="group-' . esc_attr( $group->id ) . '" class="group-button leave-group" rel="leave" href="' . wp_nonce_url( bp_get_group_permalink( $group ) . 'leave-group', 'groups_leave_group' ) . '">' . __( 'Leave Group', 'buddypress' ) . '</a>';
    			}
    		break;
    
    		case 'request_membership' :
    			check_ajax_referer( 'groups_request_membership' );
    
    			if ( ! groups_send_membership_request( [ 'user_id' => bp_loggedin_user_id(), 'group_id' => $group->id ] ) ) {
    				_e( 'Error requesting membership', 'buddypress' );
    			} else {
    				echo '<a id="group-' . esc_attr( $group->id ) . '" class="group-button disabled pending membership-requested" rel="membership-requested" href="' . bp_get_group_permalink( $group ) . '">' . __( 'Request Sent', 'buddypress' ) . '</a>';
    			}
    		break;
    
    		case 'leave_group' :
    			check_ajax_referer( 'groups_leave_group' );
    
    			if ( ! groups_leave_group( $group->id ) ) {
    				_e( 'Error leaving group', 'buddypress' );
    			} elseif ( 'public' === $group->status ) {
    				echo '<a id="group-' . esc_attr( $group->id ) . '" class="group-button join-group btn" rel="join" href="' . wp_nonce_url( bp_get_group_permalink( $group ) . 'join', 'groups_join_group' ) . '">' . __( 'Join Group', 'buddypress' ) . '</a>';
    			} else {
    				echo '<a id="group-' . esc_attr( $group->id ) . '" class="group-button request-membership" rel="join" href="' . wp_nonce_url( bp_get_group_permalink( $group ) . 'request-membership', 'groups_request_membership' ) . '">' . __( 'Request Membership', 'buddypress' ) . '</a>';
    			}
    		break;
    	}
    
    	exit;
    }
Viewing 5 replies - 1 through 5 (of 5 total)

  • shanebp
    Moderator

    @shanebp

    For reference – try switching to the Nouveau template pack and see if the issue persists.


    fullmetalworkshop
    Participant

    @fullmetalworkshop

    Thanks for your response!

    Is there any way to debug it once I’ve done this? There’s a lot of code that’s reliant on the legacy theme so it’ll take some time to switch it and getting it to a properly functional state.


    fullmetalworkshop
    Participant

    @fullmetalworkshop

    Thanks for your response!

    Is there any way to debug it once I’ve done this? There’s a lot of code that’s reliant on the legacy theme so it’ll take some time to switch it and getting it to a properly functional state.

    EDIT: I was able to switch it and the join buttons work but not with AJAX. It would be fine if I could remove AJAX. Is that possible to remove AJAX for only one element or does it need to be all or none?


    shanebp
    Moderator

    @shanebp

    Turn on debugging and post the relevant errors – they might be javascript errors so check your browser inspector console.


    fullmetalworkshop
    Participant

    @fullmetalworkshop

    Thanks, I know it sounds crazy but there are literally no other errors in the debug. only the error in the console: Failed to load resource: the server responded with a status of 403 () and /wp-admin/admin-ajax.php:1 which only outputs “0”

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