PageRenderTime 57ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/wordpress/wp-content/plugins/invite-anyone/by-email/by-email.php

http://ownerpress.googlecode.com/
PHP | 1190 lines | 910 code | 211 blank | 69 comment | 152 complexity | 90d21767c9bf2b0e9a0b6aa0e3b7d694 MD5 | raw file
Possible License(s): Apache-2.0, AGPL-1.0, GPL-2.0, GPL-3.0, LGPL-2.1
  1. <?php
  2. require( WP_PLUGIN_DIR . '/invite-anyone/by-email/by-email-db.php' );
  3. require( WP_PLUGIN_DIR . '/invite-anyone/widgets/widgets.php' );
  4. require( WP_PLUGIN_DIR . '/invite-anyone/by-email/cloudsponge-integration.php' );
  5. // Temporary function until bp_is_active is fully integrated
  6. function invite_anyone_are_groups_running() {
  7. if ( function_exists( 'groups_install' ) )
  8. return true;
  9. if ( function_exists( 'bp_is_active' ) ) {
  10. if ( bp_is_active( 'groups' ) )
  11. return true;
  12. }
  13. return false;
  14. }
  15. function invite_anyone_add_by_email_css() {
  16. global $bp;
  17. if ( $bp->current_component == BP_INVITE_ANYONE_SLUG ) {
  18. $style_url = WP_PLUGIN_URL . '/invite-anyone/by-email/by-email-css.css';
  19. $style_file = WP_PLUGIN_DIR . '/invite-anyone/by-email/by-email-css.css';
  20. if (file_exists($style_file)) {
  21. wp_register_style('invite-anyone-by-email-style', $style_url);
  22. wp_enqueue_style('invite-anyone-by-email-style');
  23. }
  24. }
  25. }
  26. add_action( 'wp_print_styles', 'invite_anyone_add_by_email_css' );
  27. function invite_anyone_add_by_email_js() {
  28. global $bp;
  29. if ( $bp->current_component == BP_INVITE_ANYONE_SLUG ) {
  30. $style_url = WP_PLUGIN_URL . '/invite-anyone/by-email/by-email-js.js';
  31. $style_file = WP_PLUGIN_DIR . '/invite-anyone/by-email/by-email-js.js';
  32. if (file_exists($style_file)) {
  33. wp_register_script('invite-anyone-by-email-scripts', $style_url);
  34. wp_enqueue_script('invite-anyone-by-email-scripts');
  35. }
  36. }
  37. }
  38. add_action( 'wp_print_scripts', 'invite_anyone_add_by_email_js' );
  39. function invite_anyone_setup_globals() {
  40. global $bp, $wpdb;
  41. $bp->invite_anyone->id = 'invite_anyone';
  42. $bp->invite_anyone->table_name = $wpdb->base_prefix . 'bp_invite_anyone';
  43. $bp->invite_anyone->slug = 'invite-anyone';
  44. /* Register this in the active components array */
  45. $bp->active_components[$bp->invite_anyone->slug] = $bp->invite_anyone->id;
  46. }
  47. add_action( 'bp_setup_globals', 'invite_anyone_setup_globals', 2 );
  48. function invite_anyone_opt_out_screen() {
  49. global $bp;
  50. if ( isset( $_POST['oops_submit'] ) ) {
  51. bp_core_redirect( site_url( BP_REGISTER_SLUG ) . '/accept-invitation/' . urlencode( $_POST['opt_out_email'] ) );
  52. }
  53. $opt_out_button_text = __( 'Opt Out', 'bp-invite-anyone' );
  54. $oops_button_text = __( 'Accept Invitation', 'bp-invite-anyone' );
  55. $sitename = get_bloginfo( 'name' );
  56. $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 );
  57. $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 );
  58. if ( $bp->current_component == BP_REGISTER_SLUG && $bp->current_action == 'opt-out' ) {
  59. get_header();
  60. ?>
  61. <div id="content">
  62. <div class="padder">
  63. <?php if ( $bp->action_variables[1] == 'submit' ) : ?>
  64. <?php if ( $_POST['opt_out_submit'] == $opt_out_button_text && $email = urldecode( $_POST['opt_out_email'] ) ) : ?>
  65. <?php check_admin_referer( 'invite_anyone_opt_out' ) ?>
  66. <?php if ( invite_anyone_mark_as_opt_out( $email ) ) : ?>
  67. <?php $opted_out_message = __( 'You have successfully opted out. No more invitation emails will be sent to you by this site.', 'bp-invite-anyone' ) ?>
  68. <p><?php echo $opted_out_message ?></p>
  69. <?php else : ?>
  70. <p><?php _e( 'Sorry, there was an error in processing your request', 'bp-invite-anyone' ) ?></p>
  71. <?php endif; ?>
  72. <?php else : ?>
  73. <?php /* I guess this should be some sort of error message? */ ?>
  74. <?php endif; ?>
  75. <?php else : ?>
  76. <?php if ( $email = $bp->action_variables[0] ) : ?>
  77. <script type="text/javascript">
  78. jQuery(document).ready( function() {
  79. jQuery("input#opt_out_email").val("<?php echo urldecode($email) ?>");
  80. });
  81. </script>
  82. <?php endif; ?>
  83. <form action="<?php echo $email ?>/submit" method="post">
  84. <?php do_action( 'invite_anyone_before_optout_messages' ) ?>
  85. <p><?php echo $opt_out_message ?></p>
  86. <p><?php echo $oops_message ?></p>
  87. <?php do_action( 'invite_anyone_after_optout_messages' ) ?>
  88. <?php wp_nonce_field( 'invite_anyone_opt_out' ) ?>
  89. <p><?php _e( 'Email:', 'bp-invite-anyone' ) ?> <input type="text" id="opt_out_email" name="opt_out_email" size="50" /></p>
  90. <p><input type="submit" name="opt_out_submit" value="<?php echo $opt_out_button_text ?>" /> <input type="submit" name="oops_submit" value="<?php echo $oops_button_text ?>" />
  91. </p>
  92. </form>
  93. <?php endif; ?>
  94. </div>
  95. </div>
  96. <?php
  97. get_footer();
  98. die();
  99. }
  100. }
  101. add_action( 'wp', 'invite_anyone_opt_out_screen', 1 );
  102. function invite_anyone_register_screen_message() {
  103. global $bp;
  104. ?>
  105. <?php if ( isset( $bp->current_action ) && $bp->current_action == 'accept-invitation' && empty( $bp->action_variables[0] ) ) : ?>
  106. <div id="message" class="error"><p><?php _e( "It looks like you're trying to accept an invitation to join the site, but some information is missing. Please try again by clicking on the link in the invitation email.", 'bp-invite-anyone' ) ?></p></div>
  107. <?php endif; ?>
  108. <?php if ( $bp->signup->step == 'request-details' && $bp->current_action == 'accept-invitation' && $email = urldecode( $bp->action_variables[0] ) ) : ?>
  109. <?php do_action( 'accept_email_invite_before' ) ?>
  110. <script type="text/javascript">
  111. jQuery(document).ready( function() {
  112. jQuery("input#signup_email").val("<?php echo $email ?>");
  113. });
  114. </script>
  115. <?php
  116. $ia_obj = invite_anyone_get_invitations_by_invited_email( $email );
  117. $inviters = array();
  118. if ( $ia_obj->have_posts() ) {
  119. while ( $ia_obj->have_posts() ) {
  120. $ia_obj->the_post();
  121. $inviters[] = get_the_author_meta( 'ID' );
  122. }
  123. }
  124. $inviters = array_unique( $inviters );
  125. $inviters_text = '';
  126. if ( count( $inviters ) == 0 ) {
  127. $inviters_text = '';
  128. } else if ( count( $inviters ) == 1 ) {
  129. $inviters_text .= 'by ';
  130. $inviters_text .= bp_core_get_user_displayname( $inviters[0] );
  131. } else {
  132. $counter = 1;
  133. $inviters_text .= 'by ';
  134. $inviters_text .= bp_core_get_user_displayname( $inviters[0] );
  135. while ( $counter < count( $inviters ) - 1 ) {
  136. $inviters_text .= ', ' . bp_core_get_user_displayname( $inviters[$counter] );
  137. $counter++;
  138. }
  139. $inviters_text .= ' and ' . bp_core_get_user_displayname( $inviters[$counter] );
  140. }
  141. if ( !empty( $inviters_text ) ) {
  142. $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 );
  143. echo '<div id="message" class="success"><p>' . $message . '</p></div>';
  144. }
  145. ?>
  146. <?php endif; ?>
  147. <?php
  148. }
  149. add_action( 'bp_before_register_page', 'invite_anyone_register_screen_message' );
  150. function invite_anyone_activate_user( $user_id, $key, $user ) {
  151. global $bp;
  152. $email = bp_core_get_user_email( $user_id );
  153. // Fire the query
  154. $invites = invite_anyone_get_invitations_by_invited_email( $email );
  155. if ( $invites->have_posts() ) {
  156. // From the posts returned by the query, get a list of unique inviters
  157. $inviters = array();
  158. $groups = array();
  159. while ( $invites->have_posts() ) {
  160. $invites->the_post();
  161. $inviter_id = get_the_author_meta( 'ID' );
  162. $inviters[] = $inviter_id;
  163. $groups_data = wp_get_post_terms( get_the_ID(), invite_anyone_get_invited_groups_tax_name() );
  164. foreach ( $groups_data as $group_data ) {
  165. if ( !isset( $groups[$group_data->name] ) ) {
  166. // Keyed by inviter, which means they'll only get one invite per group
  167. $groups[$group_data->name] = $inviter_id;
  168. }
  169. }
  170. // Mark as accepted
  171. update_post_meta( get_the_ID(), 'bp_ia_accepted', date( 'Y-m-d H:i:s' ) );
  172. }
  173. $inviters = array_unique( $inviters );
  174. // Friendship requests
  175. if ( bp_is_active( 'friends' ) ) {
  176. if ( function_exists( 'friends_add_friend' ) ) {
  177. foreach ( $inviters as $inviter ) {
  178. friends_add_friend( $inviter, $user_id );
  179. }
  180. }
  181. }
  182. // BuddyPress Followers support
  183. if ( function_exists( 'bp_follow_start_following' ) ) {
  184. foreach ( $inviters as $inviter ) {
  185. bp_follow_start_following( array( 'leader_id' => $user_id, 'follower_id' => $inviter ) );
  186. bp_follow_start_following( array( 'leader_id' => $inviter, 'follower_id' => $user_id ) );
  187. }
  188. }
  189. // Group invitations
  190. if ( bp_is_active( 'groups' ) ) {
  191. foreach ( $groups as $group_id => $inviter_id ) {
  192. $args = array(
  193. 'user_id' => $user_id,
  194. 'group_id' => $group_id,
  195. 'inviter_id' => $inviter_id
  196. );
  197. groups_invite_user( $args );
  198. groups_send_invites( $inviter_id, $group_id );
  199. }
  200. }
  201. }
  202. do_action( 'accepted_email_invite', $user_id, $inviters );
  203. }
  204. add_action( 'bp_core_activated_user', 'invite_anyone_activate_user', 10, 3 );
  205. function invite_anyone_setup_nav() {
  206. global $bp;
  207. if ( !invite_anyone_access_test() )
  208. return;
  209. /* Add 'Send Invites' to the main user profile navigation */
  210. bp_core_new_nav_item( array(
  211. 'name' => __( 'Send Invites', 'buddypress' ),
  212. 'slug' => $bp->invite_anyone->slug,
  213. 'position' => 80,
  214. 'screen_function' => 'invite_anyone_screen_one',
  215. 'default_subnav_slug' => 'invite-new-members',
  216. 'show_for_displayed_user' => invite_anyone_access_test()
  217. ) );
  218. $invite_anyone_link = $bp->loggedin_user->domain . $bp->invite_anyone->slug . '/';
  219. /* Create two sub nav items for this component */
  220. bp_core_new_subnav_item( array(
  221. 'name' => __( 'Invite New Members', 'bp-invite-anyone' ),
  222. 'slug' => 'invite-new-members',
  223. 'parent_slug' => $bp->invite_anyone->slug,
  224. 'parent_url' => $invite_anyone_link,
  225. 'screen_function' => 'invite_anyone_screen_one',
  226. 'position' => 10,
  227. 'user_has_access' => invite_anyone_access_test()
  228. ) );
  229. bp_core_new_subnav_item( array(
  230. 'name' => __( 'Sent Invites', 'bp-invite-anyone' ),
  231. 'slug' => 'sent-invites',
  232. 'parent_slug' => $bp->invite_anyone->slug,
  233. 'parent_url' => $invite_anyone_link,
  234. 'screen_function' => 'invite_anyone_screen_two',
  235. 'position' => 20,
  236. 'user_has_access' => invite_anyone_access_test()
  237. ) );
  238. }
  239. add_action( 'bp_setup_nav', 'invite_anyone_setup_nav' );
  240. function invite_anyone_access_test() {
  241. global $current_user, $bp;
  242. if ( !is_user_logged_in() )
  243. return false;
  244. if ( bp_displayed_user_id() && !bp_is_my_profile() )
  245. return false;
  246. $iaoptions = invite_anyone_options();
  247. /* This is the last of the general checks: logged in, looking at own profile, and finally admin has set to "All Users".*/
  248. if ( isset( $iaoptions['email_visibility_toggle'] ) && $iaoptions['email_visibility_toggle'] == 'no_limit' )
  249. return true;
  250. /* Minimum number of days since joined the site */
  251. if ( isset( $iaoptions['email_since_toggle'] ) && $iaoptions['email_since_toggle'] == 'yes' ) {
  252. if ( isset( $iaoptions['days_since'] ) && $since = $iaoptions['days_since'] ) {
  253. $since = $since * 86400;
  254. $date_registered = strtotime($current_user->data->user_registered);
  255. $time = time();
  256. if ( $time - $date_registered < $since )
  257. return false;
  258. }
  259. }
  260. /* Minimum role on this blog. Users who are at the necessary role or higher should move right through this toward the 'return true' at the end of the function. */
  261. if ( isset( $iaoptions['email_role_toggle'] ) && $iaoptions['email_role_toggle'] == 'yes' ) {
  262. if ( isset( $iaoptions['minimum_role'] ) && $role = $iaoptions['minimum_role'] ) {
  263. switch ( $role ) {
  264. case 'Subscriber' :
  265. if ( !current_user_can( 'read' ) )
  266. return false;
  267. break;
  268. case 'Contributor' :
  269. if ( !current_user_can( 'edit_posts' ) )
  270. return false;
  271. break;
  272. case 'Author' :
  273. if ( !current_user_can( 'publish_posts' ) )
  274. return false;
  275. break;
  276. case 'Editor' :
  277. if ( !current_user_can( 'delete_others_pages' ) )
  278. return false;
  279. break;
  280. case 'Administrator' :
  281. if ( !current_user_can( 'switch_themes' ) )
  282. return false;
  283. break;
  284. }
  285. }
  286. }
  287. /* User blacklist */
  288. if ( isset( $iaoptions['email_blacklist_toggle'] ) && $iaoptions['email_blacklist_toggle'] == 'yes' ) {
  289. if ( isset( $iaoptions['email_blacklist'] ) ) {
  290. $blacklist = explode( ",", $iaoptions['email_blacklist'] );
  291. $user_id = $current_user->ID;
  292. if ( in_array( $user_id, $blacklist ) )
  293. return false;
  294. }
  295. }
  296. return true;
  297. }
  298. add_action( 'wp_head', 'invite_anyone_access_test' );
  299. function invite_anyone_catch_clear() {
  300. global $bp;
  301. // We'll take a moment nice and early in the loading process to get returned_data
  302. // out of the cookie.
  303. // Get any returned data out of the cookie. It will need to be unserialized before use
  304. $bp->invite_anyone->returned_data = ! empty( $_COOKIE['invite-anyone-error-data'] ) ? maybe_unserialize( stripslashes( $_COOKIE['invite-anyone-error-data'] ) ) : array();
  305. // Unset the cookie right away so that you don't get old data when returning to the page
  306. setcookie( 'invite-anyone-error-data', ' ', time() - 360000, COOKIEPATH, COOKIE_DOMAIN );
  307. if ( isset( $_GET['clear'] ) ) {
  308. $clear_id = $_GET['clear'];
  309. $inviter_id = bp_loggedin_user_id();
  310. check_admin_referer( 'invite_anyone_clear' );
  311. if ( (int)$clear_id ) {
  312. if ( invite_anyone_clear_sent_invite( array( 'inviter_id' => $inviter_id, 'clear_id' => $clear_id ) ) )
  313. bp_core_add_message( __( 'Invitation cleared', 'bp-invite-anyone' ) );
  314. else
  315. bp_core_add_message( __( 'There was a problem clearing the invitation.', 'bp-invite-anyone' ), 'error' );
  316. } else {
  317. if ( invite_anyone_clear_sent_invite( array( 'inviter_id' => $inviter_id, 'type' => $clear_id ) ) )
  318. bp_core_add_message( __( 'Invitations cleared.', 'bp-invite-anyone' ) );
  319. else
  320. bp_core_add_message( __( 'There was a problem clearing the invitations.', 'bp-invite-anyone' ), 'error' );
  321. }
  322. bp_core_redirect( $bp->displayed_user->domain . $bp->invite_anyone->slug . '/sent-invites/' );
  323. }
  324. }
  325. add_action( 'wp', 'invite_anyone_catch_clear', 1 );
  326. function invite_anyone_screen_one() {
  327. global $bp;
  328. /*
  329. print "<pre>";
  330. print_r($bp);
  331. */
  332. /* Add a do action here, so your component can be extended by others. */
  333. do_action( 'invite_anyone_screen_one' );
  334. /* bp_template_title ought to be used - bp-default needs to markup the template tag
  335. and run a conditional check on template tag true to hide empty element markup or not
  336. add_action( 'bp_template_title', 'invite_anyone_screen_one_title' );
  337. */
  338. add_action( 'bp_template_content', 'invite_anyone_screen_one_content' );
  339. bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
  340. }
  341. /*
  342. function invite_anyone_screen_one_title() {
  343. _e( 'Invite New Members', 'bp-invite-anyone' );
  344. }
  345. */
  346. function invite_anyone_screen_one_content() {
  347. global $bp;
  348. $iaoptions = invite_anyone_options();
  349. if ( !$max_invites = $iaoptions['max_invites'] )
  350. $max_invites = 5;
  351. $from_group = false;
  352. if ( !empty( $bp->action_variables ) ) {
  353. if ( 'group-invites' == $bp->action_variables[0] )
  354. $from_group = $bp->action_variables[1];
  355. }
  356. $returned_data = !empty( $bp->invite_anyone->returned_data ) ? $bp->invite_anyone->returned_data : false;
  357. /* If the user is coming from the widget, $returned_emails is populated with those email addresses */
  358. if ( isset( $_POST['invite_anyone_widget'] ) ) {
  359. check_admin_referer( 'invite-anyone-widget_' . $bp->loggedin_user->id );
  360. if ( !empty( $_POST['invite_anyone_email_addresses'] ) ) {
  361. $returned_data['error_emails'] = invite_anyone_parse_addresses( $_POST['invite_anyone_email_addresses'] );
  362. }
  363. /* If the widget appeared on a group page, the group ID should come along with it too */
  364. if ( isset( $_POST['invite_anyone_widget_group'] ) )
  365. $returned_data['groups'] = $_POST['invite_anyone_widget_group'];
  366. }
  367. // $returned_groups is padded so that array_search (below) returns true for first group */
  368. $counter = 0;
  369. $returned_groups = array( 0 );
  370. if ( ! empty( $returned_data['groups'] ) ) {
  371. foreach( $returned_data['groups'] as $group_id ) {
  372. $returned_groups[] = $group_id;
  373. }
  374. }
  375. // Get the returned email subject, if there is one
  376. $returned_subject = ! empty( $returned_data['subject'] ) ? stripslashes( $returned_data['subject'] ) : false;
  377. // Get the returned email message, if there is one
  378. $returned_message = ! empty( $returned_data['message'] ) ? stripslashes( $returned_data['message'] ) : false;
  379. if ( ! empty( $returned_data['error_message'] ) ) {
  380. ?>
  381. <div class="invite-anyone-error error">
  382. <p><?php _e( "Some of your invitations were not sent. Please see the errors below and resubmit the failed invitations.", 'bp-invite-anyone' ) ?></p>
  383. </div>
  384. <?php
  385. }
  386. $blogname = get_bloginfo('name');
  387. $welcome_message = sprintf( __( 'Invite friends to join %s by following these steps:', 'bp-invite-anyone' ), $blogname );
  388. ?>
  389. <form id="invite-anyone-by-email" action="<?php echo $bp->displayed_user->domain . $bp->invite_anyone->slug . '/sent-invites/send/' ?>" method="post">
  390. <h4><?php _e( 'Invite New Members', 'bp-invite-anyone' ); ?></h4>
  391. <p id="welcome-message"><?php echo $welcome_message ?></p>
  392. <ol id="invite-anyone-steps">
  393. <li>
  394. <?php if ( ! empty( $returned_data['error_message'] ) ) : ?>
  395. <div class="invite-anyone-error error">
  396. <p><?php echo $returned_data['error_message'] ?></p>
  397. </div>
  398. <?php endif ?>
  399. <div class="manual-email">
  400. <p><?php _e( 'Enter email addresses below, one per line.', 'bp-invite-anyone' ) ?><?php if( invite_anyone_allowed_domains() ) : ?> <?php _e( 'You can only invite people whose email addresses end in one of the following domains:', 'bp-invite-anyone' ) ?> <?php echo invite_anyone_allowed_domains(); ?><?php endif; ?></p>
  401. <?php invite_anyone_email_fields( $returned_data['error_emails'] ) ?>
  402. </div>
  403. <?php /* invite_anyone_after_addresses gets $iaoptions so that Cloudsponge etc can tell whether certain components are activated, without an additional lookup */ ?>
  404. <?php do_action( 'invite_anyone_after_addresses', $iaoptions ) ?>
  405. </li>
  406. <li>
  407. <?php if ( $iaoptions['subject_is_customizable'] == 'yes' ) : ?>
  408. <label for="invite-anyone-custom-subject"><?php _e( '(optional) Customize the subject line of the invitation email.', 'bp-invite-anyone' ) ?></label>
  409. <textarea name="invite_anyone_custom_subject" id="invite-anyone-custom-subject" rows="15" cols="10" ><?php echo invite_anyone_invitation_subject( $returned_subject ) ?></textarea>
  410. <?php else : ?>
  411. <label for="invite-anyone-custom-subject"><?php _e( 'Subject: <span class="disabled-subject">Subject line is fixed</span>', 'bp-invite-anyone' ) ?></label>
  412. <textarea name="invite_anyone_custom_subject" id="invite-anyone-custom-subject" rows="15" cols="10" disabled="disabled"><?php echo invite_anyone_invitation_subject( $returned_subject ) ?> </textarea>
  413. <input type="hidden" id="invite-anyone-customised-subject" name="invite_anyone_custom_subject" value="<?php echo invite_anyone_invitation_subject() ?>" />
  414. <?php endif; ?>
  415. </li>
  416. <li>
  417. <?php if ( $iaoptions['message_is_customizable'] == 'yes' ) : ?>
  418. <label for="invite-anyone-custom-message"><?php _e( '(optional) Customize the text of the invitation.', 'bp-invite-anyone' ) ?></label>
  419. <textarea name="invite_anyone_custom_message" id="invite-anyone-custom-message" cols="40" rows="10"><?php echo invite_anyone_invitation_message( $returned_message ) ?></textarea>
  420. <?php else : ?>
  421. <label for="invite-anyone-custom-message"><?php _e( 'Message:', 'bp-invite-anyone' ) ?></label>
  422. <textarea name="invite_anyone_custom_message" id="invite-anyone-custom-message" disabled="disabled"><?php echo invite_anyone_invitation_message( $returned_message ) ?></textarea>
  423. <input type="hidden" name="invite_anyone_custom_message" value="<?php echo invite_anyone_invitation_message() ?>" />
  424. <?php endif; ?>
  425. <p><?php _e( 'The message will also contain a custom footer containing links to accept the invitation or opt out of further email invitations from this site.', 'bp-invite-anyone' ) ?></p>
  426. </li>
  427. <?php if ( invite_anyone_are_groups_running() ) : ?>
  428. <?php if ( $iaoptions['can_send_group_invites_email'] == 'yes' && bp_has_groups( "per_page=10000&type=alphabetical&user_id=" . bp_loggedin_user_id() ) ) : ?>
  429. <li>
  430. <p><?php _e( '(optional) Select some groups. Invitees will receive invitations to these groups when they join the site.', 'bp-invite-anyone' ) ?></p>
  431. <ul id="invite-anyone-group-list">
  432. <?php while ( bp_groups() ) : bp_the_group(); ?>
  433. <li>
  434. <input type="checkbox" name="invite_anyone_groups[]" id="invite_anyone_groups-<?php bp_group_id() ?>" value="<?php bp_group_id() ?>" <?php if ( $from_group == bp_get_group_id() || array_search( bp_get_group_id(), $returned_groups) ) : ?>checked<?php endif; ?> />
  435. <label for="invite_anyone_groups-<?php bp_group_id() ?>" class="invite-anyone-group-name"><?php bp_group_avatar_mini() ?> <span><?php bp_group_name() ?></span></label>
  436. </li>
  437. <?php endwhile; ?>
  438. </ul>
  439. </li>
  440. <?php endif; ?>
  441. <?php endif; ?>
  442. <?php do_action( 'invite_anyone_addl_fields' ) ?>
  443. </ol>
  444. <div class="submit">
  445. <input type="submit" name="invite-anyone-submit" id="invite-anyone-submit" value="<?php _e( 'Send Invites', 'buddypress' ) ?> " />
  446. </div>
  447. </form>
  448. <?php
  449. }
  450. /**
  451. * invite_anyone_screen_two()
  452. *
  453. */
  454. function invite_anyone_screen_two() {
  455. global $bp;
  456. if ( $bp->current_component == $bp->invite_anyone->slug && $bp->current_action == 'sent-invites' && isset( $bp->action_variables[0] ) && $bp->action_variables[0] == 'send' ) {
  457. if ( ! invite_anyone_process_invitations( $_POST ) )
  458. bp_core_add_message( __( 'Sorry, there was a problem sending your invitations. Please try again.', 'bp-invite-anyone' ), 'error' );
  459. }
  460. do_action( 'invite_anyone_sent_invites_screen' );
  461. /* bp_template_title ought to be used - bp-default needs to markup the template tag
  462. and run a conditional check on template tag true to hide empty element markup or not
  463. add_action( 'bp_template_title', 'invite_anyone_screen_two_title' );
  464. */
  465. add_action( 'bp_template_content', 'invite_anyone_screen_two_content' );
  466. bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
  467. }
  468. /*
  469. function invite_anyone_screen_two_title() {
  470. _e( 'Sent Invites', 'bp-invite-anyone' );
  471. }
  472. */
  473. function invite_anyone_screen_two_content() {
  474. global $bp;
  475. // Load the pagination helper
  476. if ( !class_exists( 'BBG_CPT_Pag' ) )
  477. require_once( dirname( __FILE__ ) . '/../lib/bbg-cpt-pag.php' );
  478. $pagination = new BBG_CPT_Pag;
  479. $inviter_id = bp_loggedin_user_id();
  480. if ( isset( $_GET['sort_by'] ) )
  481. $sort_by = $_GET['sort_by'];
  482. else
  483. $sort_by = 'date_invited';
  484. if ( isset( $_GET['order'] ) )
  485. $order = $_GET['order'];
  486. else
  487. $order = 'DESC';
  488. $base_url = $bp->displayed_user->domain . $bp->invite_anyone->slug . '/sent-invites/';
  489. ?>
  490. <h4><?php _e( 'Sent Invites', 'bp-invite-anyone' ); ?></h4>
  491. <?php $invites = invite_anyone_get_invitations_by_inviter_id( bp_loggedin_user_id(), $sort_by, $order, $pagination->get_per_page, $pagination->get_paged ) ?>
  492. <?php $pagination->setup_query( $invites ) ?>
  493. <?php if ( $invites->have_posts() ) : ?>
  494. <p id="sent-invites-intro"><?php _e( 'You have sent invitations to the following people.', 'bp-invite-anyone' ) ?></p>
  495. <div class="ia-pagination">
  496. <div class="currently-viewing">
  497. <?php $pagination->currently_viewing_text() ?>
  498. </div>
  499. <div class="pag-links">
  500. <?php $pagination->paginate_links() ?>
  501. </div>
  502. </div>
  503. <table class="invite-anyone-sent-invites zebra"
  504. summary="<?php _e( 'This table displays a list of all your sent invites.
  505. Invites that have been accepted are highlighted in the listings.
  506. You may clear any individual invites, all accepted invites or all of the invites from the list.', 'bp-invite-anyone' ) ?>">
  507. <thead>
  508. <tr>
  509. <th scope="col"></th>
  510. <th scope="col" <?php if ( $sort_by == 'email' ) : ?>class="sort-by-me"<?php endif ?>><a class="<?php echo $order ?>" title="Sort column order <?php echo $order ?>" href="<?php echo $base_url ?>?sort_by=email&amp;order=<?php if ( $sort_by == 'email' && $order == 'ASC' ) : ?>DESC<?php else : ?>ASC<?php endif; ?>"><?php _e( 'Invited email address', 'bp-invite-anyone' ) ?></a></th>
  511. <th scope="col"><?php _e( 'Group invitations', 'bp-invite-anyone' ) ?></th>
  512. <th scope="col" <?php if ( $sort_by == 'date_invited' ) : ?>class="sort-by-me"<?php endif ?>><a class="<?php echo $order ?>" title="Sort column order <?php echo $order ?>" href="<?php echo $base_url ?>?sort_by=date_invited&amp;order=<?php if ( $sort_by == 'date_invited' && $order == 'DESC' ) : ?>ASC<?php else : ?>DESC<?php endif; ?>"><?php _e( 'Sent', 'bp-invite-anyone' ) ?></a></th>
  513. <th scope="col" <?php if ( $sort_by == 'date_joined' ) : ?>class="sort-by-me"<?php endif ?>><a class="<?php echo $order ?>" title="Sort column order <?php echo $order ?>" href="<?php echo $base_url ?>?sort_by=date_joined&amp;order=<?php if ( $order == 'DESC' ) : ?>ASC<?php else : ?>DESC<?php endif; ?>"><?php _e( 'Accepted', 'bp-invite-anyone' ) ?></a></th>
  514. </tr>
  515. </thead>
  516. <tfoot>
  517. <tr id="batch-clear">
  518. <td colspan="5" >
  519. <ul id="invite-anyone-clear-links">
  520. <li> <a title="<?php _e( 'Clear all accepted invites from the list', 'bp-invite-anyone' ) ?>" class="confirm" href="<?php echo wp_nonce_url( $base_url . '?clear=accepted', 'invite_anyone_clear' ) ?>"><?php _e( 'Clear all accepted invitations', 'bp-invite-anyone' ) ?></a></li>
  521. <li class="last"><a title="<?php _e( 'Clear all your listed invites', 'bp-invite-anyone' ) ?>" class="confirm" href="<?php echo wp_nonce_url( $base_url . '?clear=all', 'invite_anyone_clear' ) ?>"><?php _e( 'Clear all invitations', 'bp-invite-anyone' ) ?></a></li>
  522. </ul>
  523. </td>
  524. </tr>
  525. </tfoot>
  526. <tbody>
  527. <?php while ( $invites->have_posts() ) : $invites->the_post() ?>
  528. <?php
  529. $emails = wp_get_post_terms( get_the_ID(), invite_anyone_get_invitee_tax_name() );
  530. // Should never happen, but was messing up my test env
  531. if ( empty( $emails ) ) {
  532. continue;
  533. }
  534. $email = $emails[0]->name;
  535. $post_id = get_the_ID();
  536. $query_string = preg_replace( "|clear=[0-9]+|", '', $_SERVER['QUERY_STRING'] );
  537. $clear_url = ( $query_string ) ? $base_url . '?' . $query_string . '&clear=' . $post_id : $base_url . '?clear=' . $post_id;
  538. $clear_url = wp_nonce_url( $clear_url, 'invite_anyone_clear' );
  539. $clear_link = '<a class="clear-entry confirm" title="' . __( 'Clear this invitation', 'bp-invite-anyone' ) . '" href="' . $clear_url . '">x<span></span></a>';
  540. $groups = wp_get_post_terms( get_the_ID(), invite_anyone_get_invited_groups_tax_name() );
  541. if ( !empty( $groups ) ) {
  542. $group_names = '<ul>';
  543. foreach( $groups as $group_term ) {
  544. $group = new BP_Groups_Group( $group_term->name );
  545. $group_names .= '<li>' . bp_get_group_name( $group ) . '</li>';
  546. }
  547. $group_names .= '</ul>';
  548. } else {
  549. $group_names = '-';
  550. }
  551. global $post;
  552. $date_invited = invite_anyone_format_date( $post->post_date );
  553. $accepted = get_post_meta( get_the_ID(), 'bp_ia_accepted', true );
  554. if ( $accepted ):
  555. $date_joined = invite_anyone_format_date( $accepted );
  556. $accepted = true;
  557. else:
  558. $date_joined = '-';
  559. $accepted = false;
  560. endif;
  561. ?>
  562. <tr <?php if($accepted){ ?> class="accepted" <?php } ?>>
  563. <td><?php echo $clear_link ?></td>
  564. <td><?php echo esc_html( $email ) ?></td>
  565. <td><?php echo $group_names ?></td>
  566. <td><?php echo $date_invited ?></td>
  567. <td class="date-joined"><?php echo $date_joined ?></td>
  568. </tr>
  569. <?php endwhile ?>
  570. </tbody>
  571. </table>
  572. <div class="ia-pagination">
  573. <div class="currently-viewing">
  574. <?php $pagination->currently_viewing_text() ?>
  575. </div>
  576. <div class="pag-links">
  577. <?php $pagination->paginate_links() ?>
  578. </div>
  579. </div>
  580. <?php else : ?>
  581. <p id="sent-invites-intro"><?php _e( "You haven't sent any email invitations yet.", 'bp-invite-anyone' ) ?></p>
  582. <?php endif; ?>
  583. <?php
  584. }
  585. /**
  586. * Displays the field where email addresses are entered on the Send Invites page
  587. *
  588. * In version 0.8, this field was changed to be a textarea rather than individual fields.
  589. *
  590. * @package Invite Anyone
  591. *
  592. * @param array $returned_emails Optional. Emails returned because of a processing error
  593. */
  594. function invite_anyone_email_fields( $returned_emails = false ) {
  595. if ( is_array( $returned_emails ) )
  596. $returned_emails = implode( "\n", $returned_emails );
  597. ?>
  598. <textarea name="invite_anyone_email_addresses" class="invite-anyone-email-addresses" id="invite-anyone-email-addresses"><?php echo $returned_emails ?></textarea>
  599. <?php
  600. }
  601. function invite_anyone_invitation_subject( $returned_message = false ) {
  602. global $bp;
  603. if ( !$returned_message ) {
  604. $site_name = get_bloginfo('name');
  605. $iaoptions = invite_anyone_options();
  606. if ( empty( $iaoptions['default_invitation_subject'] ) ) {
  607. $text = sprintf( __( 'An invitation to join the %s community.', 'bp-invite-anyone' ), $site_name );
  608. } else {
  609. $text = $iaoptions['default_invitation_subject'];
  610. }
  611. if ( !is_admin() ) {
  612. $text = invite_anyone_wildcard_replace( $text );
  613. }
  614. } else {
  615. $text = $returned_message;
  616. }
  617. return stripslashes( $text );
  618. }
  619. function invite_anyone_invitation_message( $returned_message = false ) {
  620. global $bp;
  621. if ( !$returned_message ) {
  622. $inviter_name = $bp->loggedin_user->userdata->display_name;
  623. $blogname = get_bloginfo('name');
  624. $iaoptions = invite_anyone_options();
  625. if ( empty( $iaoptions['default_invitation_message'] ) ) {
  626. $text = sprintf( __( 'You have been invited by %%INVITERNAME%% to join the %s community.
  627. Visit %%INVITERNAME%%\'s profile at %%INVITERURL%%.', 'bp-invite-anyone' ), $blogname ); /* Do not translate the strings embedded in %% ... %% ! */
  628. } else {
  629. $text = $iaoptions['default_invitation_message'];
  630. }
  631. if ( !is_admin() ) {
  632. $text = invite_anyone_wildcard_replace( $text );
  633. }
  634. } else {
  635. $text = $returned_message;
  636. }
  637. return apply_filters( 'invite_anyone_get_invitation_message', stripslashes( $text ) );
  638. }
  639. function invite_anyone_process_footer( $email ) {
  640. $iaoptions = invite_anyone_options();
  641. if ( empty( $iaoptions['addl_invitation_message'] ) ) {
  642. $footer = apply_filters( 'invite_anyone_accept_invite_footer_message', __( 'To accept this invitation, please visit %%ACCEPTURL%%', 'bp-invite-anyone' ) );
  643. $footer .= '
  644. ';
  645. $footer .= apply_filters( 'invite_anyone_opt_out_footer_message', __( 'To opt out of future invitations to this site, please visit %%OPTOUTURL%%', 'bp-invite-anyone' ) );
  646. } else {
  647. $footer = $iaoptions['addl_invitation_message'];
  648. }
  649. return stripslashes( $footer );
  650. }
  651. function invite_anyone_wildcard_replace( $text, $email = false ) {
  652. global $bp;
  653. $inviter_name = $bp->loggedin_user->userdata->display_name;
  654. $site_name = get_bloginfo('name');
  655. $inviter_url = bp_loggedin_user_domain();
  656. $accept_link = apply_filters( 'invite_anyone_accept_url', site_url( BP_REGISTER_SLUG ) . '/accept-invitation/' . urlencode($email) );
  657. $opt_out_link = site_url( BP_REGISTER_SLUG ) . '/opt-out/' . urlencode( $email );
  658. $text = str_replace( '%%INVITERNAME%%', $inviter_name, $text );
  659. $text = str_replace( '%%INVITERURL%%', $inviter_url, $text );
  660. $text = str_replace( '%%SITENAME%%', $site_name, $text );
  661. $text = str_replace( '%%OPTOUTURL%%', $opt_out_link, $text );
  662. $text = str_replace( '%%ACCEPTURL%%', $accept_link, $text );
  663. /* Adding single % replacements because lots of people are making the mistake */
  664. $text = str_replace( '%INVITERNAME%', $inviter_name, $text );
  665. $text = str_replace( '%INVITERURL%', $inviter_url, $text );
  666. $text = str_replace( '%SITENAME%', $site_name, $text );
  667. $text = str_replace( '%OPTOUTURL%', $opt_out_link, $text );
  668. $text = str_replace( '%ACCEPTURL%', $accept_link, $text );
  669. return $text;
  670. }
  671. function invite_anyone_allowed_domains() {
  672. $domains = '';
  673. if ( function_exists( 'get_site_option' ) ) {
  674. $limited_email_domains = get_site_option( 'limited_email_domains' );
  675. if ( !$limited_email_domains || !is_array( $limited_email_domains ) )
  676. return $domains;
  677. foreach( $limited_email_domains as $domain )
  678. $domains .= "<strong>$domain</strong> ";
  679. }
  680. return $domains;
  681. }
  682. /**
  683. * Fetches the invitee taxonomy name out of the $bp global so it can be queried in the template
  684. *
  685. * @package Invite Anyone
  686. * @since 0.8
  687. *
  688. * @return str $tax_name
  689. */
  690. function invite_anyone_get_invitee_tax_name() {
  691. global $bp;
  692. $tax_name = '';
  693. if ( !empty( $bp->invite_anyone->invitee_tax_name ) )
  694. $tax_name = $bp->invite_anyone->invitee_tax_name;
  695. return $tax_name;
  696. }
  697. /**
  698. * Fetches the groups taxonomy name out of the $bp global so it can be queried in the template
  699. *
  700. * @package Invite Anyone
  701. * @since 0.8
  702. *
  703. * @return str $tax_name
  704. */
  705. function invite_anyone_get_invited_groups_tax_name() {
  706. global $bp;
  707. $tax_name = '';
  708. if ( !empty( $bp->invite_anyone->invited_groups_tax_name ) )
  709. $tax_name = $bp->invite_anyone->invited_groups_tax_name;
  710. return $tax_name;
  711. }
  712. function invite_anyone_format_date( $date ) {
  713. $thetime = strtotime( $date );
  714. $format = get_option('date_format');
  715. $thetime = date( "$format", $thetime );
  716. return $thetime;
  717. }
  718. /**
  719. * Parses email addresses, comma-separated or line-separated, into an array
  720. *
  721. * @package Invite Anyone
  722. * @since 0.8.8
  723. *
  724. * @param str $address_string The raw string from the input box
  725. * @return array $emails An array of addresses
  726. */
  727. function invite_anyone_parse_addresses( $address_string ) {
  728. $emails = array();
  729. // First, split by line breaks
  730. $rows = explode( "\n", $address_string );
  731. // Then look through each row to split by comma
  732. foreach( $rows as $row ) {
  733. $row_addresses = explode( ',', $row );
  734. // Then walk through and add each address to the array
  735. foreach( $row_addresses as $row_address ) {
  736. $row_address_trimmed = trim( $row_address );
  737. // We also have to make sure that the email address isn't empty
  738. if ( ! empty( $row_address_trimmed ) && ! in_array( $row_address_trimmed, $emails ) )
  739. $emails[] = $row_address_trimmed;
  740. }
  741. }
  742. return apply_filters( 'invite_anyone_parse_addresses', $emails, $address_string );
  743. }
  744. function invite_anyone_process_invitations( $data ) {
  745. global $bp;
  746. $emails = false;
  747. // Parse out the individual email addresses
  748. if ( !empty( $data['invite_anyone_email_addresses'] ) ) {
  749. $emails = invite_anyone_parse_addresses( $data['invite_anyone_email_addresses'] );
  750. }
  751. // Filter the email addresses so that plugins can have a field day
  752. $emails = apply_filters( 'invite_anyone_submitted_email_addresses', $emails, $data );
  753. // Set up a wrapper for any data to return to the Send Invites screen in case of error
  754. $returned_data = array(
  755. 'error_message' => false,
  756. 'error_emails' => array(),
  757. 'subject' => $data['invite_anyone_custom_subject'],
  758. 'message' => $data['invite_anyone_custom_message'],
  759. 'groups' => isset( $data['invite_anyone_groups'] ) ? $data['invite_anyone_groups'] : ''
  760. );
  761. // Check against the max number of invites. Send back right away if there are too many
  762. $options = invite_anyone_options();
  763. $max_invites = !empty( $options['max_invites'] ) ? $options['max_invites'] : 5;
  764. if ( count( $emails ) > $max_invites ) {
  765. $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 );
  766. $returned_data['error_emails'] = $emails;
  767. // Stash error info in cookies so we can use it after a redirect
  768. setcookie( 'invite-anyone-error-data', maybe_serialize( $returned_data ), time()+60*60*24, COOKIEPATH, COOKIE_DOMAIN );
  769. bp_core_redirect( $bp->loggedin_user->domain . $bp->invite_anyone->slug . '/invite-new-members' );
  770. }
  771. if ( empty( $emails ) ) {
  772. bp_core_add_message( __( 'You didn\'t include any email addresses!', 'bp-invite-anyone' ), 'error' );
  773. bp_core_redirect( $bp->loggedin_user->domain . $bp->invite_anyone->slug . '/invite-new-members' );
  774. }
  775. // Turn the CS emails into an array so that they can be matched against the main list
  776. if ( isset( $_POST['cloudsponge-emails'] ) ) {
  777. $cs_emails = explode( ',', $_POST['cloudsponge-emails'] );
  778. }
  779. // validate email addresses
  780. foreach( $emails as $key => $email ) {
  781. $check = invite_anyone_validate_email( $email );
  782. switch ( $check ) {
  783. case 'opt_out' :
  784. $returned_data['error_message'] .= sprintf( __( '<strong>%s</strong> has opted out of email invitations from this site.', 'bp-invite-anyone' ), $email );
  785. break;
  786. case 'used' :
  787. $returned_data['error_message'] .= sprintf( __( "<strong>%s</strong> is already a registered user of the site.", 'bp-invite-anyone' ), $email );
  788. break;
  789. case 'unsafe' :
  790. $returned_data['error_message'] .= sprintf( __( '<strong>%s</strong> is not a permitted email address.', 'bp-invite-anyone' ), $email );
  791. break;
  792. case 'invalid' :
  793. $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 );
  794. break;
  795. case 'limited_domain' :
  796. $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 );
  797. break;
  798. }
  799. // If there was an error in validation, we won't process this email
  800. if ( $check != 'okay' ) {
  801. $returned_data['error_message'] .= '<br />';
  802. $returned_data['error_emails'][] = $email;
  803. unset( $emails[$key] );
  804. }
  805. }
  806. // Stash error info in cookies so we can use it after a redirect
  807. setcookie( 'invite-anyone-error-data', maybe_serialize( $returned_data ), time()+60*60*24, COOKIEPATH, COOKIE_DOMAIN );
  808. if ( ! empty( $emails ) ) {
  809. unset( $message, $to );
  810. /* send and record invitations */
  811. do_action( 'invite_anyone_process_addl_fields' );
  812. $groups = ! empty( $data['invite_anyone_groups'] ) ? $data['invite_anyone_groups'] : array();
  813. $is_error = 0;
  814. foreach( $emails as $email ) {
  815. $subject = stripslashes( strip_tags( $data['invite_anyone_custom_subject'] ) );
  816. $message = stripslashes( strip_tags( $data['invite_anyone_custom_message'] ) );
  817. $footer = invite_anyone_process_footer( $email );
  818. $footer = invite_anyone_wildcard_replace( $footer, $email );
  819. $message .= '
  820. ================
  821. ';
  822. $message .= $footer;
  823. $to = apply_filters( 'invite_anyone_invitee_email', $email );
  824. $subject = apply_filters( 'invite_anyone_invitation_subject', $subject );
  825. $message = apply_filters( 'invite_anyone_invitation_message', $message );
  826. wp_mail( $to, $subject, $message );
  827. /* todo: isolate which email(s) cause problems, and send back to user */
  828. /* if ( !invite_anyone_send_invitation( $bp->loggedin_user->id, $email, $message, $groups ) )
  829. $is_error = 1; */
  830. // Determine whether this address came from CloudSponge
  831. $is_cloudsponge = isset( $cs_emails ) && in_array( $email, $cs_emails ) ? true : false;
  832. invite_anyone_record_invitation( $bp->loggedin_user->id, $email, $message, $groups, $subject, $is_cloudsponge );
  833. do_action( 'sent_email_invite', $bp->loggedin_user->id, $email, $groups );
  834. unset( $message, $to );
  835. }
  836. // Set a success message
  837. $success_message = sprintf( __( "Invitations were sent successfully to the following email addresses: %s", 'bp-invite-anyone' ), implode( ", ", $emails ) );
  838. bp_core_add_message( $success_message );
  839. do_action( 'sent_email_invites', $bp->loggedin_user->id, $emails, $groups );
  840. } else {
  841. $success_message = sprintf( __( "Please correct your errors and resubmit.", 'bp-invite-anyone' ) );
  842. bp_core_add_message( $success_message, 'error' );
  843. }
  844. // If there are errors, redirect to the Invite New Members page
  845. if ( ! empty( $returned_data['error_emails'] ) )
  846. bp_core_redirect( $bp->loggedin_user->domain . $bp->invite_anyone->slug . '/invite-new-members' );
  847. return true;
  848. }
  849. function invite_anyone_send_invitation( $inviter_id, $email, $message, $groups ) {
  850. global $bp;
  851. }
  852. function invite_anyone_bypass_registration_lock() {
  853. global $bp;
  854. if ( $bp->current_component != BP_REGISTER_SLUG || $bp->current_action != 'accept-invitation' )
  855. return;
  856. if ( !isset( $bp->action_variables[0] ) || !$email = urldecode( $bp->action_variables[0] ) )
  857. return;
  858. $options = invite_anyone_options();
  859. if ( empty( $options['bypass_registration_lock'] ) || $options['bypass_registration_lock'] != 'yes' )
  860. return;
  861. // Check to make sure that it's actually a valid email
  862. $ia_obj = invite_anyone_get_invitations_by_invited_email( $email );
  863. if ( !$ia_obj->have_posts() ) {
  864. bp_core_add_message( __( "We couldn't find any invitations associated with this email address.", 'bp-invite-anyone' ), 'error' );
  865. return;
  866. }
  867. // This is a royal hack until there is a filter on bp_get_signup_allowed()
  868. if ( is_multisite() ) {
  869. if ( !empty( $bp->site_options['registration'] ) && $bp->site_options['registration'] == 'blog' ) {
  870. $bp->site_options['registration'] = 'all';
  871. } else if ( !empty( $bp->site_options['registration'] ) && $bp->site_options['registration'] == 'none' ) {
  872. $bp->site_options['registration'] = 'user';
  873. }
  874. } else {
  875. add_filter( 'option_users_can_register', create_function( false, 'return true;' ) );
  876. }
  877. }
  878. add_action( 'wp', 'invite_anyone_bypass_registration_lock', 1 );
  879. function invite_anyone_validate_email( $user_email ) {
  880. $status = 'okay';
  881. if ( invite_anyone_check_is_opt_out( $user_email ) ) {
  882. $status = 'opt_out';
  883. } else if ( $user = get_user_by_email( $user_email ) ) {
  884. $status = 'used';
  885. } else if ( function_exists( 'is_email_address_unsafe' ) && is_email_address_unsafe( $user_email ) ) {
  886. $status = 'unsafe';
  887. } else if ( function_exists( 'is_email' ) && !is_email( $user_email ) ) {
  888. $status = 'invalid';
  889. }
  890. if ( function_exists( 'get_site_option' ) ) {
  891. if ( $limited_email_domains = get_site_option( 'limited_email_domains' ) ) {
  892. if ( is_array( $limited_email_domains ) && empty( $limited_email_domains ) == false ) {
  893. $emaildomain = substr( $user_email, 1 + strpos( $user_email, '@' ) );
  894. if( in_array( $emaildomain, $limited_email_domains ) == false ) {
  895. $status = 'limited_domain';
  896. }
  897. }
  898. }
  899. }
  900. return apply_filters( 'invite_anyone_validate_email', $status, $user_email );
  901. }
  902. ?>