latest stable versions: v150827 (changelog)

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Plugin disables my invite anyone plugin

Home Forums Community Forum Plugin disables my invite anyone plugin

This topic contains 4 replies, has 2 voices. Last updated by  Robert Nava 3 years, 11 months ago.

Topic Author Topic
Posted: Monday Jan 14th, 2013 at 7:11 pm #37543

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] ) : ?&gt;
				
				jQuery(document).ready( function() {
					jQuery("input#opt_out_email").val("");
				});
				
			

			&lt;form action=&quot;/submit" method="post"&gt;

				

				<p></p>

				<p></p>

				

				
				<p> </p>

				<p>&lt;input type=&quot;submit&quot; name=&quot;opt_out_submit&quot; value=&quot;" /&gt; &lt;input type=&quot;submit&quot; name=&quot;oops_submit&quot; value=&quot;" /&gt;
				</p>

			
		
		
		

	current_action ) &amp;&amp; $bp-&gt;current_action == 'accept-invitation' &amp;&amp; empty( $bp-&gt;action_variables[0] ) ) : ?&gt;
		<p></p>
	

	signup-&gt;step == 'request-details' &amp;&amp; $bp-&gt;current_action == 'accept-invitation' &amp;&amp; $email = urldecode( $bp-&gt;action_variables[0] ) ) : ?&gt;

		

		
		jQuery(document).ready( function() {
			jQuery("input#signup_email").val("");
		});

		


		have_posts() ) {
				while ( $ia_obj-&gt;have_posts() ) {
					$ia_obj-&gt;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 &lt; count( $inviters ) - 1 ) {
					$inviters_text .= &#039;, &#039; . bp_core_get_user_displayname( $inviters[$counter] );
					$counter++;
				}
				$inviters_text .= &#039; and &#039; . bp_core_get_user_displayname( $inviters[$counter] );
			}

			if ( !empty( $inviters_text ) ) {
				$message = sprintf( __( &#039;Welcome! You&#039;ve been invited %s to join the site. Please fill out the information below to create your account.&#039;, &#039;bp-invite-anyone&#039; ), $inviters_text );
				echo &#039;<p>' . $message . '</p>';
			}

		?&gt;

	
have_posts() ) {
		// From the posts returned by the query, get a list of unique inviters
		$inviters 	= array();
		$groups		= array();
		while ( $invites-&gt;have_posts() ) {
			$invites-&gt;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-&gt;name] ) ) {
					// Keyed by inviter, which means they'll only get one invite per group
					$groups[$group_data-&gt;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' =&gt; $user_id, 'follower_id' =&gt; $inviter ) );
				bp_follow_start_following( array( 'leader_id' =&gt; $inviter, 'follower_id' =&gt; $user_id ) );
			}
		}

		// Group invitations
		if ( bp_is_active( 'groups' ) ) {
			foreach ( $groups as $group_id =&gt; $inviter_id ) {
				$args = array(
					'user_id' =&gt; $user_id,
					'group_id' =&gt; $group_id,
					'inviter_id' =&gt; $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' =&gt; __( 'Send Invites', 'buddypress' ),
		'slug' =&gt; $bp-&gt;invite_anyone-&gt;slug,
		'position' =&gt; 80,
		'screen_function' =&gt; 'invite_anyone_screen_one',
		'default_subnav_slug' =&gt; 'invite-new-members',
		'show_for_displayed_user' =&gt; invite_anyone_access_test()
	) );

	$invite_anyone_link = $bp-&gt;loggedin_user-&gt;domain . $bp-&gt;invite_anyone-&gt;slug . '/';

	/* Create two sub nav items for this component */
	bp_core_new_subnav_item( array(
		'name' =&gt; __( 'Invite New Members', 'bp-invite-anyone' ),
		'slug' =&gt; 'invite-new-members',
		'parent_slug' =&gt; $bp-&gt;invite_anyone-&gt;slug,
		'parent_url' =&gt; $invite_anyone_link,
		'screen_function' =&gt; 'invite_anyone_screen_one',
		'position' =&gt; 10,
		'user_has_access' =&gt; invite_anyone_access_test()
	) );

	bp_core_new_subnav_item( array(
		'name' =&gt; __( 'Sent Invites', 'bp-invite-anyone' ),
		'slug' =&gt; 'sent-invites',
		'parent_slug' =&gt; $bp-&gt;invite_anyone-&gt;slug,
		'parent_url' =&gt; $invite_anyone_link,
		'screen_function' =&gt; 'invite_anyone_screen_two',
		'position' =&gt; 20,
		'user_has_access' =&gt; 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() &amp;&amp; !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'] ) &amp;&amp; $iaoptions['email_visibility_toggle'] == 'no_limit' )
		return true;

	/* Minimum number of days since joined the site */
	if ( isset( $iaoptions['email_since_toggle'] ) &amp;&amp; $iaoptions['email_since_toggle'] == 'yes' ) {
		if ( isset( $iaoptions['days_since'] ) &amp;&amp; $since = $iaoptions['days_since'] ) {
			$since = $since * 86400;

			$date_registered = strtotime($current_user-&gt;data-&gt;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-&gt;invite_anyone-&gt;returned_data[$key] = null;
		if ( isset( $_GET[$key] ) ) {
			if ( is_array( $_GET[$key] ) ) {
				$value = array();
				foreach( $_GET[$key] as $kk =&gt; $vv ) {
					$value[$kk] = urldecode( $vv );
				}
			} else {
				$value = urldecode( $_GET[$key] );
			}
			$bp-&gt;invite_anyone-&gt;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' =&gt; $inviter_id, 'clear_id' =&gt; $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' =&gt; $inviter_id, 'type' =&gt; $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-&gt;displayed_user-&gt;domain . $bp-&gt;invite_anyone-&gt;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'] ) &amp;&amp; $iaoptions['email_limit_invites_toggle'] == 'yes' &amp;&amp; !current_user_can( 'delete_others_pages' ) ) {
		$sent_invites       = invite_anyone_get_invitations_by_inviter_id( bp_displayed_user_id() );
		$sent_invites_count  = $sent_invites-&gt;post_count;
		if ( $sent_invites_count &gt;= $iaoptions['limit_invites_per_user'] ) : ?&gt;

			<h4></h4>

			<p></p>

			action_variables ) ) {
		if ( 'group-invites' == $bp-&gt;action_variables[0] )
			$from_group = $bp-&gt;action_variables[1];
	}

	$returned_data = !empty( $bp-&gt;invite_anyone-&gt;returned_data ) ? $bp-&gt;invite_anyone-&gt;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-&gt;loggedin_user-&gt;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'] ) ) {
		?&gt;
		
			<p></p>
		
		
	&lt;form id=&quot;invite-anyone-by-email&quot; action=&quot;displayed_user-&gt;domain . $bp-&gt;invite_anyone-&gt;slug . '/sent-invites/send/' ?&gt;" method="post"&gt;

	<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>
			
				
					
			
				&lt; ?php _e( &#039;Subject: Subject line is fixed', 'bp-invite-anyone' ) ?&gt;
					 

				&lt;input type=&quot;hidden&quot; id=&quot;invite-anyone-customised-subject&quot; name=&quot;invite_anyone_custom_subject&quot; value=&quot;" /&gt;
			
		</li>

		<li>
			
				
				<p></p>
					
			
				
					

				&lt;input type=&quot;hidden&quot; name=&quot;invite_anyone_custom_message&quot; value=&quot;" /&gt;
			

		</li>

		
			
			<li>
				<p></p>
				<ul>
					
						<li>
						&lt;input type=&quot;checkbox&quot; name=&quot;invite_anyone_groups[]&quot; id=&quot;invite_anyone_groups-" value="" checked /&gt;

						&lt;label for=&quot;invite_anyone_groups-" class="invite-anyone-group-name"&gt; 

						</li>
					

				</ul>
			</li>
			

		

		

	</ol>

	
		&lt;input type=&quot;submit&quot; name=&quot;invite-anyone-submit&quot; id=&quot;invite-anyone-submit&quot; value=&quot; " /&gt;
	


	
	current_component == $bp-&gt;invite_anyone-&gt;slug &amp;&amp; $bp-&gt;current_action == 'sent-invites' &amp;&amp; isset( $bp-&gt;action_variables[0] ) &amp;&amp; $bp-&gt;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-&gt;displayed_user-&gt;domain . $bp-&gt;invite_anyone-&gt;slug . '/sent-invites/';

		?&gt;

		<h4></h4>

		get_per_page, $pagination-&gt;get_paged ) ?&gt;

		setup_query( $invites ) ?&gt;

		have_posts() ) : ?&gt;
			<p></p>

			
				
					currently_viewing_text() ?&gt;
				

				
					paginate_links() ?&gt;
				
			

			&lt;table class=&quot;invite-anyone-sent-invites zebra&quot;
			summary=&quot;"&gt;
				<thead>
					<tr>
					  <th></th>
					  &lt;th scope=&quot;col&quot; class="sort-by-me"&gt;&lt;a class=&quot;" title="Sort column order " href="?sort_by=email&amp;order=DESCASC"&gt;</a></th>
					  <th></th>
					  &lt;th scope=&quot;col&quot; class="sort-by-me"&gt;&lt;a class=&quot;" title="Sort column order " href="?sort_by=date_invited&amp;order=ASCDESC"&gt;</a></th>
					  &lt;th scope=&quot;col&quot; class="sort-by-me"&gt;&lt;a class=&quot;" title="Sort column order " href="?sort_by=date_joined&amp;order=ASCDESC"&gt;</a></th>
					</tr>
				</thead>

				<tfoot>
				<tr>
				  <td>
				   <ul>
				      <li> &lt;a title=&quot;" class="confirm" href=""&gt;</a></li>
				      <li>&lt;a title=&quot;" class="confirm" href=""&gt;</a></li>
				  </ul>
				 </td>
				</tr>
				</tfoot>

				<tbody>
				have_posts() ) : $invites-&gt;the_post() ?&gt;

				name;

					$post_id = get_the_ID();

					$query_string = preg_replace( "|clear=[0-9]+|", '', $_SERVER['QUERY_STRING'] );

					$clear_url = ( $query_string ) ? $base_url . '?' . $query_string . '&amp;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-&gt;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-&gt;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;

					?&gt;

					&lt;tr  class="accepted" &gt;
						<td></td>
						<td></td>
						<td></td>
						<td></td>
						<td></td>
					</tr>
				
			 </tbody>
			</table>

			
				
					currently_viewing_text() ?&gt;
				

				
					paginate_links() ?&gt;
				
			


		

		<p></p>

		
	
	
loggedin_user-&gt;userdata-&gt;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-&gt;loggedin_user-&gt;userdata-&gt;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-&gt;invite_anyone-&gt;invitee_tax_name ) )
		$tax_name = $bp-&gt;invite_anyone-&gt;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-&gt;invite_anyone-&gt;invited_groups_tax_name ) )
		$tax_name = $bp-&gt;invite_anyone-&gt;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 ) &amp;&amp; ! 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' =&gt; false,
		'error_emails'  =&gt; array(),
		'subject' 	=&gt; $data['invite_anyone_custom_subject'],
		'message' 	=&gt; $data['invite_anyone_custom_message'],
		'groups' 	=&gt; 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 ) &gt; $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-&gt;invite_anyone-&gt;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-&gt;loggedin_user-&gt;domain . $bp-&gt;invite_anyone-&gt;slug . '/invite-new-members' );
	}

	// Max number of invites sent
	$limit_total_invites = !empty( $options['email_limit_invites_toggle'] ) &amp;&amp; 'no' != $options['email_limit_invites_toggle'];
	if ( $limit_total_invites &amp;&amp; !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-&gt;post_count;
		$remaining_invites_count = (int) $options['limit_invites_per_user'] - $sent_invites_count;

		if ( count( $emails ) &gt; $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-&gt;invite_anyone-&gt;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 =&gt; $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-&gt;loggedin_user-&gt;id, $email, $message, $groups ) )
				$is_error = 1; */

			// Determine whether this address came from CloudSponge
			$is_cloudsponge = isset( $cs_emails ) &amp;&amp; in_array( $email, $cs_emails ) ? true : false;

			invite_anyone_record_invitation( $bp-&gt;loggedin_user-&gt;id, $email, $message, $groups, $subject, $is_cloudsponge );

			do_action( 'sent_email_invite', $bp-&gt;loggedin_user-&gt;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-&gt;loggedin_user-&gt;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-&gt;invite_anyone-&gt;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 =&gt; $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-&gt;current_component != BP_REGISTER_SLUG || $bp-&gt;current_action != 'accept-invitation' )
		return;

	if ( !isset( $bp-&gt;action_variables[0] ) || !$email = urldecode( $bp-&gt;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-&gt;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-&gt;site_options['registration'] ) &amp;&amp; $bp-&gt;site_options['registration'] == 'blog' ) {
			$bp-&gt;site_options['registration'] = 'all';
		} else if ( !empty( $bp-&gt;site_options['registration'] ) &amp;&amp; $bp-&gt;site_options['registration'] == 'none' ) {
			$bp-&gt;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' ) &amp;&amp; is_email_address_unsafe( $user_email ) ) {
		$status = 'unsafe';
	} else if ( function_exists( 'is_email' ) &amp;&amp; !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 ) &amp;&amp; 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 );
}

?&gt;
</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.

List Of Topic Replies

Viewing 4 replies - 1 through 4 (of 4 total)
Author Replies
Author Replies
Posted: Monday Jan 14th, 2013 at 8:53 pm #37551
Staff Member

Thanks for your inquiry. ~ We appreciate your patience :-)

I’m sorry, but we are unable to provide support for custom code or general WordPress funtionality. Please see our policy here for some clarification on this. Thanks! s2Member® » Support Policy » Within Scope

If you have a specific question that pertains to s2Member, we’ll be happy to help (i.e. a particular hook/filter, or something related to s2Member’s functionality is fine). We just can’t offer support for custom code that integrates with something we do not provide.

Posted: Monday Jan 14th, 2013 at 9:51 pm #37559

I understand Jason. You answered this forum post here http://www.s2member.com/forums/topic/bypass-closed-registration-for-current-user/ Can you explain how to use code that you provided in that thread?

Posted: Tuesday Jan 15th, 2013 at 11:13 am #37579
Staff Member

Thanks for your reply :-)

The code sample I provided in that thread is showing an example of how you might close Open Registration on your site dynamically through code, based on some condition that you have on-site.

Please create this directory and file:
/wp-content/mu-plugins/s2-hacks.php
(NOTE: these are MUST USE plugins, see: http://codex.wordpress.org/Must_Use_Plugins)
(See also: http://www.s2member.com/kb/hacking-s2member/)

<?php
add_filter("ws_plugin__s2member_check_register_access", "my_function");
function my_function($users_can_register)
	{
		if($something_allows_a_user_to_register)
			return /* Yes, they can register. */ "1";
			
		else /* Whatever s2Member says already. */
			return $users_can_register;
	}
?>

See Also: s2Member/Options_Forces
See Also: Hooks/Filters in this class package

Open Registration? See: Dashboard -› s2Member® -› General Options -› Open Registration

Posted: Wednesday Jan 16th, 2013 at 1:58 pm #37815

When I added this function it still says registration is not open. I’ve also run into other problems that I can’t fix.

Viewing 4 replies - 1 through 4 (of 4 total)

This topic is closed to new replies. Topics with no replies for 2 weeks are closed automatically.

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Contacting s2Member: Please use our Support Center for bug reports, pre-sale questions & technical assistance.