Changeset 9939
- Timestamp:
- 06/11/2015 11:06:22 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-groups/bp-groups-template.php
r9938 r9939 4799 4799 } 4800 4800 4801 function bp_new_group_invite_friend_list() { 4802 echo bp_get_new_group_invite_friend_list(); 4803 } 4804 function bp_get_new_group_invite_friend_list( $args = '' ) { 4805 $bp = buddypress(); 4806 4807 if ( !bp_is_active( 'friends' ) ) { 4801 /** 4802 * Output a list of friends who can be invited to a group 4803 * 4804 * @since BuddyPress (1.0.0) 4805 */ 4806 function bp_new_group_invite_friend_list( $args = array() ) { 4807 echo bp_get_new_group_invite_friend_list( $args ); 4808 } 4809 /** 4810 * Return a list of friends who can be invited to a group 4811 * 4812 * @since BuddyPress (1.0.0) 4813 * 4814 * @param array $args 4815 * @return mixed HTML list of checkboxes, or false 4816 */ 4817 function bp_get_new_group_invite_friend_list( $args = array() ) { 4818 4819 // Bail if no friends component 4820 if ( ! bp_is_active( 'friends' ) ) { 4808 4821 return false; 4809 4822 } 4810 4823 4811 $defaults = array( 4824 // Parse arguments 4825 $r = wp_parse_args( $args, array( 4826 'user_id' => bp_loggedin_user_id(), 4812 4827 'group_id' => false, 4813 4828 'separator' => 'li' 4814 ); 4815 4816 $r = wp_parse_args( $args, $defaults ); 4817 extract( $r, EXTR_SKIP ); 4818 4819 if ( empty( $group_id ) ) { 4820 $group_id = !empty( $bp->groups->new_group_id ) ? $bp->groups->new_group_id : $bp->groups->current_group->id; 4821 } 4822 4823 if ( $friends = friends_get_friends_invite_list( bp_loggedin_user_id(), $group_id ) ) { 4824 $invites = groups_get_invites_for_group( bp_loggedin_user_id(), $group_id ); 4829 ) ); 4830 4831 // No group passed, so look for new or current group ID's 4832 if ( empty( $r['group_id'] ) ) { 4833 $bp = buddypress(); 4834 $r['group_id'] = ! empty( $bp->groups->new_group_id ) 4835 ? $bp->groups->new_group_id 4836 : $bp->groups->current_group->id; 4837 } 4838 4839 // Setup empty items array 4840 $items = array(); 4841 4842 // Get user's friends who are not in this group already 4843 $friends = friends_get_friends_invite_list( $r['user_id'], $r['group_id'] ); 4844 4845 if ( ! empty( $friends ) ) { 4846 4847 // Get already invited users 4848 $invites = groups_get_invites_for_group( $r['user_id'], $r['group_id'] ); 4825 4849 4826 4850 for ( $i = 0, $count = count( $friends ); $i < $count; ++$i ) { 4827 $checked = ''; 4828 4829 if ( !empty( $invites ) ) { 4830 if ( in_array( $friends[$i]['id'], $invites ) ) { 4831 $checked = ' checked="checked"'; 4832 } 4833 } 4834 4835 $items[] = '<' . $separator . '><input' . $checked . ' type="checkbox" name="friends[]" id="f-' . $friends[$i]['id'] . '" value="' . esc_attr( $friends[$i]['id'] ) . '" /> ' . $friends[$i]['full_name'] . '</' . $separator . '>'; 4851 $checked = in_array( (int) $friends[ $i ]['id'], (array) $invites ); 4852 $items[] = '<' . $r['separator'] . '><input' . checked( $checked ) . ' type="checkbox" name="friends[]" id="f-' . esc_attr( $friends[ $i ]['id'] ) . '" value="' . esc_attr( $friends[ $i ]['id'] ) . '" /> ' . esc_html( $friends[ $i ]['full_name'] ) . '</' . $r['separator'] . '>'; 4836 4853 } 4837 4854 } 4838 4855 4839 if ( !empty( $items ) ) { 4840 return implode( "\n", (array) $items ); 4841 } 4842 4843 return false; 4856 /** 4857 * Filters the array of friends who can be invited to a group. 4858 * 4859 * @since BuddyPress (1.0.0) 4860 * 4861 * @param array $items Array of friends. 4862 */ 4863 $invitable_friends = apply_filters( 'bp_get_new_group_invite_friend_list', $items, $r, $args ); 4864 4865 if ( ! empty( $invitable_friends ) && is_array( $invitable_friends ) ) { 4866 $retval = implode( "\n", $invitable_friends ); 4867 } else { 4868 $retval = false; 4869 } 4870 4871 return $retval; 4844 4872 } 4845 4873
Note: See TracChangeset
for help on using the changeset viewer.