Advertisement
Guest User

Untitled

a guest
Sep 24th, 2017
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.87 KB | None | 0 0
  1. <?php
  2.  
  3. /********************************************************************************
  4. * Screen Functions
  5. *
  6. * Screen functions are the controllers of BuddyPress. They will execute when their
  7. * specific URL is caught. They will first save or manipulate data using business
  8. * functions, then pass on the user to a template file.
  9. */
  10.  
  11. function bp_core_screen_signup() {
  12. global $bp, $wpdb;
  13.  
  14. if ( $bp->current_component != BP_REGISTER_SLUG )
  15. return false;
  16.  
  17. /* If the user is logged in, redirect away from here */
  18. if ( is_user_logged_in() )
  19. bp_core_redirect( $bp->root_domain );
  20.  
  21. /* If signups are disabled, just re-direct */
  22. if ( !bp_get_signup_allowed() )
  23. bp_core_redirect( $bp->root_domain );
  24.  
  25. $bp->signup->step = 'request-details';
  26.  
  27. /* If the signup page is submitted, validate and save */
  28. if ( isset( $_POST['signup_submit'] ) ) {
  29.  
  30. /* Check the nonce */
  31. check_admin_referer( 'bp_new_signup' );
  32.  
  33. require_once( ABSPATH . WPINC . '/registration.php' );
  34.  
  35. /* Check the base account details for problems */
  36. $account_details = bp_core_validate_user_signup( $_POST['signup_username'], $_POST['signup_email'] );
  37.  
  38. /* If there are errors with account details, set them for display */
  39. if ( !empty( $account_details['errors']->errors['user_name'] ) )
  40. $bp->signup->errors['signup_username'] = $account_details['errors']->errors['user_name'][0];
  41.  
  42. if ( !empty( $account_details['errors']->errors['user_email'] ) )
  43. $bp->signup->errors['signup_email'] = $account_details['errors']->errors['user_email'][0];
  44.  
  45. /* Check that both password fields are filled in */
  46. if ( empty( $_POST['signup_password'] ) || empty( $_POST['signup_password_confirm'] ) )
  47. $bp->signup->errors['signup_password'] = __( 'Please make sure you enter your password twice', 'buddypress' );
  48.  
  49. /* Check that the passwords match */
  50. if ( ( !empty( $_POST['signup_password'] ) && !empty( $_POST['signup_password_confirm'] ) ) && $_POST['signup_password'] != $_POST['signup_password_confirm'] )
  51. $bp->signup->errors['signup_password'] = __( 'The passwords you entered do not match.', 'buddypress' );
  52.  
  53. $bp->signup->username = $_POST['signup_username'];
  54. $bp->signup->email = $_POST['signup_email'];
  55.  
  56. /* Now we've checked account details, we can check profile information */
  57. if ( function_exists( 'xprofile_check_is_required_field' ) ) {
  58.  
  59. /* Make sure hidden field is passed and populated */
  60. if ( isset( $_POST['signup_profile_field_ids'] ) && !empty( $_POST['signup_profile_field_ids'] ) ) {
  61.  
  62. /* Let's compact any profile field info into an array */
  63. $profile_field_ids = explode( ',', $_POST['signup_profile_field_ids'] );
  64.  
  65. /* Loop through the posted fields formatting any datebox values then validate the field */
  66. foreach ( (array) $profile_field_ids as $field_id ) {
  67. if ( !isset( $_POST['field_' . $field_id] ) ) {
  68. if ( isset( $_POST['field_' . $field_id . '_day'] ) )
  69. $_POST['field_' . $field_id] = strtotime( $_POST['field_' . $field_id . '_day'] . $_POST['field_' . $field_id . '_month'] . $_POST['field_' . $field_id . '_year'] );
  70. }
  71.  
  72. /* Create errors for required fields without values */
  73. if ( xprofile_check_is_required_field( $field_id ) && empty( $_POST['field_' . $field_id] ) )
  74. $bp->signup->errors['field_' . $field_id] = __( 'This is a required field', 'buddypress' );
  75. }
  76.  
  77. /* This situation doesn't naturally occur so bounce to website root */
  78. } else {
  79. bp_core_redirect( $bp->root_domain );
  80. }
  81. }
  82.  
  83. /* Finally, let's check the blog details, if the user wants a blog and blog creation is enabled */
  84. if ( isset( $_POST['signup_with_blog'] ) ) {
  85. $active_signup = $bp->site_options['registration'];
  86.  
  87. if ( 'blog' == $active_signup || 'all' == $active_signup ) {
  88. $blog_details = bp_core_validate_blog_signup( $_POST['signup_blog_url'], $_POST['signup_blog_title'] );
  89.  
  90. /* If there are errors with blog details, set them for display */
  91. if ( !empty( $blog_details['errors']->errors['blogname'] ) )
  92. $bp->signup->errors['signup_blog_url'] = $blog_details['errors']->errors['blogname'][0];
  93.  
  94. if ( !empty( $blog_details['errors']->errors['blog_title'] ) )
  95. $bp->signup->errors['signup_blog_title'] = $blog_details['errors']->errors['blog_title'][0];
  96. }
  97. }
  98.  
  99. do_action( 'bp_signup_validate' );
  100.  
  101. /* Add any errors to the action for the field in the template for display. */
  102. if ( !empty( $bp->signup->errors ) ) {
  103. foreach ( (array)$bp->signup->errors as $fieldname => $error_message )
  104. add_action( 'bp_' . $fieldname . '_errors', create_function( '', 'echo "<div class=\"error\">' . $error_message . '</div>";' ) );
  105. } else {
  106. $bp->signup->step = 'save-details';
  107.  
  108. /* No errors! Let's register those deets. */
  109. $active_signup = $bp->site_options['registration'];
  110.  
  111. if ( 'none' != $active_signup ) {
  112.  
  113. /* Let's compact any profile field info into usermeta */
  114. $profile_field_ids = explode( ',', $_POST['signup_profile_field_ids'] );
  115.  
  116. /* Loop through the posted fields formatting any datebox values then add to usermeta */
  117. foreach ( (array) $profile_field_ids as $field_id ) {
  118. if ( !isset( $_POST['field_' . $field_id] ) ) {
  119. if ( isset( $_POST['field_' . $field_id . '_day'] ) )
  120. $_POST['field_' . $field_id] = strtotime( $_POST['field_' . $field_id . '_day'] . $_POST['field_' . $field_id . '_month'] . $_POST['field_' . $field_id . '_year'] );
  121. }
  122.  
  123. if ( !empty( $_POST['field_' . $field_id] ) )
  124. $usermeta['field_' . $field_id] = $_POST['field_' . $field_id];
  125. }
  126.  
  127. /* Store the profile field ID's in usermeta */
  128. $usermeta['profile_field_ids'] = $_POST['signup_profile_field_ids'];
  129.  
  130. /* Hash and store the password */
  131. $usermeta['password'] = wp_hash_password( $_POST['signup_password'] );
  132.  
  133. /* If the user decided to create a blog, save those details to usermeta */
  134. if ( 'blog' == $active_signup || 'all' == $active_signup ) {
  135. $usermeta['public'] = ( 'public' == $_POST['signup_blog_privacy'] ) ? true : false;
  136. }
  137.  
  138. $usermeta = apply_filters( 'bp_signup_usermeta', $usermeta );
  139.  
  140. /* Finally, sign up the user and/or blog */
  141. if ( isset( $_POST['signup_with_blog'] ) && bp_core_is_multisite() )
  142. bp_core_signup_blog( $blog_details['domain'], $blog_details['path'], $blog_details['blog_title'], $_POST['signup_username'], $_POST['signup_email'], $usermeta );
  143. else {
  144. bp_core_signup_user( $_POST['signup_username'], $_POST['signup_password'], $_POST['signup_email'], $usermeta );
  145. }
  146.  
  147. $bp->signup->step = 'completed-confirmation';
  148. }
  149.  
  150. do_action( 'bp_complete_signup' );
  151. }
  152.  
  153. }
  154.  
  155. $bp->avatar_admin->step = 'upload-image';
  156.  
  157. /* If user has uploaded a new avatar */
  158. if ( !empty( $_FILES ) ) {
  159.  
  160. /* Check the nonce */
  161. check_admin_referer( 'bp_avatar_upload' );
  162.  
  163. $bp->signup->step = 'completed-confirmation';
  164.  
  165. if ( bp_core_is_multisite() ) {
  166. /* Get the activation key */
  167. if ( !$bp->signup->key = $wpdb->get_var( $wpdb->prepare( "SELECT activation_key FROM {$wpdb->signups} WHERE user_login = %s AND user_email = %s", $_POST[ 'signup_username' ], $_POST[ 'signup_email' ] ) ) ) {
  168. bp_core_add_message( __( 'There was a problem uploading your avatar, please try uploading it again', 'buddypress' ) );
  169. } else {
  170. /* Hash the key to create the upload folder (added security so people don't sniff the activation key) */
  171. $bp->signup->avatar_dir = wp_hash( $bp->signup->key );
  172. }
  173. } else {
  174. $user_id = bp_core_get_userid( $_POST['signup_username'] );
  175. $bp->signup->avatar_dir = wp_hash( $user_id );
  176. }
  177.  
  178. /* Pass the file to the avatar upload handler */
  179. if ( bp_core_avatar_handle_upload( $_FILES, 'bp_core_signup_avatar_upload_dir' ) ) {
  180. $bp->avatar_admin->step = 'crop-image';
  181.  
  182. /* Make sure we include the jQuery jCrop file for image cropping */
  183. add_action( 'wp', 'bp_core_add_jquery_cropper' );
  184. }
  185. }
  186.  
  187. /* If the image cropping is done, crop the image and save a full/thumb version */
  188. if ( isset( $_POST['avatar-crop-submit'] ) ) {
  189.  
  190. /* Check the nonce */
  191. check_admin_referer( 'bp_avatar_cropstore' );
  192.  
  193. /* Reset the avatar step so we can show the upload form again if needed */
  194. $bp->signup->step = 'completed-confirmation';
  195. $bp->avatar_admin->step = 'upload-image';
  196.  
  197. if ( !bp_core_avatar_handle_crop( array( 'original_file' => $_POST['image_src'], 'crop_x' => $_POST['x'], 'crop_y' => $_POST['y'], 'crop_w' => $_POST['w'], 'crop_h' => $_POST['h'] ) ) )
  198. bp_core_add_message( __( 'There was a problem cropping your avatar, please try uploading it again', 'buddypress' ), 'error' );
  199. else
  200. bp_core_add_message( __( 'Your new avatar was uploaded successfully', 'buddypress' ) );
  201. }
  202. bp_core_load_template( 'registration/register' );
  203. }
  204. add_action( 'wp', 'bp_core_screen_signup', 3 );
  205.  
  206. function bp_core_screen_activation() {
  207. global $bp, $wpdb;
  208.  
  209. if ( BP_ACTIVATION_SLUG != $bp->current_component )
  210. return false;
  211.  
  212. /* Check if an activation key has been passed */
  213. if ( isset( $_GET['key'] ) ) {
  214.  
  215. require_once( ABSPATH . WPINC . '/registration.php' );
  216.  
  217. /* Activate the signup */
  218. $user = apply_filters( 'bp_core_activate_account', bp_core_activate_signup( $_GET['key'] ) );
  219.  
  220. /* If there was errors, add a message and redirect */
  221. if ( $user->errors ) {
  222. bp_core_add_message( __( 'There was an error activating your account, please try again.', 'buddypress' ), 'error' );
  223. bp_core_redirect( $bp->root_domain . '/' . BP_ACTIVATION_SLUG );
  224. }
  225.  
  226. /* Check for an uploaded avatar and move that to the correct user folder */
  227. if ( bp_core_is_multisite() )
  228. $hashed_key = wp_hash( $_GET['key'] );
  229. else
  230. $hashed_key = wp_hash( $user );
  231.  
  232. /* Check if the avatar folder exists. If it does, move rename it, move it and delete the signup avatar dir */
  233. if ( file_exists( BP_AVATAR_UPLOAD_PATH . '/avatars/signups/' . $hashed_key ) )
  234. @rename( BP_AVATAR_UPLOAD_PATH . '/avatars/signups/' . $hashed_key, BP_AVATAR_UPLOAD_PATH . '/avatars/' . $user );
  235.  
  236. bp_core_add_message( __( 'Your account is now active!', 'buddypress' ) );
  237.  
  238. $bp->activation_complete = true;
  239. }
  240.  
  241. if ( '' != locate_template( array( 'registration/activate' ), false ) )
  242. bp_core_load_template( apply_filters( 'bp_core_template_activate', 'activate' ) );
  243. else
  244. bp_core_load_template( apply_filters( 'bp_core_template_activate', 'registration/activate' ) );
  245. }
  246. add_action( 'wp', 'bp_core_screen_activation', 3 );
  247.  
  248.  
  249. /********************************************************************************
  250. * Business Functions
  251. *
  252. * Business functions are where all the magic happens in BuddyPress. They will
  253. * handle the actual saving or manipulation of information. Usually they will
  254. * hand off to a database class for data access, then return
  255. * true or false on success or failure.
  256. */
  257.  
  258. /**
  259. * bp_core_validate_user_signup()
  260. *
  261. * Validate a user name and email address when creating a new user.
  262. *
  263. * @global object $wpdb DB Layer
  264. * @param string $user_name Username to validate
  265. * @param string $user_email Email address to validate
  266. * @return array Results of user validation including errors, if any
  267. */
  268. function bp_core_validate_user_signup( $user_name, $user_email ) {
  269. global $wpdb;
  270.  
  271. $errors = new WP_Error();
  272. $user_email = sanitize_email( $user_email );
  273.  
  274. if ( empty( $user_name ) )
  275. $errors->add( 'user_name', __( 'Please enter a username', 'buddypress' ) );
  276.  
  277. $maybe = array();
  278. preg_match( "/[a-z0-9]+/", $user_name, $maybe );
  279.  
  280. // Make sure illegal names include BuddyPress slugs and values
  281. bp_core_flush_illegal_names();
  282.  
  283. if ( !validate_username( $user_name ) || in_array( $user_name, (array)$illegal_names ) || $user_name != $maybe[0] )
  284. $errors->add( 'user_name', __( 'Only lowercase letters and numbers allowed', 'buddypress' ) );
  285.  
  286. if( strlen( $user_name ) < 4 )
  287. $errors->add( 'user_name', __( 'Username must be at least 4 characters', 'buddypress' ) );
  288.  
  289. if ( strpos( ' ' . $user_name, '_' ) != false )
  290. $errors->add( 'user_name', __( 'Sorry, usernames may not contain the character "_"!', 'buddypress' ) );
  291.  
  292. /* Is the user_name all numeric? */
  293. $match = array();
  294. preg_match( '/[0-9]*/', $user_name, $match );
  295.  
  296. if ( $match[0] == $user_name )
  297. $errors->add( 'user_name', __( 'Sorry, usernames must have letters too!', 'buddypress' ) );
  298.  
  299. if ( !is_email( $user_email ) )
  300. $errors->add( 'user_email', __( 'Please check your email address.', 'buddypress' ) );
  301.  
  302. $limited_email_domains = get_site_option( 'limited_email_domains', 'buddypress' );
  303.  
  304. if ( is_array( $limited_email_domains ) && empty( $limited_email_domains ) == false ) {
  305. $emaildomain = substr( $user_email, 1 + strpos( $user_email, '@' ) );
  306.  
  307. if ( in_array( $emaildomain, (array)$limited_email_domains ) == false )
  308. $errors->add( 'user_email', __( 'Sorry, that email address is not allowed!', 'buddypress' ) );
  309. }
  310.  
  311. /* Check to see if email is blacklisted. */
  312.  
  313. $banned_email_domains = get_site_option( 'banned_email_domains', 'buddypress' );
  314.  
  315. if ( is_array( $banned_email_domains ) && empty( $banned_email_domains ) == false ) {
  316. $emaildomain = substr( $user_email, 1 + strpos( $user_email, '@' ) );
  317.  
  318. if ( in_array( $emaildomain, (array)$banned_email_domains ) == true )
  319. $errors->add( 'user_email', __( 'Sorry, that email address is not allowed!', 'buddypress' ) );
  320. }
  321. /* Check if the username has been used already. */
  322. if ( username_exists( $user_name ) )
  323. $errors->add( 'user_name', __( 'Sorry, that username already exists!', 'buddypress' ) );
  324.  
  325. /* Check if the email address has been used already. */
  326. if ( email_exists( $user_email ) )
  327. $errors->add( 'user_email', __( 'Sorry, that email address is already used!', 'buddypress' ) );
  328.  
  329. $result = array( 'user_name' => $user_name, 'user_email' => $user_email, 'errors' => $errors );
  330.  
  331. /* Apply WPMU legacy filter */
  332. $result = apply_filters( 'wpmu_validate_user_signup', $result );
  333.  
  334. return apply_filters( 'bp_core_validate_user_signup', $result );
  335. }
  336.  
  337. function bp_core_validate_blog_signup( $blog_url, $blog_title ) {
  338. if ( !bp_core_is_multisite() || !function_exists( 'wpmu_validate_blog_signup' ) )
  339. return false;
  340.  
  341. return apply_filters( 'bp_core_validate_blog_signup', wpmu_validate_blog_signup( $blog_url, $blog_title ) );
  342. }
  343.  
  344. function bp_core_signup_user( $user_login, $user_password, $user_email, $usermeta ) {
  345. global $bp, $wpdb;
  346.  
  347. /* Multisite installs have their own install procedure */
  348. if ( bp_core_is_multisite() ) {
  349. wpmu_signup_user( $user_login, $user_email, $usermeta );
  350.  
  351. } else {
  352. $errors = new WP_Error();
  353.  
  354. $user_id = wp_insert_user( array(
  355. 'user_login' => $user_login,
  356. 'user_pass' => $user_password,
  357. 'display_name' => sanitize_title( $user_login ),
  358. 'user_email' => $user_email
  359. ) );
  360.  
  361. if ( is_wp_error( $user_id ) || !$user_id ) {
  362. $errors->add( 'registerfail', sprintf( __('<strong>ERROR</strong>: Couldn&#8217;t register you... please contact the <a href="mailto:%s">webmaster</a> !', 'buddypress' ), get_option( 'admin_email' ) ) );
  363. return $errors;
  364. }
  365.  
  366. /* Update the user status to '2' which we will use as 'not activated' (0 = active, 1 = spam, 2 = not active) */
  367. $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->users SET user_status = 2 WHERE ID = %d", $user_id ) );
  368.  
  369. /* Set any profile data */
  370. if ( function_exists( 'xprofile_set_field_data' ) ) {
  371. if ( !empty( $usermeta['profile_field_ids'] ) ) {
  372. $profile_field_ids = explode( ',', $usermeta['profile_field_ids'] );
  373.  
  374. foreach( (array)$profile_field_ids as $field_id ) {
  375. $current_field = $usermeta["field_{$field_id}"];
  376.  
  377. if ( !empty( $current_field ) )
  378. xprofile_set_field_data( $field_id, $user_id, $current_field );
  379. }
  380. }
  381. }
  382. }
  383. $bp->signup->username = $user_login;
  384.  
  385. /***
  386. * Now generate an activation key and send an email to the user so they can activate their account
  387. * and validate their email address. Multisite installs send their own email, so this is only for single blog installs.
  388. *
  389. * To disable sending activation emails you can user the filter 'bp_core_signup_send_activation_key' and return false.
  390. */
  391. if ( apply_filters( 'bp_core_signup_send_activation_key', true ) ) {
  392. if ( !bp_core_is_multisite() ) {
  393. $activation_key = wp_hash( $user_id );
  394. update_user_meta( $user_id, 'activation_key', $activation_key );
  395. bp_core_signup_send_validation_email( $user_id, $user_email, $activation_key );
  396. }
  397. }
  398.  
  399. do_action( 'bp_core_signup_user', $user_id, $user_login, $user_password, $user_email, $usermeta );
  400.  
  401. return $user_id;
  402. }
  403.  
  404. function bp_core_signup_blog( $blog_domain, $blog_path, $blog_title, $user_name, $user_email, $usermeta ) {
  405. if ( !bp_core_is_multisite() || !function_exists( 'wpmu_signup_blog' ) )
  406. return false;
  407.  
  408. return apply_filters( 'bp_core_signup_blog', wpmu_signup_blog( $blog_domain, $blog_path, $blog_title, $user_name, $user_email, $usermeta ) );
  409. }
  410.  
  411. function bp_core_activate_signup( $key ) {
  412. global $bp, $wpdb;
  413.  
  414. $user = false;
  415.  
  416. /* Multisite installs have their own activation routine */
  417. if ( bp_core_is_multisite() ) {
  418. $user = wpmu_activate_signup( $key );
  419.  
  420. /* If there was errors, add a message and redirect */
  421. if ( $user->errors ) {
  422. bp_core_add_message( __( 'There was an error activating your account, please try again.', 'buddypress' ), 'error' );
  423. bp_core_redirect( $bp->root_domain . '/' . BP_ACTIVATION_SLUG );
  424. }
  425.  
  426. $user_id = $user['user_id'];
  427.  
  428. /* Set any profile data */
  429. if ( function_exists( 'xprofile_set_field_data' ) ) {
  430. if ( !empty( $user['meta']['profile_field_ids'] ) ) {
  431. $profile_field_ids = explode( ',', $user['meta']['profile_field_ids'] );
  432.  
  433. foreach( (array)$profile_field_ids as $field_id ) {
  434. $current_field = $user['meta']["field_{$field_id}"];
  435.  
  436. if ( !empty( $current_field ) )
  437. xprofile_set_field_data( $field_id, $user_id, $current_field );
  438. }
  439. }
  440. }
  441.  
  442. } else {
  443. /* Get the user_id based on the $key */
  444. $user_id = $wpdb->get_var( $wpdb->prepare( "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = 'activation_key' AND meta_value = %s", $key ) );
  445.  
  446. if ( empty( $user_id ) )
  447. return new WP_Error( 'invalid_key', __( 'Invalid activation key', 'buddypress' ) );
  448.  
  449. /* Change the user's status so they become active */
  450. if ( !$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->users SET user_status = 0 WHERE ID = %d", $user_id ) ) )
  451. return new WP_Error( 'invalid_key', __( 'Invalid activation key', 'buddypress' ) );
  452.  
  453. /* Notify the site admin of a new user registration */
  454. wp_new_user_notification( $user_id );
  455.  
  456. /* Remove the activation key meta */
  457. delete_user_meta( $user_id, 'activation_key' );
  458. }
  459.  
  460. /* Update the user_url and display_name */
  461. wp_update_user( array( 'ID' => $user_id, 'user_url' => bp_core_get_user_domain( $user_id, sanitize_title( $user_login ), $user_login ), 'display_name' => bp_core_get_user_displayname( $user_id ) ) );
  462.  
  463. /* Add a last active entry */
  464. update_user_meta( $user_id, 'last_activity', bp_core_current_time() );
  465.  
  466. /* Set the password on multisite installs */
  467. if ( bp_core_is_multisite() && !empty( $user['meta']['password'] ) )
  468. $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->users SET user_pass = %s WHERE ID = %d", $user['meta']['password'], $user_id ) );
  469.  
  470. /* Delete the total member cache */
  471. wp_cache_delete( 'bp_total_member_count', 'bp' );
  472.  
  473. do_action( 'bp_core_activated_user', $user_id, $key, $user );
  474.  
  475. return $user_id;
  476. }
  477.  
  478. function bp_core_new_user_activity( $user ) {
  479. if ( empty( $user ) || !function_exists( 'bp_activity_add' ) )
  480. return false;
  481.  
  482. if ( is_array( $user ) )
  483. $user_id = $user['user_id'];
  484. else
  485. $user_id = $user;
  486.  
  487. if ( empty( $user_id ) )
  488. return false;
  489.  
  490. $userlink = bp_core_get_userlink( $user_id );
  491.  
  492. bp_activity_add( array(
  493. 'user_id' => $user_id,
  494. 'action' => apply_filters( 'bp_core_activity_registered_member_action', sprintf( __( '%s became a registered member', 'buddypress' ), $userlink ), $user_id ),
  495. 'component' => 'profile',
  496. 'type' => 'new_member'
  497. ) );
  498. }
  499. add_action( 'bp_core_activated_user', 'bp_core_new_user_activity' );
  500.  
  501. function bp_core_map_user_registration( $user_id ) {
  502. /* Only map data when the site admin is adding users, not on registration. */
  503. if ( !is_admin() )
  504. return false;
  505.  
  506. /* Add a last active entry */
  507. update_user_meta( $user_id, 'last_activity', bp_core_current_time() );
  508.  
  509. /* Add the user's fullname to Xprofile */
  510. if ( function_exists( 'xprofile_set_field_data' ) ) {
  511. $firstname = get_user_meta( $user_id, 'first_name', true );
  512. $lastname = ' ' . get_user_meta( $user_id, 'last_name', true );
  513. $name = $firstname . $lastname;
  514.  
  515. if ( empty( $name ) || ' ' == $name )
  516. $name = get_user_meta( $user_id, 'nickname', true );
  517.  
  518. xprofile_set_field_data( 1, $user_id, $name );
  519. }
  520. }
  521. add_action( 'user_register', 'bp_core_map_user_registration' );
  522. add_action('bp_before_registration_submit_buttons', 'display_recaptcha', 9999);
  523.  
  524. add_filter(‘wpmu_validate_user_signup’, ‘check_recaptcha_wpmu’);
  525. add_action( 'user_register', 'bp_core_map_user_registration' );
  526.  
  527. function bp_core_signup_avatar_upload_dir() {
  528. global $bp;
  529.  
  530. if ( !$bp->signup->avatar_dir )
  531. return false;
  532.  
  533. $path = BP_AVATAR_UPLOAD_PATH . '/avatars/signups/' . $bp->signup->avatar_dir;
  534. $newbdir = $path;
  535.  
  536. if ( !file_exists( $path ) )
  537. @wp_mkdir_p( $path );
  538.  
  539. $newurl = BP_AVATAR_URL . '/avatars/signups/' . $bp->signup->avatar_dir;
  540. $newburl = $newurl;
  541. $newsubdir = '/avatars/signups/' . $bp->signup->avatar_dir;
  542.  
  543. return apply_filters( 'bp_core_signup_avatar_upload_dir', array( 'path' => $path, 'url' => $newurl, 'subdir' => $newsubdir, 'basedir' => $newbdir, 'baseurl' => $newburl, 'error' => false ) );
  544. }
  545.  
  546. function bp_core_signup_send_validation_email( $user_id, $user_email, $key ) {
  547. $activate_url = bp_get_activation_page() ."?key=$key";
  548. $activate_url = esc_url( $activate_url );
  549. $admin_email = get_site_option( "admin_email" );
  550.  
  551. if ( empty( $admin_email ) )
  552. $admin_email = 'noreply@' . $_SERVER['SERVER_NAME'];
  553.  
  554. $from_name = ( '' == get_option( 'blogname' ) ) ? 'BuddyPress' : wp_specialchars( get_option( 'blogname' ) );
  555. $message_headers = "MIME-Version: 1.0\n" . "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option( 'blog_charset' ) . "\"\n";
  556. $message = sprintf( __( "Thanks for registering! To complete the activation of your account please click the following link:\n\n%s\n\n", 'buddypress' ), $activate_url );
  557. $subject = '[' . $from_name . '] ' . __( 'Activate Your Account', 'buddypress' );
  558.  
  559. /* Send the message */
  560. $to = apply_filters( 'bp_core_activation_signup_user_notification_to', $user_email );
  561. $subject = apply_filters( 'bp_core_activation_signup_user_notification_subject', $subject );
  562. $message = apply_filters( 'bp_core_activation_signup_user_notification_message', $message );
  563.  
  564. wp_mail( $to, $subject, $message, $message_headers );
  565. }
  566.  
  567. /* Stop user accounts logging in that have not been activated (user_status = 2) */
  568. function bp_core_signup_disable_inactive( $auth_obj, $username ) {
  569. global $bp, $wpdb;
  570.  
  571. if ( !$user_id = bp_core_get_userid( $username ) )
  572. return $auth_obj;
  573.  
  574. $user_status = (int) $wpdb->get_var( $wpdb->prepare( "SELECT user_status FROM $wpdb->users WHERE ID = %d", $user_id ) );
  575.  
  576. if ( 2 == $user_status )
  577. bp_core_redirect( $bp->root_domain );
  578. else
  579. return $auth_obj;
  580. }
  581. add_filter( 'authenticate', 'bp_core_signup_disable_inactive', 11, 2 );
  582.  
  583. /* Kill the wp-signup.php if custom registration signup templates are present */
  584. function bp_core_wpsignup_redirect() {
  585. if ( false === strpos( $_SERVER['SCRIPT_NAME'], 'wp-signup.php') && $_GET['action'] != 'register' )
  586. return false;
  587.  
  588. if ( locate_template( array( 'registration/register.php' ), false ) || locate_template( array( 'register.php' ), false ) )
  589. bp_core_redirect( bp_get_root_domain() . '/' . BP_REGISTER_SLUG . '/' );
  590. }
  591. if ( bp_core_is_multisite() )
  592. add_action( 'wp', 'bp_core_wpsignup_redirect' );
  593. else
  594. add_action( 'init', 'bp_core_wpsignup_redirect' );
  595.  
  596. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement