public static function EnrolledCourse($student_id, $course_id, $status) { global $wpdb; $group_id = get_post_meta($course_id, 'buddypress_id', true); // Get BuddyPress $bp = buddypress(); $group = $wpdb->get_row($wpdb->prepare("SELECT g.* FROM {$bp->groups->table_name} g WHERE g.id = %d", $group_id)); groups_invite_user(array('user_id' => $student_id, 'group_id' => $group_id, 'inviter_id' => $group->creator_id, 'date_modified' => bp_core_current_time(), 'is_confirmed' => 1)); $forums = bbp_get_group_forum_ids($group_id); bbp_add_user_forum_subscription(bbp_get_current_user_id(), $forums[0]); }
public static function addUserFromCourseToGroup($courseId, $groupId) { global $wpdb; if (get_current_user_id() != 30) { return; } $bp = buddypress(); $group = $wpdb->get_row($wpdb->prepare("SELECT g.* FROM {$bp->groups->table_name} g WHERE g.id = %d", $groupId)); $userIdList = $wpdb->get_results($wpdb->prepare("SELECT user_id FROM `wp_namaste_student_courses` WHERE course_id=%d", $courseId)); foreach ($userIdList as $userId) { groups_invite_user(array('user_id' => $userId->user_id, 'group_id' => $groupId, 'inviter_id' => $group->creator_id, 'date_modified' => bp_core_current_time(), 'is_confirmed' => 1)); $forums = bbp_get_group_forum_ids($groupId); bbp_add_user_forum_subscription($userId, $forums[0]); } }
/** * @group BP6319 */ public function test_private_group_where_logged_in_user_has_not_requested_membership_but_has_been_invited() { $users = $this->factory->user->create_many(2); $g = $this->factory->group->create(array('status' => 'private')); $this->set_current_user($users[0]); groups_invite_user(array('user_id' => $users[0], 'group_id' => $g, 'inviter_id' => $users[1])); if (bp_has_groups(array('include' => array($g)))) { while (bp_groups()) { bp_the_group(); $found = get_echo('bp_group_status_message'); } } $expected = __('This is a private group and you must request group membership in order to join.', 'buddypress'); $this->assertSame($expected, $found); }
function groups_ajax_invite_user() { global $bp; check_ajax_referer('groups_invite_uninvite_user'); if (!$_POST['friend_id'] || !$_POST['friend_action'] || !$_POST['group_id']) { return false; } if (!groups_is_user_admin($bp->loggedin_user->id, $_POST['group_id'])) { return false; } if (!friends_check_friendship($bp->loggedin_user->id, $_POST['friend_id'])) { return false; } if ('invite' == $_POST['friend_action']) { if (!groups_invite_user($_POST['friend_id'], $_POST['group_id'])) { return false; } $user = new BP_Core_User($_POST['friend_id']); echo '<li id="uid-' . $user->id . '">'; echo attribute_escape($user->avatar_thumb); echo '<h4>' . attribute_escape($user->user_link) . '</h4>'; echo '<span class="activity">' . attribute_escape($user->last_active) . '</span>'; echo '<div class="action"> <a class="remove" href="' . wp_nonce_url($bp->loggedin_user->domain . $bp->groups->slug . '/' . $_POST['group_id'] . '/invites/remove/' . $user->id, 'groups_invite_uninvite_user') . '" id="uid-' . attribute_escape($user->id) . '">' . __('Remove Invite', 'buddypress') . '</a> </div>'; echo '</li>'; } else { if ('uninvite' == $_POST['friend_action']) { if (!groups_uninvite_user($_POST['friend_id'], $_POST['group_id'])) { return false; } return true; } else { return false; } } }
/** * Invites a friend to join a group via a POST request. * * @since BuddyPress (1.2) * @todo Audit return types */ function bp_legacy_theme_ajax_invite_user() { // Bail if not a POST action if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) { return; } check_ajax_referer('groups_invite_uninvite_user'); if (!$_POST['friend_id'] || !$_POST['friend_action'] || !$_POST['group_id']) { return; } if (!bp_groups_user_can_send_invites($_POST['group_id'])) { return; } if (!friends_check_friendship(bp_loggedin_user_id(), $_POST['friend_id'])) { return; } $group_id = (int) $_POST['group_id']; $friend_id = (int) $_POST['friend_id']; if ('invite' == $_POST['friend_action']) { $group = groups_get_group($group_id); // Users who have previously requested membership do not need // another invitation created for them if (BP_Groups_Member::check_for_membership_request($friend_id, $group_id)) { $user_status = 'is_pending'; // Create the user invitation } elseif (groups_invite_user(array('user_id' => $friend_id, 'group_id' => $group_id))) { $user_status = 'is_invited'; // Miscellaneous failure } else { return; } $user = new BP_Core_User($friend_id); $uninvite_url = bp_is_current_action('create') ? bp_get_groups_directory_permalink() . 'create/step/group-invites/?user_id=' . $friend_id : bp_get_group_permalink($group) . 'send-invites/remove/' . $friend_id; echo '<li id="uid-' . esc_attr($user->id) . '">'; echo $user->avatar_thumb; echo '<h4>' . $user->user_link . '</h4>'; echo '<span class="activity">' . esc_attr($user->last_active) . '</span>'; echo '<div class="action"> <a class="button remove" href="' . wp_nonce_url($uninvite_url, 'groups_invite_uninvite_user') . '" id="uid-' . esc_attr($user->id) . '">' . __('Remove Invite', 'buddypress') . '</a> </div>'; if ('is_pending' == $user_status) { 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>'; } echo '</li>'; exit; } elseif ('uninvite' == $_POST['friend_action']) { // Users who have previously requested membership should not // have their requests deleted on the "uninvite" action if (BP_Groups_Member::check_for_membership_request($friend_id, $group_id)) { return; } // Remove the unsent invitation if (!groups_uninvite_user($friend_id, $group_id)) { return; } exit; } else { return; } }
/** * Invites a friend to join a group via a POST request. * * @return unknown * @since BuddyPress (1.2) * @todo Audit return types */ function bp_dtheme_ajax_invite_user() { // Bail if not a POST action if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) { return; } check_ajax_referer('groups_invite_uninvite_user'); if (!$_POST['friend_id'] || !$_POST['friend_action'] || !$_POST['group_id']) { return; } if (!bp_groups_user_can_send_invites($_POST['group_id'])) { return; } if (!friends_check_friendship(bp_loggedin_user_id(), $_POST['friend_id'])) { return; } if ('invite' == $_POST['friend_action']) { if (!groups_invite_user(array('user_id' => $_POST['friend_id'], 'group_id' => $_POST['group_id']))) { return; } $user = new BP_Core_User($_POST['friend_id']); echo '<li id="uid-' . $user->id . '">'; echo $user->avatar_thumb; echo '<h4>' . $user->user_link . '</h4>'; echo '<span class="activity">' . esc_attr($user->last_active) . '</span>'; echo '<div class="action"> <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', 'logicalboneshug') . '</a> </div>'; echo '</li>'; exit; } elseif ('uninvite' == $_POST['friend_action']) { if (!groups_uninvite_user($_POST['friend_id'], $_POST['group_id'])) { return; } exit; } else { return; } }
/** * Handle the display of a group's Send Invites page. */ function groups_screen_group_invite() { if (!bp_is_single_item()) { return false; } $bp = buddypress(); if (bp_is_action_variable('send', 0)) { if (!check_admin_referer('groups_send_invites', '_wpnonce_send_invites')) { return false; } if (!empty($_POST['friends'])) { foreach ((array) $_POST['friends'] as $friend) { groups_invite_user(array('user_id' => $friend, 'group_id' => $bp->groups->current_group->id)); } } // Send the invites. groups_send_invites(bp_loggedin_user_id(), $bp->groups->current_group->id); bp_core_add_message(__('Group invites sent.', 'buddypress')); /** * Fires after the sending of a group invite inside the group's Send Invites page. * * @since 1.0.0 * * @param int $id ID of the group whose members are being displayed. */ do_action('groups_screen_group_invite', $bp->groups->current_group->id); bp_core_redirect(bp_get_group_permalink($bp->groups->current_group)); } elseif (!bp_action_variable(0)) { /** * Filters the template to load for a group's Send Invites page. * * @since 1.0.0 * * @param string $value Path to a group's Send Invites template. */ bp_core_load_template(apply_filters('groups_template_group_invite', 'groups/single/home')); } else { bp_do_404(); } }
function invite_anyone_activate_user($user_id, $key, $user) { global $bp; $email = bp_core_get_user_email($user_id); $inviters = array(); // Fire the query $invites = invite_anyone_get_invitations_by_invited_email($email); if ($invites->have_posts()) { // From the posts returned by the query, get a list of unique inviters $groups = array(); while ($invites->have_posts()) { $invites->the_post(); $inviter_id = get_the_author_meta('ID'); $inviters[] = $inviter_id; $groups_data = wp_get_post_terms(get_the_ID(), invite_anyone_get_invited_groups_tax_name()); foreach ($groups_data as $group_data) { if (!isset($groups[$group_data->name])) { // Keyed by inviter, which means they'll only get one invite per group $groups[$group_data->name] = $inviter_id; } } // Mark as accepted update_post_meta(get_the_ID(), 'bp_ia_accepted', date('Y-m-d H:i:s')); } $inviters = array_unique($inviters); // Friendship requests if (bp_is_active('friends') && apply_filters('invite_anyone_send_friend_requests_on_acceptance', true)) { if (function_exists('friends_add_friend')) { foreach ($inviters as $inviter) { friends_add_friend($inviter, $user_id); } } } // BuddyPress Followers support if (function_exists('bp_follow_start_following') && apply_filters('invite_anyone_send_follow_requests_on_acceptance', true)) { foreach ($inviters as $inviter) { bp_follow_start_following(array('leader_id' => $user_id, 'follower_id' => $inviter)); bp_follow_start_following(array('leader_id' => $inviter, 'follower_id' => $user_id)); } } // Group invitations if (bp_is_active('groups')) { foreach ($groups as $group_id => $inviter_id) { $args = array('user_id' => $user_id, 'group_id' => $group_id, 'inviter_id' => $inviter_id); groups_invite_user($args); groups_send_invites($inviter_id, $group_id); } } } do_action('accepted_email_invite', $user_id, $inviters); }
public function test_groups_is_user_pending_should_return_false_for_pending_member() { groups_invite_user(array('user_id' => self::$user, 'group_id' => self::$groups[1], 'inviter_id' => 123)); // Send invite. $m = new BP_Groups_Member(self::$user, self::$groups[1]); $m->invite_sent = 1; $m->save(); $this->assertEquals(false, groups_is_user_pending(self::$user, self::$groups[1])); }
/** * Catch and process group creation form submissions. */ function groups_action_create_group() { global $bp; // If we're not at domain.org/groups/create/ then return false if (!bp_is_groups_component() || !bp_is_current_action('create')) { return false; } if (!is_user_logged_in()) { return false; } if (!bp_user_can_create_groups()) { bp_core_add_message(__('Sorry, you are not allowed to create groups.', 'buddypress'), 'error'); bp_core_redirect(trailingslashit(bp_get_root_domain() . '/' . bp_get_groups_root_slug())); } // Make sure creation steps are in the right order groups_action_sort_creation_steps(); // If no current step is set, reset everything so we can start a fresh group creation $bp->groups->current_create_step = bp_action_variable(1); if (!bp_get_groups_current_create_step()) { unset($bp->groups->current_create_step); unset($bp->groups->completed_create_steps); setcookie('bp_new_group_id', false, time() - 1000, COOKIEPATH); setcookie('bp_completed_create_steps', false, time() - 1000, COOKIEPATH); $reset_steps = true; $keys = array_keys($bp->groups->group_creation_steps); bp_core_redirect(bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/step/' . array_shift($keys) . '/'); } // If this is a creation step that is not recognized, just redirect them back to the first screen if (bp_get_groups_current_create_step() && empty($bp->groups->group_creation_steps[bp_get_groups_current_create_step()])) { bp_core_add_message(__('There was an error saving group details. Please try again.', 'buddypress'), 'error'); bp_core_redirect(bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/'); } // Fetch the currently completed steps variable if (isset($_COOKIE['bp_completed_create_steps']) && !isset($reset_steps)) { $bp->groups->completed_create_steps = json_decode(base64_decode(stripslashes($_COOKIE['bp_completed_create_steps']))); } // Set the ID of the new group, if it has already been created in a previous step if (isset($_COOKIE['bp_new_group_id'])) { $bp->groups->new_group_id = (int) $_COOKIE['bp_new_group_id']; $bp->groups->current_group = groups_get_group(array('group_id' => $bp->groups->new_group_id)); // Only allow the group creator to continue to edit the new group if (!bp_is_group_creator($bp->groups->current_group, bp_loggedin_user_id())) { bp_core_add_message(__('Only the group creator may continue editing this group.', 'buddypress'), 'error'); bp_core_redirect(bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/'); } } // If the save, upload or skip button is hit, lets calculate what we need to save if (isset($_POST['save'])) { // Check the nonce check_admin_referer('groups_create_save_' . bp_get_groups_current_create_step()); if ('group-details' == bp_get_groups_current_create_step()) { if (empty($_POST['group-name']) || empty($_POST['group-desc']) || !strlen(trim($_POST['group-name'])) || !strlen(trim($_POST['group-desc']))) { bp_core_add_message(__('Please fill in all of the required fields', 'buddypress'), 'error'); bp_core_redirect(bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/step/' . bp_get_groups_current_create_step() . '/'); } $new_group_id = isset($bp->groups->new_group_id) ? $bp->groups->new_group_id : 0; if (!($bp->groups->new_group_id = groups_create_group(array('group_id' => $new_group_id, 'name' => $_POST['group-name'], 'description' => $_POST['group-desc'], 'slug' => groups_check_slug(sanitize_title(esc_attr($_POST['group-name']))), 'date_created' => bp_core_current_time(), 'status' => 'public')))) { bp_core_add_message(__('There was an error saving group details, please try again.', 'buddypress'), 'error'); bp_core_redirect(bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/step/' . bp_get_groups_current_create_step() . '/'); } } if ('group-settings' == bp_get_groups_current_create_step()) { $group_status = 'public'; $group_enable_forum = 1; if (!isset($_POST['group-show-forum'])) { $group_enable_forum = 0; } else { // Create the forum if enable_forum = 1 if (bp_is_active('forums') && !groups_get_groupmeta($bp->groups->new_group_id, 'forum_id')) { groups_new_group_forum(); } } if ('private' == $_POST['group-status']) { $group_status = 'private'; } else { if ('hidden' == $_POST['group-status']) { $group_status = 'hidden'; } } if (!($bp->groups->new_group_id = groups_create_group(array('group_id' => $bp->groups->new_group_id, 'status' => $group_status, 'enable_forum' => $group_enable_forum)))) { bp_core_add_message(__('There was an error saving group details, please try again.', 'buddypress'), 'error'); bp_core_redirect(bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/step/' . bp_get_groups_current_create_step() . '/'); } // Set the invite status // Checked against a whitelist for security $allowed_invite_status = apply_filters('groups_allowed_invite_status', array('members', 'mods', 'admins')); $invite_status = !empty($_POST['group-invite-status']) && in_array($_POST['group-invite-status'], (array) $allowed_invite_status) ? $_POST['group-invite-status'] : 'members'; groups_update_groupmeta($bp->groups->new_group_id, 'invite_status', $invite_status); } if ('group-invites' === bp_get_groups_current_create_step()) { if (!empty($_POST['friends'])) { foreach ((array) $_POST['friends'] as $friend) { groups_invite_user(array('user_id' => $friend, 'group_id' => $bp->groups->new_group_id)); } } groups_send_invites(bp_loggedin_user_id(), $bp->groups->new_group_id); } do_action('groups_create_group_step_save_' . bp_get_groups_current_create_step()); do_action('groups_create_group_step_complete'); // Mostly for clearing cache on a generic action name /** * Once we have successfully saved the details for this step of the creation process * we need to add the current step to the array of completed steps, then update the cookies * holding the information */ $completed_create_steps = isset($bp->groups->completed_create_steps) ? $bp->groups->completed_create_steps : array(); if (!in_array(bp_get_groups_current_create_step(), $completed_create_steps)) { $bp->groups->completed_create_steps[] = bp_get_groups_current_create_step(); } // Reset cookie info setcookie('bp_new_group_id', $bp->groups->new_group_id, time() + 60 * 60 * 24, COOKIEPATH); setcookie('bp_completed_create_steps', base64_encode(json_encode($bp->groups->completed_create_steps)), time() + 60 * 60 * 24, COOKIEPATH); // If we have completed all steps and hit done on the final step we // can redirect to the completed group $keys = array_keys($bp->groups->group_creation_steps); if (count($bp->groups->completed_create_steps) == count($keys) && bp_get_groups_current_create_step() == array_pop($keys)) { unset($bp->groups->current_create_step); unset($bp->groups->completed_create_steps); // Once we compelete all steps, record the group creation in the activity stream. groups_record_activity(array('type' => 'created_group', 'item_id' => $bp->groups->new_group_id)); do_action('groups_group_create_complete', $bp->groups->new_group_id); bp_core_redirect(bp_get_group_permalink($bp->groups->current_group)); } else { /** * Since we don't know what the next step is going to be (any plugin can insert steps) * we need to loop the step array and fetch the next step that way. */ foreach ($keys as $key) { if ($key == bp_get_groups_current_create_step()) { $next = 1; continue; } if (isset($next)) { $next_step = $key; break; } } bp_core_redirect(bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/step/' . $next_step . '/'); } } // Remove invitations if ('group-invites' === bp_get_groups_current_create_step() && !empty($_REQUEST['user_id']) && is_numeric($_REQUEST['user_id'])) { if (!check_admin_referer('groups_invite_uninvite_user')) { return false; } $message = __('Invite successfully removed', 'buddypress'); $error = false; if (!groups_uninvite_user((int) $_REQUEST['user_id'], $bp->groups->new_group_id)) { $message = __('There was an error removing the invite', 'buddypress'); $error = 'error'; } bp_core_add_message($message, $error); bp_core_redirect(bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/step/group-invites/'); } // Group avatar is handled separately if ('group-avatar' == bp_get_groups_current_create_step() && isset($_POST['upload'])) { if (!isset($bp->avatar_admin)) { $bp->avatar_admin = new stdClass(); } if (!empty($_FILES) && isset($_POST['upload'])) { // Normally we would check a nonce here, but the group save nonce is used instead // Pass the file to the avatar upload handler if (bp_core_avatar_handle_upload($_FILES, 'groups_avatar_upload_dir')) { $bp->avatar_admin->step = 'crop-image'; // Make sure we include the jQuery jCrop file for image cropping add_action('wp_print_scripts', 'bp_core_add_jquery_cropper'); } } // If the image cropping is done, crop the image and save a full/thumb version if (isset($_POST['avatar-crop-submit']) && isset($_POST['upload'])) { // Normally we would check a nonce here, but the group save nonce is used instead if (!bp_core_avatar_handle_crop(array('object' => 'group', 'avatar_dir' => 'group-avatars', 'item_id' => $bp->groups->current_group->id, 'original_file' => $_POST['image_src'], 'crop_x' => $_POST['x'], 'crop_y' => $_POST['y'], 'crop_w' => $_POST['w'], 'crop_h' => $_POST['h']))) { bp_core_add_message(__('There was an error saving the group profile photo, please try uploading again.', 'buddypress'), 'error'); } else { bp_core_add_message(__('The group profile photo was uploaded successfully!', 'buddypress')); } } } bp_core_load_template(apply_filters('groups_template_create_group', 'groups/create')); }
/** * Handle the display of a group's Send Invites page. */ function groups_screen_group_invite() { if (!bp_is_single_item()) { return false; } $bp = buddypress(); if (bp_is_action_variable('send', 0)) { if (!check_admin_referer('groups_send_invites', '_wpnonce_send_invites')) { return false; } if (!empty($_POST['friends'])) { foreach ((array) $_POST['friends'] as $friend) { groups_invite_user(array('user_id' => $friend, 'group_id' => $bp->groups->current_group->id)); } } // Send the invites. groups_send_invites(bp_loggedin_user_id(), $bp->groups->current_group->id); bp_core_add_message(__('Group invites sent.', 'buddypress')); do_action('groups_screen_group_invite', $bp->groups->current_group->id); bp_core_redirect(bp_get_group_permalink($bp->groups->current_group)); } elseif (!bp_action_variable(0)) { // Show send invite page bp_core_load_template(apply_filters('groups_template_group_invite', 'groups/single/home')); } else { bp_do_404(); } }
function invite_anyone_ajax_invite_user() { global $bp; check_ajax_referer('groups_invite_uninvite_user'); if (!$_POST['friend_id'] || !$_POST['friend_action'] || !$_POST['group_id']) { return false; } if ('invite' == $_POST['friend_action']) { if (!groups_invite_user(array('user_id' => $_POST['friend_id'], 'group_id' => $_POST['group_id']))) { return false; } $user = new BP_Core_User($_POST['friend_id']); $group_slug = isset($bp->groups->root_slug) ? $bp->groups->root_slug : $bp->groups->slug; if (bp_is_current_action('create')) { $uninvite_url = bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/step/group-invites/?user_id=' . $user->id; } else { $uninvite_url = bp_get_group_permalink(groups_get_current_group()) . 'send-invites/remove/' . $user->id; } echo '<li id="uid-' . $user->id . '">'; echo bp_core_fetch_avatar(array('item_id' => $user->id)); echo '<h4>' . bp_core_get_userlink($user->id) . '</h4>'; echo '<span class="activity">' . esc_html($user->last_active) . '</span>'; echo '<div class="action"> <a class="remove" href="' . wp_nonce_url($uninvite_url) . '" id="uid-' . esc_html($user->id) . '">' . __('Remove Invite', 'buddypress') . '</a> </div>'; echo '</li>'; } else { if ('uninvite' == $_POST['friend_action']) { groups_uninvite_user($_POST['friend_id'], $_POST['group_id']); } } die; }
/** * @group counts */ public function test_get_invite_count_for_user() { $u1 = $this->factory->user->create(); $u2 = $this->factory->user->create(); $g = $this->factory->group->create(array('creator_id' => $u1)); // create invitation groups_invite_user(array('user_id' => $u2, 'group_id' => $g, 'inviter_id' => $u1)); // send the invite // this function is imperative to set the 'invite_sent' flag in the DB // why is this separated from groups_invite_user()? // @see groups_screen_group_invite() groups_send_invites($u1, $g); // assert invite count $this->assertEquals(1, groups_get_invite_count_for_user($u2)); // accept the invite and reassert groups_accept_invite($u2, $g); $this->assertEquals(0, groups_get_invite_count_for_user($u2)); }
/** * The main workhorse where the friends, groups and welcome message features happens. * Triggers when a user account is activated. * * @param int $user_id ID of the new user * @since 3.0 */ function user_activated($user_id) { $settings = DP_Welcome_Pack::get_settings(); // Is the Friend invitations component enabled? if (!empty($settings['dpw_friendstoggle']) && bp_is_active('friends') && !empty($settings['friends'])) { // Send friend requests foreach ((array) $settings['friends'] as $friend_id) { friends_add_friend((int) $friend_id, $user_id, constant('WELCOME_PACK_AUTOACCEPT_INVITATIONS')); } } // Is the Group invitations component enabled? if (!empty($settings['dpw_groupstoggle']) && bp_is_active('groups') && !empty($settings['groups'])) { foreach ((array) $settings['groups'] as $group_id) { $group = new BP_Groups_Group((int) $group_id); // Send group invites groups_invite_user(array('user_id' => $user_id, 'group_id' => (int) $group_id, 'inviter_id' => $group->creator_id, 'is_confirmed' => constant('WELCOME_PACK_AUTOACCEPT_INVITATIONS'))); groups_send_invites($group->creator_id, (int) $group_id); } } // Is the Welcome Message component enabled? if (!empty($settings['dpw_welcomemsgtoggle']) && bp_is_active('messages') && !empty($settings['welcomemsgsender']) && !empty($settings['welcomemsgsubject']) && !empty($settings['welcomemsg'])) { messages_new_message(array('sender_id' => $settings['welcomemsgsender'], 'recipients' => $user_id, 'subject' => apply_filters('dpw_keyword_replacement', $settings['welcomemsgsubject'], $user_id), 'content' => apply_filters('dpw_keyword_replacement', $settings['welcomemsg'], $user_id))); } // Call an action for third-parties to hook into do_action('dpw_user_activated', $user_id); }
/** * @group BP7375 */ public function test_membership_request_notifications_should_be_cleared_when_request_is_accepted() { $users = $this->factory->user->create_many(3); $this->add_user_to_group($users[0], $this->group, array('is_admin' => 1)); $this->add_user_to_group($users[1], $this->group, array('is_admin' => 1)); groups_send_membership_request($users[2], $this->group); // Both admins should get a notification. $get_args = array('user_id' => $users[0], 'item_id' => $this->group, 'secondary_item_id' => $users[2], 'component_action' => 'new_membership_request', 'is_new' => true); $u0_notifications = BP_Notifications_Notification::get($get_args); $u1_notifications = BP_Notifications_Notification::get($get_args); $this->assertNotEmpty($u0_notifications); $this->assertNotEmpty($u1_notifications); $this->assertTrue(groups_invite_user(array('user_id' => $users[2], 'group_id' => $this->group))); $u0_notifications = BP_Notifications_Notification::get($get_args); $u1_notifications = BP_Notifications_Notification::get($get_args); $this->assertEmpty($u0_notifications); $this->assertEmpty($u1_notifications); }
function invite_anyone_activate_user($user_id, $key, $user) { global $bp; $email = bp_core_get_user_email($user_id); if ($invites = invite_anyone_get_invitations_by_invited_email($email)) { // Mark as "is_joined" invite_anyone_mark_as_joined($email); // Friendship requests if (bp_is_active('friends')) { $inviters = array(); foreach ($invites as $invite) { if (!in_array($invite->inviter_id, $inviters)) { $inviters[] = $invite->inviter_id; } } if (function_exists('friends_add_friend')) { foreach ($inviters as $inviter) { friends_add_friend($inviter, $user_id); } } } // BuddyPress Followers support if (function_exists('bp_follow_start_following')) { $inviters = array(); foreach ($invites as $invite) { if (!in_array($invite->inviter_id, $inviters)) { $inviters[] = $invite->inviter_id; } } foreach ($inviters as $inviter) { bp_follow_start_following(array('leader_id' => $user_id, 'follower_id' => $inviter)); bp_follow_start_following(array('leader_id' => $inviter, 'follower_id' => $user_id)); } } // BuddyPress Followers support if (function_exists('bp_follow_start_following')) { $inviters = array(); foreach ($invites as $invite) { if (!in_array($invite->inviter_id, $inviters)) { $inviters[] = $invite->inviter_id; } } foreach ($inviters as $inviter) { bp_follow_start_following(array('leader_id' => $user_id, 'follower_id' => $inviter)); bp_follow_start_following(array('leader_id' => $inviter, 'follower_id' => $user_id)); } } // Group invitations if (bp_is_active('groups')) { $groups = array(); foreach ($invites as $invite) { if (!$invite->group_invitations[0]) { continue; } else { $group_invitations = unserialize($invite->group_invitations); } foreach ($group_invitations as $group) { if (!in_array($group, array_keys($groups))) { $groups[$group] = $invite->inviter_id; } } } foreach ($groups as $group_id => $inviter_id) { $args = array('user_id' => $user_id, 'group_id' => $group_id, 'inviter_id' => $inviter_id); groups_invite_user($args); groups_send_invites($inviter_id, $group_id); } } } do_action('accepted_email_invite', $user_id, $inviters); }
/** * @group cache */ public function test_cache_should_be_invalidated_on_group_invite_delete() { groups_invite_user(array('user_id' => self::$user, 'group_id' => self::$groups[2], 'inviter_id' => self::$admin_user)); // Populate cache. $g1 = bp_get_user_groups(self::$user, array('is_confirmed' => null)); groups_delete_invite(self::$user, self::$groups[2]); $expected = array(self::$groups[0], self::$groups[1]); $found = bp_get_user_groups(self::$user, array('is_confirmed' => null)); $this->assertEqualSets($expected, array_keys($found)); }
function invite_anyone_ajax_invite_user() { global $bp; check_ajax_referer('groups_invite_uninvite_user'); if (!$_POST['friend_id'] || !$_POST['friend_action'] || !$_POST['group_id']) { return false; } if ('invite' == $_POST['friend_action']) { if (!groups_invite_user(array('user_id' => $_POST['friend_id'], 'group_id' => $_POST['group_id']))) { return false; } $user = new BP_Core_User($_POST['friend_id']); $group_slug = isset($bp->groups->root_slug) ? $bp->groups->root_slug : $bp->groups->slug; echo '<li id="uid-' . $user->id . '">'; echo bp_core_fetch_avatar(array('item_id' => $user->id)); echo '<h4>' . bp_core_get_userlink($user->id) . '</h4>'; echo '<span class="activity">' . esc_html($user->last_active) . '</span>'; echo '<div class="action"> <a class="remove" href="' . wp_nonce_url($bp->loggedin_user->domain . $group_slug . '/' . $_POST['group_id'] . '/invites/remove/' . $user->id, 'groups_invite_uninvite_user') . '" id="uid-' . esc_html($user->id) . '">' . __('Remove Invite', 'buddypress') . '</a> </div>'; echo '</li>'; } else { if ('uninvite' == $_POST['friend_action']) { if (!groups_uninvite_user($_POST['friend_id'], $_POST['group_id'])) { return false; } return true; } else { return false; } } }
function bp_dtheme_ajax_invite_user() { global $bp; check_ajax_referer('groups_invite_uninvite_user'); if (!$_POST['friend_id'] || !$_POST['friend_action'] || !$_POST['group_id']) { return false; } if (!bp_groups_user_can_send_invites($_POST['group_id']) || !friends_check_friendship($bp->loggedin_user->id, $_POST['friend_id'])) { return false; } if ('invite' == $_POST['friend_action']) { if (!groups_invite_user(array('user_id' => $_POST['friend_id'], 'group_id' => $_POST['group_id']))) { return false; } $user = new BP_Core_User($_POST['friend_id']); echo '<li id="uid-' . $user->id . '">'; echo $user->avatar_thumb; echo '<h4>' . $user->user_link . '</h4>'; echo '<span class="activity">' . esc_attr($user->last_active) . '</span>'; echo '<div class="action"> <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> </div>'; echo '</li>'; } else { if ('uninvite' == $_POST['friend_action']) { return (bool) groups_uninvite_user($_POST['friend_id'], $_POST['group_id']); } else { return false; } } }
/** * @group groups_send_invites * @group group_invitations * @group group_membership_requests * @group group_membership */ public function test_groups_membership_request_plus_invite_equals_member() { $u1 = $this->factory->user->create(); $u2 = $this->factory->user->create(); $g1 = $this->factory->group->create(array('creator_id' => $u1)); // Create membership request groups_send_membership_request($u2, $g1); // Create draft invitation groups_invite_user(array('user_id' => $u2, 'group_id' => $g1, 'inviter_id' => $u1, 'date_modified' => bp_core_current_time(), 'is_confirmed' => 0)); // Send the invitation groups_send_invites($u1, $g1); // User should now be a group member $member = groups_is_user_member($u2, $g1); $this->assertTrue(is_numeric($member) && $member > 0); }