I found this topic that seems to be my issue. I don’t know where to implement it. Can you tell me where to place the code. http://www.s2member.com/forums/topic/bypass-closed-registration-for-current-user/
This is the php from the invite anyone plugin. I think this is what I’m looking to do something with?
current_component == BP_INVITE_ANYONE_SLUG ) {
$style_url = WP_PLUGIN_URL . '/invite-anyone/by-email/by-email-css.css';
$style_file = WP_PLUGIN_DIR . '/invite-anyone/by-email/by-email-css.css';
if (file_exists($style_file)) {
wp_register_style('invite-anyone-by-email-style', $style_url);
wp_enqueue_style('invite-anyone-by-email-style');
}
}
}
add_action( 'wp_print_styles', 'invite_anyone_add_by_email_css' );
function invite_anyone_add_by_email_js() {
global $bp;
if ( $bp->current_component == BP_INVITE_ANYONE_SLUG ) {
$style_url = WP_PLUGIN_URL . '/invite-anyone/by-email/by-email-js.js';
$style_file = WP_PLUGIN_DIR . '/invite-anyone/by-email/by-email-js.js';
if (file_exists($style_file)) {
wp_register_script('invite-anyone-by-email-scripts', $style_url);
wp_enqueue_script('invite-anyone-by-email-scripts');
}
}
}
add_action( 'wp_print_scripts', 'invite_anyone_add_by_email_js' );
function invite_anyone_setup_globals() {
global $bp, $wpdb;
$bp->invite_anyone->id = 'invite_anyone';
$bp->invite_anyone->table_name = $wpdb->base_prefix . 'bp_invite_anyone';
$bp->invite_anyone->slug = 'invite-anyone';
/* Register this in the active components array */
$bp->active_components[$bp->invite_anyone->slug] = $bp->invite_anyone->id;
}
add_action( 'bp_setup_globals', 'invite_anyone_setup_globals', 2 );
function invite_anyone_opt_out_screen() {
global $bp;
if ( isset( $_POST['oops_submit'] ) ) {
bp_core_redirect( site_url( BP_REGISTER_SLUG ) . '/accept-invitation/' . urlencode( $_POST['opt_out_email'] ) );
}
$opt_out_button_text = __( 'Opt Out', 'bp-invite-anyone' );
$oops_button_text = __( 'Accept Invitation', 'bp-invite-anyone' );
$sitename = get_bloginfo( 'name' );
$opt_out_message = sprintf( __( 'To opt out of future invitations to %s, make sure that your email is entered in the field below and click "Opt Out".', 'bp-invite-anyone' ), $sitename );
$oops_message = sprintf( __( 'If you are here by mistake and would like to accept your invitation to %s, click "Accept Invitation" instead.', 'bp-invite-anyone' ), $sitename );
if ( $bp->current_component == BP_REGISTER_SLUG && $bp->current_action == 'opt-out' ) {
get_header();
?>
action_variables[1] == 'submit' ) : ?>
<p></p>
<p></p>
action_variables[0] ) : ?>
jQuery(document).ready( function() {
jQuery("input#opt_out_email").val("");
});
<form action="/submit" method="post">
<p></p>
<p></p>
<p> </p>
<p><input type="submit" name="opt_out_submit" value="" /> <input type="submit" name="oops_submit" value="" />
</p>
current_action ) && $bp->current_action == 'accept-invitation' && empty( $bp->action_variables[0] ) ) : ?>
<p></p>
signup->step == 'request-details' && $bp->current_action == 'accept-invitation' && $email = urldecode( $bp->action_variables[0] ) ) : ?>
jQuery(document).ready( function() {
jQuery("input#signup_email").val("");
});
have_posts() ) {
while ( $ia_obj->have_posts() ) {
$ia_obj->the_post();
$inviters[] = get_the_author_meta( 'ID' );
}
}
$inviters = array_unique( $inviters );
$inviters_text = '';
if ( count( $inviters ) == 0 ) {
$inviters_text = '';
} else if ( count( $inviters ) == 1 ) {
$inviters_text .= 'by ';
$inviters_text .= bp_core_get_user_displayname( $inviters[0] );
} else {
$counter = 1;
$inviters_text .= 'by ';
$inviters_text .= bp_core_get_user_displayname( $inviters[0] );
while ( $counter < count( $inviters ) - 1 ) {
$inviters_text .= ', ' . bp_core_get_user_displayname( $inviters[$counter] );
$counter++;
}
$inviters_text .= ' and ' . bp_core_get_user_displayname( $inviters[$counter] );
}
if ( !empty( $inviters_text ) ) {
$message = sprintf( __( 'Welcome! You've been invited %s to join the site. Please fill out the information below to create your account.', 'bp-invite-anyone' ), $inviters_text );
echo '<p>' . $message . '</p>';
}
?>
have_posts() ) {
// From the posts returned by the query, get a list of unique inviters
$inviters = array();
$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' ) ) {
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' ) ) {
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 );
}
add_action( 'bp_core_activated_user', 'invite_anyone_activate_user', 10, 3 );
function invite_anyone_setup_nav() {
global $bp;
if ( !invite_anyone_access_test() )
return;
/* Add 'Send Invites' to the main user profile navigation */
bp_core_new_nav_item( array(
'name' => __( 'Send Invites', 'buddypress' ),
'slug' => $bp->invite_anyone->slug,
'position' => 80,
'screen_function' => 'invite_anyone_screen_one',
'default_subnav_slug' => 'invite-new-members',
'show_for_displayed_user' => invite_anyone_access_test()
) );
$invite_anyone_link = $bp->loggedin_user->domain . $bp->invite_anyone->slug . '/';
/* Create two sub nav items for this component */
bp_core_new_subnav_item( array(
'name' => __( 'Invite New Members', 'bp-invite-anyone' ),
'slug' => 'invite-new-members',
'parent_slug' => $bp->invite_anyone->slug,
'parent_url' => $invite_anyone_link,
'screen_function' => 'invite_anyone_screen_one',
'position' => 10,
'user_has_access' => invite_anyone_access_test()
) );
bp_core_new_subnav_item( array(
'name' => __( 'Sent Invites', 'bp-invite-anyone' ),
'slug' => 'sent-invites',
'parent_slug' => $bp->invite_anyone->slug,
'parent_url' => $invite_anyone_link,
'screen_function' => 'invite_anyone_screen_two',
'position' => 20,
'user_has_access' => invite_anyone_access_test()
) );
}
add_action( 'bp_setup_nav', 'invite_anyone_setup_nav' );
function invite_anyone_access_test() {
global $current_user, $bp;
if ( !is_user_logged_in() )
return false;
if ( bp_displayed_user_id() && !bp_is_my_profile() )
return false;
$iaoptions = invite_anyone_options();
/* This is the last of the general checks: logged in, looking at own profile, and finally admin has set to "All Users".*/
if ( isset( $iaoptions['email_visibility_toggle'] ) && $iaoptions['email_visibility_toggle'] == 'no_limit' )
return true;
/* Minimum number of days since joined the site */
if ( isset( $iaoptions['email_since_toggle'] ) && $iaoptions['email_since_toggle'] == 'yes' ) {
if ( isset( $iaoptions['days_since'] ) && $since = $iaoptions['days_since'] ) {
$since = $since * 86400;
$date_registered = strtotime($current_user->data->user_registered);
$time = time();
if ( $time - $date_registered ID;
if ( in_array( $user_id, $blacklist ) )
return false;
}
}
return true;
}
add_action( 'wp_head', 'invite_anyone_access_test' );
function invite_anyone_catch_clear() {
global $bp;
// We'll take a moment nice and early in the loading process to get returned_data
$keys = array(
'error_message',
'error_emails',
'subject',
'message',
'groups'
);
foreach( $keys as $key ) {
$bp->invite_anyone->returned_data[$key] = null;
if ( isset( $_GET[$key] ) ) {
if ( is_array( $_GET[$key] ) ) {
$value = array();
foreach( $_GET[$key] as $kk => $vv ) {
$value[$kk] = urldecode( $vv );
}
} else {
$value = urldecode( $_GET[$key] );
}
$bp->invite_anyone->returned_data[$key] = $value;
}
}
if ( isset( $_GET['clear'] ) ) {
$clear_id = $_GET['clear'];
$inviter_id = bp_loggedin_user_id();
check_admin_referer( 'invite_anyone_clear' );
if ( (int)$clear_id ) {
if ( invite_anyone_clear_sent_invite( array( 'inviter_id' => $inviter_id, 'clear_id' => $clear_id ) ) )
bp_core_add_message( __( 'Invitation cleared', 'bp-invite-anyone' ) );
else
bp_core_add_message( __( 'There was a problem clearing the invitation.', 'bp-invite-anyone' ), 'error' );
} else {
if ( invite_anyone_clear_sent_invite( array( 'inviter_id' => $inviter_id, 'type' => $clear_id ) ) )
bp_core_add_message( __( 'Invitations cleared.', 'bp-invite-anyone' ) );
else
bp_core_add_message( __( 'There was a problem clearing the invitations.', 'bp-invite-anyone' ), 'error' );
}
bp_core_redirect( $bp->displayed_user->domain . $bp->invite_anyone->slug . '/sent-invites/' );
}
}
add_action( 'wp', 'invite_anyone_catch_clear', 1 );
function invite_anyone_screen_one() {
global $bp;
/*
print "<pre>";
print_r($bp);
*/
/* Add a do action here, so your component can be extended by others. */
do_action( 'invite_anyone_screen_one' );
/* bp_template_title ought to be used - bp-default needs to markup the template tag
and run a conditional check on template tag true to hide empty element markup or not
add_action( 'bp_template_title', 'invite_anyone_screen_one_title' );
*/
add_action( 'bp_template_content', 'invite_anyone_screen_one_content' );
bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
}
/*
function invite_anyone_screen_one_title() {
_e( 'Invite New Members', 'bp-invite-anyone' );
}
*/
function invite_anyone_screen_one_content() {
global $bp;
$iaoptions = invite_anyone_options();
// If the user has maxed out his invites, no need to go on
if ( !empty( $iaoptions['email_limit_invites_toggle'] ) && $iaoptions['email_limit_invites_toggle'] == 'yes' && !current_user_can( 'delete_others_pages' ) ) {
$sent_invites = invite_anyone_get_invitations_by_inviter_id( bp_displayed_user_id() );
$sent_invites_count = $sent_invites->post_count;
if ( $sent_invites_count >= $iaoptions['limit_invites_per_user'] ) : ?>
<h4></h4>
<p></p>
action_variables ) ) {
if ( 'group-invites' == $bp->action_variables[0] )
$from_group = $bp->action_variables[1];
}
$returned_data = !empty( $bp->invite_anyone->returned_data ) ? $bp->invite_anyone->returned_data : false;
/* If the user is coming from the widget, $returned_emails is populated with those email addresses */
if ( isset( $_POST['invite_anyone_widget'] ) ) {
check_admin_referer( 'invite-anyone-widget_' . $bp->loggedin_user->id );
if ( !empty( $_POST['invite_anyone_email_addresses'] ) ) {
$returned_data['error_emails'] = invite_anyone_parse_addresses( $_POST['invite_anyone_email_addresses'] );
}
/* If the widget appeared on a group page, the group ID should come along with it too */
if ( isset( $_POST['invite_anyone_widget_group'] ) )
$returned_data['groups'] = $_POST['invite_anyone_widget_group'];
}
// $returned_groups is padded so that array_search (below) returns true for first group */
$counter = 0;
$returned_groups = array( 0 );
if ( ! empty( $returned_data['groups'] ) ) {
foreach( $returned_data['groups'] as $group_id ) {
$returned_groups[] = $group_id;
}
}
// Get the returned email subject, if there is one
$returned_subject = ! empty( $returned_data['subject'] ) ? stripslashes( $returned_data['subject'] ) : false;
// Get the returned email message, if there is one
$returned_message = ! empty( $returned_data['message'] ) ? stripslashes( $returned_data['message'] ) : false;
if ( ! empty( $returned_data['error_message'] ) ) {
?>
<p></p>
<form id="invite-anyone-by-email" action="displayed_user->domain . $bp->invite_anyone->slug . '/sent-invites/send/' ?>" method="post">
<h4></h4>
post_count;
}
$limit_invite_count = (int) $iaoptions['limit_invites_per_user'] - (int) $sent_invites_count;
if ( $limit_invite_count
<p></p>
<p></p>
<ol>
<li>
<p></p>
<p>
</p>
<p></p>
</li>
<li>
< ?php _e( 'Subject: Subject line is fixed', 'bp-invite-anyone' ) ?>
<input type="hidden" id="invite-anyone-customised-subject" name="invite_anyone_custom_subject" value="" />
</li>
<li>
<p></p>
<input type="hidden" name="invite_anyone_custom_message" value="" />
</li>
<li>
<p></p>
<ul>
<li>
<input type="checkbox" name="invite_anyone_groups[]" id="invite_anyone_groups-" value="" checked />
<label for="invite_anyone_groups-" class="invite-anyone-group-name">
</li>
</ul>
</li>
</ol>
<input type="submit" name="invite-anyone-submit" id="invite-anyone-submit" value=" " />
current_component == $bp->invite_anyone->slug && $bp->current_action == 'sent-invites' && isset( $bp->action_variables[0] ) && $bp->action_variables[0] == 'send' ) {
if ( ! invite_anyone_process_invitations( $_POST ) )
bp_core_add_message( __( 'Sorry, there was a problem sending your invitations. Please try again.', 'bp-invite-anyone' ), 'error' );
}
do_action( 'invite_anyone_sent_invites_screen' );
/* bp_template_title ought to be used - bp-default needs to markup the template tag
and run a conditional check on template tag true to hide empty element markup or not
add_action( 'bp_template_title', 'invite_anyone_screen_two_title' );
*/
add_action( 'bp_template_content', 'invite_anyone_screen_two_content' );
bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
}
/*
function invite_anyone_screen_two_title() {
_e( 'Sent Invites', 'bp-invite-anyone' );
}
*/
function invite_anyone_screen_two_content() {
global $bp;
// Load the pagination helper
if ( !class_exists( 'BBG_CPT_Pag' ) )
require_once( dirname( __FILE__ ) . '/../lib/bbg-cpt-pag.php' );
$pagination = new BBG_CPT_Pag;
$inviter_id = bp_loggedin_user_id();
if ( isset( $_GET['sort_by'] ) )
$sort_by = $_GET['sort_by'];
else
$sort_by = 'date_invited';
if ( isset( $_GET['order'] ) )
$order = $_GET['order'];
else
$order = 'DESC';
$base_url = $bp->displayed_user->domain . $bp->invite_anyone->slug . '/sent-invites/';
?>
<h4></h4>
get_per_page, $pagination->get_paged ) ?>
setup_query( $invites ) ?>
have_posts() ) : ?>
<p></p>
currently_viewing_text() ?>
paginate_links() ?>
<table class="invite-anyone-sent-invites zebra"
summary="">
<thead>
<tr>
<th></th>
<th scope="col" class="sort-by-me"><a class="" title="Sort column order " href="?sort_by=email&order=DESCASC"></a></th>
<th></th>
<th scope="col" class="sort-by-me"><a class="" title="Sort column order " href="?sort_by=date_invited&order=ASCDESC"></a></th>
<th scope="col" class="sort-by-me"><a class="" title="Sort column order " href="?sort_by=date_joined&order=ASCDESC"></a></th>
</tr>
</thead>
<tfoot>
<tr>
<td>
<ul>
<li> <a title="" class="confirm" href=""></a></li>
<li><a title="" class="confirm" href=""></a></li>
</ul>
</td>
</tr>
</tfoot>
<tbody>
have_posts() ) : $invites->the_post() ?>
name;
$post_id = get_the_ID();
$query_string = preg_replace( "|clear=[0-9]+|", '', $_SERVER['QUERY_STRING'] );
$clear_url = ( $query_string ) ? $base_url . '?' . $query_string . '&clear=' . $post_id : $base_url . '?clear=' . $post_id;
$clear_url = wp_nonce_url( $clear_url, 'invite_anyone_clear' );
$clear_link = '<a title="' . __( 'Clear this invitation', 'bp-invite-anyone' ) . '" href="' . $clear_url . '">x</a>';
$groups = wp_get_post_terms( get_the_ID(), invite_anyone_get_invited_groups_tax_name() );
if ( !empty( $groups ) ) {
$group_names = '<ul>';
foreach( $groups as $group_term ) {
$group = new BP_Groups_Group( $group_term->name );
$group_names .= '<li>' . bp_get_group_name( $group ) . '</li>';
}
$group_names .= '</ul>';
} else {
$group_names = '-';
}
global $post;
$date_invited = invite_anyone_format_date( $post->post_date );
$accepted = get_post_meta( get_the_ID(), 'bp_ia_accepted', true );
if ( $accepted ):
$date_joined = invite_anyone_format_date( $accepted );
$accepted = true;
else:
$date_joined = '-';
$accepted = false;
endif;
?>
<tr class="accepted" >
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
currently_viewing_text() ?>
paginate_links() ?>
<p></p>
loggedin_user->userdata->display_name;
$blogname = get_bloginfo('name');
$iaoptions = invite_anyone_options();
if ( empty( $iaoptions['default_invitation_message'] ) ) {
$text = sprintf( __( 'You have been invited by %%INVITERNAME%% to join the %s community.
Visit %%INVITERNAME%%'s profile at %%INVITERURL%%.', 'bp-invite-anyone' ), $blogname ); /* Do not translate the strings embedded in %% ... %% ! */
} else {
$text = $iaoptions['default_invitation_message'];
}
if ( !is_admin() ) {
$text = invite_anyone_wildcard_replace( $text );
}
} else {
$text = $returned_message;
}
return apply_filters( 'invite_anyone_get_invitation_message', stripslashes( $text ) );
}
function invite_anyone_process_footer( $email ) {
$iaoptions = invite_anyone_options();
if ( empty( $iaoptions['addl_invitation_message'] ) ) {
$footer = apply_filters( 'invite_anyone_accept_invite_footer_message', __( 'To accept this invitation, please visit %%ACCEPTURL%%', 'bp-invite-anyone' ) );
$footer .= '
';
$footer .= apply_filters( 'invite_anyone_opt_out_footer_message', __( 'To opt out of future invitations to this site, please visit %%OPTOUTURL%%', 'bp-invite-anyone' ) );
} else {
$footer = $iaoptions['addl_invitation_message'];
}
return stripslashes( $footer );
}
function invite_anyone_wildcard_replace( $text, $email = false ) {
global $bp;
$inviter_name = $bp->loggedin_user->userdata->display_name;
$site_name = get_bloginfo('name');
$inviter_url = bp_loggedin_user_domain();
$accept_link = apply_filters( 'invite_anyone_accept_url', site_url( BP_REGISTER_SLUG ) . '/accept-invitation/' . urlencode($email) );
$opt_out_link = site_url( BP_REGISTER_SLUG ) . '/opt-out/' . urlencode( $email );
$text = str_replace( '%%INVITERNAME%%', $inviter_name, $text );
$text = str_replace( '%%INVITERURL%%', $inviter_url, $text );
$text = str_replace( '%%SITENAME%%', $site_name, $text );
$text = str_replace( '%%OPTOUTURL%%', $opt_out_link, $text );
$text = str_replace( '%%ACCEPTURL%%', $accept_link, $text );
/* Adding single % replacements because lots of people are making the mistake */
$text = str_replace( '%INVITERNAME%', $inviter_name, $text );
$text = str_replace( '%INVITERURL%', $inviter_url, $text );
$text = str_replace( '%SITENAME%', $site_name, $text );
$text = str_replace( '%OPTOUTURL%', $opt_out_link, $text );
$text = str_replace( '%ACCEPTURL%', $accept_link, $text );
return $text;
}
/**
* Get the max allowed invites
*/
function invite_anyone_max_invites() {
$options = invite_anyone_options();
return isset( $options['max_invites'] ) ? intval( $options['max_invites'] ) : false;
}
function invite_anyone_allowed_domains() {
$domains = '';
if ( function_exists( 'get_site_option' ) ) {
$limited_email_domains = get_site_option( 'limited_email_domains' );
if ( !$limited_email_domains || !is_array( $limited_email_domains ) )
return $domains;
foreach( $limited_email_domains as $domain )
$domains .= "<strong>$domain</strong> ";
}
return $domains;
}
/**
* Fetches the invitee taxonomy name out of the $bp global so it can be queried in the template
*
* @package Invite Anyone
* @since 0.8
*
* @return str $tax_name
*/
function invite_anyone_get_invitee_tax_name() {
global $bp;
$tax_name = '';
if ( !empty( $bp->invite_anyone->invitee_tax_name ) )
$tax_name = $bp->invite_anyone->invitee_tax_name;
return $tax_name;
}
/**
* Fetches the groups taxonomy name out of the $bp global so it can be queried in the template
*
* @package Invite Anyone
* @since 0.8
*
* @return str $tax_name
*/
function invite_anyone_get_invited_groups_tax_name() {
global $bp;
$tax_name = '';
if ( !empty( $bp->invite_anyone->invited_groups_tax_name ) )
$tax_name = $bp->invite_anyone->invited_groups_tax_name;
return $tax_name;
}
function invite_anyone_format_date( $date ) {
$thetime = strtotime( $date );
$format = get_option('date_format');
$thetime = date( "$format", $thetime );
return $thetime;
}
/**
* Parses email addresses, comma-separated or line-separated, into an array
*
* @package Invite Anyone
* @since 0.8.8
*
* @param str $address_string The raw string from the input box
* @return array $emails An array of addresses
*/
function invite_anyone_parse_addresses( $address_string ) {
$emails = array();
// First, split by line breaks
$rows = explode( "n", $address_string );
// Then look through each row to split by comma
foreach( $rows as $row ) {
$row_addresses = explode( ',', $row );
// Then walk through and add each address to the array
foreach( $row_addresses as $row_address ) {
$row_address_trimmed = trim( $row_address );
// We also have to make sure that the email address isn't empty
if ( ! empty( $row_address_trimmed ) && ! in_array( $row_address_trimmed, $emails ) )
$emails[] = $row_address_trimmed;
}
}
return apply_filters( 'invite_anyone_parse_addresses', $emails, $address_string );
}
function invite_anyone_process_invitations( $data ) {
global $bp;
$emails = false;
// Parse out the individual email addresses
if ( !empty( $data['invite_anyone_email_addresses'] ) ) {
$emails = invite_anyone_parse_addresses( $data['invite_anyone_email_addresses'] );
}
// Filter the email addresses so that plugins can have a field day
$emails = apply_filters( 'invite_anyone_submitted_email_addresses', $emails, $data );
// Set up a wrapper for any data to return to the Send Invites screen in case of error
$returned_data = array(
'error_message' => false,
'error_emails' => array(),
'subject' => $data['invite_anyone_custom_subject'],
'message' => $data['invite_anyone_custom_message'],
'groups' => isset( $data['invite_anyone_groups'] ) ? $data['invite_anyone_groups'] : ''
);
// Check against the max number of invites. Send back right away if there are too many
$options = invite_anyone_options();
$max_invites = !empty( $options['max_invites'] ) ? $options['max_invites'] : 5;
if ( count( $emails ) > $max_invites ) {
$returned_data['error_message'] = sprintf( __( 'You are only allowed to invite up to %s people at a time. Please remove some addresses and try again', 'bp-invite-anyone' ), $max_invites );
$returned_data['error_emails'] = $emails;
$redirect = bp_loggedin_user_domain() . $bp->invite_anyone->slug . '/invite-new-members' . invite_anyone_prepare_return_qs( $returned_data );
bp_core_redirect( $redirect );
}
if ( empty( $emails ) ) {
bp_core_add_message( __( 'You didn't include any email addresses!', 'bp-invite-anyone' ), 'error' );
bp_core_redirect( $bp->loggedin_user->domain . $bp->invite_anyone->slug . '/invite-new-members' );
}
// Max number of invites sent
$limit_total_invites = !empty( $options['email_limit_invites_toggle'] ) && 'no' != $options['email_limit_invites_toggle'];
if ( $limit_total_invites && !current_user_can( 'delete_others_pages' ) ) {
$sent_invites = invite_anyone_get_invitations_by_inviter_id( bp_loggedin_user_id() );
$sent_invites_count = (int) $sent_invites->post_count;
$remaining_invites_count = (int) $options['limit_invites_per_user'] - $sent_invites_count;
if ( count( $emails ) > $remaining_invites_count ) {
$returned_data['error_message'] = sprintf( __( 'You are only allowed to invite %s more people. Please remove some addresses and try again', 'bp-invite-anyone' ), $remaining_invites_count );
$returned_data['error_emails'] = $emails;
$redirect = bp_loggedin_user_domain() . $bp->invite_anyone->slug . '/invite-new-members' . invite_anyone_prepare_return_qs( $returned_data );
bp_core_redirect( $redirect );
}
}
// Turn the CS emails into an array so that they can be matched against the main list
if ( isset( $_POST['cloudsponge-emails'] ) ) {
$cs_emails = explode( ',', $_POST['cloudsponge-emails'] );
}
// validate email addresses
foreach( $emails as $key => $email ) {
$check = invite_anyone_validate_email( $email );
switch ( $check ) {
case 'opt_out' :
$returned_data['error_message'] .= sprintf( __( '<strong>%s</strong> has opted out of email invitations from this site.', 'bp-invite-anyone' ), $email );
break;
case 'used' :
$returned_data['error_message'] .= sprintf( __( "<strong>%s</strong> is already a registered user of the site.", 'bp-invite-anyone' ), $email );
break;
case 'unsafe' :
$returned_data['error_message'] .= sprintf( __( '<strong>%s</strong> is not a permitted email address.', 'bp-invite-anyone' ), $email );
break;
case 'invalid' :
$returned_data['error_message'] .= sprintf( __( '<strong>%s</strong> is not a valid email address. Please make sure that you have typed it correctly.', 'bp-invite-anyone' ), $email );
break;
case 'limited_domain' :
$returned_data['error_message'] = sprintf( __( '<strong>%s</strong> is not a permitted email address. Please make sure that you have typed the domain name correctly.', 'bp-invite-anyone' ), $email );
break;
}
// If there was an error in validation, we won't process this email
if ( $check != 'okay' ) {
$returned_data['error_message'] .= '<br />';
$returned_data['error_emails'][] = $email;
unset( $emails[$key] );
}
}
if ( ! empty( $emails ) ) {
unset( $message, $to );
/* send and record invitations */
do_action( 'invite_anyone_process_addl_fields' );
$groups = ! empty( $data['invite_anyone_groups'] ) ? $data['invite_anyone_groups'] : array();
$is_error = 0;
foreach( $emails as $email ) {
$subject = stripslashes( strip_tags( $data['invite_anyone_custom_subject'] ) );
$message = stripslashes( strip_tags( $data['invite_anyone_custom_message'] ) );
$footer = invite_anyone_process_footer( $email );
$footer = invite_anyone_wildcard_replace( $footer, $email );
$message .= '
================
';
$message .= $footer;
$to = apply_filters( 'invite_anyone_invitee_email', $email );
$subject = apply_filters( 'invite_anyone_invitation_subject', $subject );
$message = apply_filters( 'invite_anyone_invitation_message', $message );
wp_mail( $to, $subject, $message );
/* todo: isolate which email(s) cause problems, and send back to user */
/* if ( !invite_anyone_send_invitation( $bp->loggedin_user->id, $email, $message, $groups ) )
$is_error = 1; */
// Determine whether this address came from CloudSponge
$is_cloudsponge = isset( $cs_emails ) && in_array( $email, $cs_emails ) ? true : false;
invite_anyone_record_invitation( $bp->loggedin_user->id, $email, $message, $groups, $subject, $is_cloudsponge );
do_action( 'sent_email_invite', $bp->loggedin_user->id, $email, $groups );
unset( $message, $to );
}
// Set a success message
$success_message = sprintf( __( "Invitations were sent successfully to the following email addresses: %s", 'bp-invite-anyone' ), implode( ", ", $emails ) );
bp_core_add_message( $success_message );
do_action( 'sent_email_invites', $bp->loggedin_user->id, $emails, $groups );
} else {
$success_message = sprintf( __( "Please correct your errors and resubmit.", 'bp-invite-anyone' ) );
bp_core_add_message( $success_message, 'error' );
}
// If there are errors, redirect to the Invite New Members page
if ( ! empty( $returned_data['error_emails'] ) ) {
$redirect = bp_loggedin_user_domain() . $bp->invite_anyone->slug . '/invite-new-members' . invite_anyone_prepare_return_qs( $returned_data );
bp_core_redirect( $redirect );
}
return true;
}
function invite_anyone_prepare_return_qs( $returned_data ) {
$qs = '';
foreach( $returned_data as $key => $value ) {
/*if ( is_array( $value ) ) {
$key .= '[]';
}*/
$qs = add_query_arg( $key, $value, $qs );
}
return $qs;
}
function invite_anyone_send_invitation( $inviter_id, $email, $message, $groups ) {
global $bp;
}
function invite_anyone_bypass_registration_lock() {
global $bp;
if ( $bp->current_component != BP_REGISTER_SLUG || $bp->current_action != 'accept-invitation' )
return;
if ( !isset( $bp->action_variables[0] ) || !$email = urldecode( $bp->action_variables[0] ) )
return;
$options = invite_anyone_options();
if ( empty( $options['bypass_registration_lock'] ) || $options['bypass_registration_lock'] != 'yes' )
return;
// Check to make sure that it's actually a valid email
$ia_obj = invite_anyone_get_invitations_by_invited_email( $email );
if ( !$ia_obj->have_posts() ) {
bp_core_add_message( __( "We couldn't find any invitations associated with this email address.", 'bp-invite-anyone' ), 'error' );
return;
}
// This is a royal hack until there is a filter on bp_get_signup_allowed()
if ( is_multisite() ) {
if ( !empty( $bp->site_options['registration'] ) && $bp->site_options['registration'] == 'blog' ) {
$bp->site_options['registration'] = 'all';
} else if ( !empty( $bp->site_options['registration'] ) && $bp->site_options['registration'] == 'none' ) {
$bp->site_options['registration'] = 'user';
}
} else {
add_filter( 'option_users_can_register', create_function( false, 'return true;' ) );
}
}
add_action( 'wp', 'invite_anyone_bypass_registration_lock', 1 );
function invite_anyone_validate_email( $user_email ) {
$status = 'okay';
if ( invite_anyone_check_is_opt_out( $user_email ) ) {
$status = 'opt_out';
} else if ( $user = get_user_by( 'email', $user_email ) ) {
$status = 'used';
} else if ( function_exists( 'is_email_address_unsafe' ) && is_email_address_unsafe( $user_email ) ) {
$status = 'unsafe';
} else if ( function_exists( 'is_email' ) && !is_email( $user_email ) ) {
$status = 'invalid';
}
if ( function_exists( 'get_site_option' ) ) {
if ( $limited_email_domains = get_site_option( 'limited_email_domains' ) ) {
if ( is_array( $limited_email_domains ) && empty( $limited_email_domains ) == false ) {
$emaildomain = substr( $user_email, 1 + strpos( $user_email, '@' ) );
if( in_array( $emaildomain, $limited_email_domains ) == false ) {
$status = 'limited_domain';
}
}
}
}
return apply_filters( 'invite_anyone_validate_email', $status, $user_email );
}
?>
</pre>
-
This topic was modified 3 years, 11 months ago by
Robert Nava.
-
This topic was modified 3 years, 11 months ago by
Robert Nava.