英国石油新能源公司阿贾克斯联合石油集团()

通过POST请求点击“加入/离开”按钮加入或离开一个组。

描述

返回

(字符串)超文本标记语言

文件:bp模板/bp nouveau/includes/groups/ajax.php

函数bp_nouveau_ajax_joinleave_group(){$ response = array('反馈'=> sprintf('  

%s ',ESC_HTML __('执行此操作有问题。请再试一次。','Buddyboss')),);//保释如果不是邮政行动。if(!bp_is_post_request()||空($ _post [action']))){wp_send_json_error($响应);}如果(空($ _post ['nonce'])||空($ _post ['item_id'])||!bp_is_active('组')){wp_send_json_error($响应);} //使用默认值nonce $ nonce = $ _post ['nonce'];$ check ='bp_nouveau_groups';//如果(!空($ _post ['_ wpnonce']))&&!空($ _post ['操作'])))){$ nonce = $ _post ['_ wpnonce'];$ check = $ _post ['action'];} //随机检查!if(空($ nonce)||!wp_verify_nonce($ nonce,$ check)){wp_send_json_error($响应); } // Cast gid as integer. $group_id = (int) $_POST['item_id']; $errors = array( 'cannot' => sprintf( '

%s

', esc_html__( 'You cannot join this group.', 'buddyboss' ) ), 'member' => sprintf( '

%s

', esc_html__( 'You are already a member of the group.', 'buddyboss' ) ), ); if ( groups_is_user_banned( bp_loggedin_user_id(), $group_id ) ) { $response['feedback'] = $errors['cannot']; wp_send_json_error( $response ); } // Validate and get the group $group = groups_get_group( array( 'group_id' => $group_id ) ); if ( empty( $group->id ) ) { wp_send_json_error( $response ); } // Manage all button's possible actions here. switch ( $_POST['action'] ) { case 'groups_accept_invite': if ( ! groups_accept_invite( bp_loggedin_user_id(), $group_id ) ) { $response = array( 'feedback' => sprintf( '

%s

', esc_html__( 'Group invitation could not be accepted.', 'buddyboss' ) ), 'type' => 'error', ); } else { if ( bp_is_active( 'activity' ) ) { groups_record_activity( array( 'type' => 'joined_group', 'item_id' => $group->id, ) ); } // User is now a member of the group $group->is_member = '1'; $response = array( 'feedback' => sprintf( '

%s

', esc_html__( 'Group invite accepted.', 'buddyboss' ) ), 'type' => 'success', 'is_user' => bp_is_user(), 'contents' => bp_get_group_join_button( $group ), 'is_group' => bp_is_group(), ); } break; case 'groups_reject_invite': if ( ! groups_reject_invite( bp_loggedin_user_id(), $group_id ) ) { $response = array( 'feedback' => sprintf( '

%s

', esc_html__( 'Group invite could not be rejected', 'buddyboss' ) ), 'type' => 'error', ); } else { $response = array( 'feedback' => sprintf( '

%s

', esc_html__( 'Group invite rejected', 'buddyboss' ) ), 'type' => 'success', 'is_user' => bp_is_user(), ); } break; case 'groups_join_group': if ( groups_is_user_member( bp_loggedin_user_id(), $group->id ) ) { $response = array( 'feedback' => $errors['member'], 'type' => 'error', ); } elseif ( 'public' !== $group->status ) { $response = array( 'feedback' => $errors['cannot'], 'type' => 'error', ); } elseif ( ! groups_join_group( $group->id ) ) { $response = array( 'feedback' => sprintf( '

%s

', esc_html__( 'Error joining this group.', 'buddyboss' ) ), 'type' => 'error', ); } else { // User is now a member of the group $group->is_member = '1'; $response = array( 'contents' => bp_get_group_join_button( $group ), 'is_group' => bp_is_group(), 'type' => 'success', ); } break; case 'groups_request_membership' : if ( ! groups_send_membership_request( bp_loggedin_user_id(), $group->id ) ) { $response = array( 'feedback' => sprintf( '

%s

', esc_html__( 'Error requesting membership.', 'buddyboss' ) ), 'type' => 'error', ); } else { // Request is pending $group->is_pending = '1'; $response = array( 'contents' => bp_get_group_join_button( $group ), 'is_group' => bp_is_group(), 'type' => 'success', ); } break; case 'groups_leave_group' : if ( ! groups_leave_group( $group->id ) ) { $response = array( 'feedback' => sprintf( '

%s

', esc_html__( 'Error leaving group.', 'buddyboss' ) ), 'type' => 'error', ); } else { // User is no more a member of the group $group->is_member = '0'; $bp = buddypress(); /** * When inside the group or in the loggedin user's group memberships screen * we need to reload the page. */ $bp_is_group = bp_is_group() || ( bp_is_user_groups() && bp_is_my_profile() ); $response = array( 'contents' => bp_get_group_join_button( $group ), 'is_group' => $bp_is_group, 'type' => 'success', ); // Reset the message if not in a Group or in a loggedin user's group memberships one! if ( ! $bp_is_group && isset( $bp->template_message ) && isset( $bp->template_message_type ) ) { unset( $bp->template_message, $bp->template_message_type ); @setcookie( 'bp-message', false, time() - 1000, COOKIEPATH, COOKIE_DOMAIN, is_ssl() ); @setcookie( 'bp-message-type', false, time() - 1000, COOKIEPATH, COOKIE_DOMAIN, is_ssl() ); } } break; } if ( 'error' === $response['type'] ) { wp_send_json_error( $response ); } wp_send_json_success( $response ); }

变更日志

变更日志
版本 描述
BuddyPress 3.0.0 介绍了。

问题?

我们随时乐意为您提供代码或其他问题的帮助!搜索我们的开发者文档,联络支持,或与我们联系销售团队.