Changeset 7442
- Timestamp:
- 10/17/2013 07:00:46 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-groups/bp-groups-classes.php
r7441 r7442 32 32 */ 33 33 public $is_member; 34 35 /** 36 * Does the current user have an outstanding invitation to this group? 37 * 38 * @since BuddyPress (1.9.0) 39 * @var bool 40 */ 41 public $is_invited; 42 43 /** 44 * Does the current user have a pending membership request to this group? 45 * 46 * @since BuddyPress (1.9.0) 47 * @var bool 48 */ 49 public $is_pending; 34 50 35 51 /** … … 73 89 $this->total_member_count = groups_get_groupmeta( $this->id, 'total_member_count' ); 74 90 $this->is_member = BP_Groups_Member::check_is_member( bp_loggedin_user_id(), $this->id ); 91 $this->is_invited = BP_Groups_Member::check_has_invite( bp_loggedin_user_id(), $this->id ); 92 $this->is_pending = BP_Groups_Member::check_for_membership_request( bp_loggedin_user_id(), $this->id ); 75 93 76 94 // If this is a private or hidden group, does the current user have access? … … 828 846 $group_ids = implode( ',', wp_parse_id_list( $group_ids ) ); 829 847 830 // Fetch the logged in users status within each group 831 $user_status = $wpdb->get_col( $wpdb->prepare( "SELECT group_id FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id IN ( {$group_ids} ) AND is_confirmed = 1 AND is_banned = 0", bp_loggedin_user_id() ) ); 848 // Fetch the logged-in user's status within each group 849 $user_status = $wpdb->get_results( $wpdb->prepare( "SELECT group_id, is_confirmed, invite_sent FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id IN ( {$group_ids} ) AND is_banned = 0", bp_loggedin_user_id() ) ); 850 832 851 for ( $i = 0, $count = count( $paged_groups ); $i < $count; ++$i ) { 833 852 $paged_groups[$i]->is_member = false; 834 853 835 foreach ( (array) $user_status as $group_id ) { 836 if ( $group_id == $paged_groups[$i]->id ) { 837 $paged_groups[$i]->is_member = true; 854 foreach ( (array) $user_status as $group ) { 855 $is_member = $is_invited = $is_pending = false; 856 if ( $group->group_id == $paged_groups[ $i ]->id ) { 857 // is_confirmed means the user is a member 858 if ( $group->is_confirmed ) { 859 $is_member = true; 860 861 // invite_sent means the user has been invited 862 } else if ( $group->invite_sent ) { 863 $is_invited = true; 864 865 // User has sent request, but has not been confirmed 866 } else { 867 $is_pending = true; 868 } 838 869 } 870 871 $paged_groups[ $i ]->is_member = $is_member; 872 $paged_groups[ $i ]->is_invited = $is_invited; 873 $paged_groups[ $i ]->is_pending = $is_pending; 839 874 } 840 875 } -
trunk/bp-groups/bp-groups-functions.php
r7338 r7442 655 655 return false; 656 656 657 if ( !groups_is_user_member( $user_id, $group_id ) && !groups_check_user_has_invite( $user_id, $group_id, 'all' ) ) { 657 // if the user has already requested membership, accept the request 658 if ( $membership_id = groups_check_for_membership_request( $user_id, $group_id ) ) { 659 groups_accept_membership_request( $membership_id, $user_id, $group_id ); 660 661 // Otherwise, create a new invitation 662 } else if ( ! groups_is_user_member( $user_id, $group_id ) && ! groups_check_user_has_invite( $user_id, $group_id, 'all' ) ) { 658 663 $invite = new BP_Groups_Member; 659 664 $invite->group_id = $group_id; … … 872 877 if ( groups_is_user_member( $requesting_user_id, $group_id ) || groups_is_user_banned( $requesting_user_id, $group_id ) ) 873 878 return false; 879 880 // Check if the user is already invited - if so, simply accept invite 881 if ( groups_check_user_has_invite( $requesting_user_id, $group_id ) ) { 882 groups_accept_invite( $requesting_user_id, $group_id ); 883 return true; 884 } 874 885 875 886 $requesting_user = new BP_Groups_Member; -
trunk/bp-groups/bp-groups-loader.php
r7347 r7442 413 413 ); 414 414 415 // If this is a private group, and the user is not a member, show a "Request Membership" nav item. 415 // If this is a private group, and the user is not a 416 // member and does not have an outstanding invitation, 417 // show a "Request Membership" nav item. 416 418 if ( is_user_logged_in() && 417 !bp_current_user_can( 'bp_moderate' ) && 418 !$this->current_group->is_user_member && 419 !groups_check_for_membership_request( bp_loggedin_user_id(), $this->current_group->id ) && 420 $this->current_group->status == 'private' 419 ! bp_current_user_can( 'bp_moderate' ) && 420 ! $this->current_group->is_user_member && 421 ! groups_check_for_membership_request( bp_loggedin_user_id(), $this->current_group->id ) && 422 $this->current_group->status == 'private' && 423 ! groups_check_user_has_invite( bp_loggedin_user_id(), $this->current_group->id ) 421 424 ) { 425 422 426 $sub_nav[] = array( 423 427 'name' => __( 'Request Membership', 'buddypress' ), -
trunk/bp-groups/bp-groups-screens.php
r7440 r7442 479 479 if ( 'private' != $bp->groups->current_group->status ) 480 480 return false; 481 482 // If the user is already invited, accept invitation 483 if ( groups_check_user_has_invite( bp_loggedin_user_id(), $bp->groups->current_group->id ) ) { 484 if ( groups_accept_invite( bp_loggedin_user_id(), $bp->groups->current_group->id ) ) 485 bp_core_add_message( __( 'Group invite accepted', 'buddypress' ) ); 486 else 487 bp_core_add_message( __( 'There was an error accepting the group invitation, please try again.', 'buddypress' ), 'error' ); 488 bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) ); 489 } 481 490 482 491 // If the user has submitted a request, send it. -
trunk/bp-groups/bp-groups-template.php
r7439 r7442 1781 1781 case 'private' : 1782 1782 1783 // Member has not requested membership yet 1784 if ( !bp_group_has_requested_membership( $group ) ) { 1783 // Member has outstanding invitation - 1784 // show an "Accept Invitation" button 1785 if ( $group->is_invited ) { 1786 $button = array( 1787 'id' => 'accept_invite', 1788 'component' => 'groups', 1789 'must_be_logged_in' => true, 1790 'block_self' => false, 1791 'wrapper_class' => 'group-button ' . $group->status, 1792 'wrapper_id' => 'groupbutton-' . $group->id, 1793 'link_href' => add_query_arg( 'redirect_to', bp_get_group_permalink( $group ), bp_get_group_accept_invite_link( $group ) ), 1794 'link_text' => __( 'Accept Invitation', 'buddypress' ), 1795 'link_title' => __( 'Accept Invitation', 'buddypress' ), 1796 'link_class' => 'group-button accept-invite', 1797 ); 1798 1799 // Member has requested membership but request is pending - 1800 // show a "Request Sent" button 1801 } elseif ( $group->is_pending ) { 1802 $button = array( 1803 'id' => 'membership_requested', 1804 'component' => 'groups', 1805 'must_be_logged_in' => true, 1806 'block_self' => false, 1807 'wrapper_class' => 'group-button pending ' . $group->status, 1808 'wrapper_id' => 'groupbutton-' . $group->id, 1809 'link_href' => bp_get_group_permalink( $group ), 1810 'link_text' => __( 'Request Sent', 'buddypress' ), 1811 'link_title' => __( 'Request Sent', 'buddypress' ), 1812 'link_class' => 'group-button pending membership-requested', 1813 ); 1814 1815 // Member has not requested membership yet - 1816 // show a "Request Membership" button 1817 } else { 1785 1818 $button = array( 1786 1819 'id' => 'request_membership', … … 1794 1827 'link_title' => __( 'Request Membership', 'buddypress' ), 1795 1828 'link_class' => 'group-button request-membership', 1796 );1797 1798 // Member has requested membership already1799 } else {1800 $button = array(1801 'id' => 'membership_requested',1802 'component' => 'groups',1803 'must_be_logged_in' => true,1804 'block_self' => false,1805 'wrapper_class' => 'group-button pending ' . $group->status,1806 'wrapper_id' => 'groupbutton-' . $group->id,1807 'link_href' => bp_get_group_permalink( $group ),1808 'link_text' => __( 'Request Sent', 'buddypress' ),1809 'link_title' => __( 'Request Sent', 'buddypress' ),1810 'link_class' => 'group-button pending membership-requested',1811 1829 ); 1812 1830 } -
trunk/bp-templates/bp-legacy/buddypress-functions.php
r7430 r7442 907 907 return; 908 908 909 $group_id = (int) $_POST['group_id']; 910 $friend_id = (int) $_POST['friend_id']; 911 909 912 if ( 'invite' == $_POST['friend_action'] ) { 910 if ( ! groups_invite_user( array( 'user_id' => $_POST['friend_id'], 'group_id' => $_POST['group_id'] ) ) ) 913 $group = groups_get_group( $group_id ); 914 915 // Users who have previously requested membership do not need 916 // another invitation created for them 917 if ( BP_Groups_Member::check_for_membership_request( $friend_id, $group_id ) ) { 918 $user_status = 'is_pending'; 919 920 // Create the user invitation 921 } else if ( groups_invite_user( array( 'user_id' => $friend_id, 'group_id' => $group_id ) ) ) { 922 $user_status = 'is_invited'; 923 924 // Miscellaneous failure 925 } else { 911 926 return; 912 913 $user = new BP_Core_User( $_POST['friend_id'] ); 927 } 928 929 $user = new BP_Core_User( $friend_id ); 914 930 915 931 echo '<li id="uid-' . $user->id . '">'; … … 920 936 <a class="button remove" href="' . wp_nonce_url( bp_loggedin_user_domain() . bp_get_groups_slug() . '/' . $_POST['group_id'] . '/invites/remove/' . $user->id, 'groups_invite_uninvite_user' ) . '" id="uid-' . esc_attr( $user->id ) . '">' . __( 'Remove Invite', 'buddypress' ) . '</a> 921 937 </div>'; 938 939 if ( 'is_pending' == $user_status ) { 940 echo '<p class="description">' . sprintf( __( '%s has previously requested to join this group. Sending an invitation will automatically add the member to the group.', 'buddypress' ), $user->user_link ) . '</p>'; 941 } 942 922 943 echo '</li>'; 923 944 exit; 924 945 925 946 } elseif ( 'uninvite' == $_POST['friend_action'] ) { 926 if ( ! groups_uninvite_user( $_POST['friend_id'], $_POST['group_id'] ) ) 947 // Users who have previously requested membership should not 948 // have their requests deleted on the "uninvite" action 949 if ( BP_Groups_Member::check_for_membership_request( $friend_id, $group_id ) ) { 927 950 return; 951 } 952 953 // Remove the unsent invitation 954 if ( ! groups_uninvite_user( $friend_id, $group_id ) ) { 955 return; 956 } 928 957 929 958 exit; … … 1056 1085 1057 1086 } elseif ( 'private' == $group->status ) { 1058 check_ajax_referer( 'groups_request_membership' ); 1059 1060 if ( ! groups_send_membership_request( bp_loggedin_user_id(), $group->id ) ) { 1061 _e( 'Error requesting membership', 'buddypress' ); 1087 1088 // If the user has already been invited, then this is 1089 // an Accept Invitation button 1090 if ( groups_check_user_has_invite( bp_loggedin_user_id(), $group->id ) ) { 1091 check_ajax_referer( 'groups_accept_invite' ); 1092 1093 if ( ! groups_accept_invite( bp_loggedin_user_id(), $group->id ) ) { 1094 _e( 'Error requesting membership', 'buddypress' ); 1095 } else { 1096 echo '<a id="group-' . esc_attr( $group->id ) . '" class="leave-group" rel="leave" title="' . __( 'Leave Group', 'buddypress' ) . '" href="' . wp_nonce_url( bp_get_group_permalink( $group ) . 'leave-group', 'groups_leave_group' ) . '">' . __( 'Leave Group', 'buddypress' ) . '</a>'; 1097 } 1098 1099 // Otherwise, it's a Request Membership button 1062 1100 } else { 1063 echo '<a id="group-' . esc_attr( $group->id ) . '" class="membership-requested" rel="membership-requested" title="' . __( 'Membership Requested', 'buddypress' ) . '" href="' . bp_get_group_permalink( $group ) . '">' . __( 'Membership Requested', 'buddypress' ) . '</a>'; 1101 check_ajax_referer( 'groups_request_membership' ); 1102 1103 if ( ! groups_send_membership_request( bp_loggedin_user_id(), $group->id ) ) { 1104 _e( 'Error requesting membership', 'buddypress' ); 1105 } else { 1106 echo '<a id="group-' . esc_attr( $group->id ) . '" class="membership-requested" rel="membership-requested" title="' . __( 'Membership Requested', 'buddypress' ) . '" href="' . bp_get_group_permalink( $group ) . '">' . __( 'Membership Requested', 'buddypress' ) . '</a>'; 1107 } 1064 1108 } 1065 1109 } -
trunk/bp-themes/bp-default/_inc/ajax.php
r7228 r7442 569 569 return; 570 570 571 $group_id = (int) $_POST['group_id']; 572 $friend_id = (int) $_POST['friend_id']; 573 571 574 if ( 'invite' == $_POST['friend_action'] ) { 572 if ( ! groups_invite_user( array( 'user_id' => $_POST['friend_id'], 'group_id' => $_POST['group_id'] ) ) ) 575 $group = groups_get_group( $group_id ); 576 577 // Users who have previously requested membership do not need 578 // another invitation created for them 579 if ( BP_Groups_Member::check_for_membership_request( $friend_id, $group_id ) ) { 580 $user_status = 'is_pending'; 581 582 // Create the user invitation 583 } else if ( groups_invite_user( array( 'user_id' => $friend_id, 'group_id' => $group_id ) ) ) { 584 $user_status = 'is_invited'; 585 586 // Miscellaneous failure 587 } else { 573 588 return; 589 } 574 590 575 591 $user = new BP_Core_User( $_POST['friend_id'] ); … … 582 598 <a class="button remove" href="' . wp_nonce_url( bp_loggedin_user_domain() . bp_get_groups_slug() . '/' . $_POST['group_id'] . '/invites/remove/' . $user->id, 'groups_invite_uninvite_user' ) . '" id="uid-' . esc_attr( $user->id ) . '">' . __( 'Remove Invite', 'buddypress' ) . '</a> 583 599 </div>'; 600 601 if ( 'is_pending' == $user_status ) { 602 echo '<p class="description">' . sprintf( __( '%s has previously requested to join this group. Sending an invitation will automatically add the member to the group.', 'buddypress' ), $user->user_link ) . '</p>'; 603 } 604 584 605 echo '</li>'; 585 606 exit; 586 607 587 608 } elseif ( 'uninvite' == $_POST['friend_action'] ) { 588 if ( ! groups_uninvite_user( $_POST['friend_id'], $_POST['group_id'] ) ) 609 // Users who have previously requested membership should not 610 // have their requests deleted on the "uninvite" action 611 if ( BP_Groups_Member::check_for_membership_request( $friend_id, $group_id ) ) { 589 612 return; 613 } 614 615 // Remove the unsent invitation 616 if ( ! groups_uninvite_user( $friend_id, $group_id ) ) { 617 return; 618 } 590 619 591 620 exit; … … 717 746 718 747 } elseif ( 'private' == $group->status ) { 719 check_ajax_referer( 'groups_request_membership' ); 720 721 if ( ! groups_send_membership_request( bp_loggedin_user_id(), $group->id ) ) { 722 _e( 'Error requesting membership', 'buddypress' ); 748 749 // If the user has already been invited, then this is 750 // an Accept Invitation button 751 if ( groups_check_user_has_invite( bp_loggedin_user_id(), $group->id ) ) { 752 check_ajax_referer( 'groups_accept_invite' ); 753 754 if ( ! groups_accept_invite( bp_loggedin_user_id(), $group->id ) ) { 755 _e( 'Error requesting membership', 'buddypress' ); 756 } else { 757 echo '<a id="group-' . esc_attr( $group->id ) . '" class="leave-group" rel="leave" title="' . __( 'Leave Group', 'buddypress' ) . '" href="' . wp_nonce_url( bp_get_group_permalink( $group ) . 'leave-group', 'groups_leave_group' ) . '">' . __( 'Leave Group', 'buddypress' ) . '</a>'; 758 } 759 760 // Otherwise, it's a Request Membership button 723 761 } else { 724 echo '<a id="group-' . esc_attr( $group->id ) . '" class="membership-requested" rel="membership-requested" title="' . __( 'Membership Requested', 'buddypress' ) . '" href="' . bp_get_group_permalink( $group ) . '">' . __( 'Membership Requested', 'buddypress' ) . '</a>'; 762 check_ajax_referer( 'groups_request_membership' ); 763 764 if ( ! groups_send_membership_request( bp_loggedin_user_id(), $group->id ) ) { 765 _e( 'Error requesting membership', 'buddypress' ); 766 } else { 767 echo '<a id="group-' . esc_attr( $group->id ) . '" class="membership-requested" rel="membership-requested" title="' . __( 'Membership Requested', 'buddypress' ) . '" href="' . bp_get_group_permalink( $group ) . '">' . __( 'Membership Requested', 'buddypress' ) . '</a>'; 768 } 725 769 } 726 770 }
Note: See TracChangeset
for help on using the changeset viewer.