function addInvites($emails) { //make sure emails are passed if (empty($emails)) { return false; } //make sure it's an array of unique, lowercase, emails if (!is_array($emails)) { $emails = sp_convertEmailStringToArray($emails); } $error_emails = array(); $okay_emails = array(); foreach ($emails as $email) { //if this doesn't look like an email add to error_emails if (!is_email($email)) { $error_emails[] = $email; } //if the user already exists, add them to the class $email_user = get_user_by("email", $email); if (!empty($email_user)) { //add the user to the BuddyPress group groups_join_group($this->group->id, $email_user->ID); //send added email $body = "You have been added to the " . $this->name . " class at SchoolPress.me.\n\n" . get_permalink($this->id); wp_mail($email, "SchoolPress - You have been added to a class.", $body); } else { //attach email to this group so we add the user after registration groups_add_groupmeta($this->group->id, "sp_invites", $email); //send invite email $body = "You have been invited to the " . $this->name . " class at SchoolPress.me.\n\nFollow this link to register for this class:\n" . get_permalink($this->id); wp_mail($email, "SchoolPress - You have been invited to a class. Register now.", $body); } $okay_emails[] = $email; } //reset student list $this->getStudents(true); //return true or array of broken emails if (empty($error_emails)) { return true; } else { return $error_emails; } }
/** * @group groupmeta * @group groups_add_groupmeta */ public function test_groups_add_groupmeta_existing_not_unique() { $g = $this->factory->group->create(); groups_add_groupmeta($g, 'foo', 'bar'); $this->assertNotEmpty(groups_add_groupmeta($g, 'foo', 'baz')); }