Guest User

Untitled

a guest
May 20th, 2018
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.59 KB | None | 0 0
  1. <?php
  2. // Exit if accessed directly
  3. if ( !defined( 'ABSPATH' ) ) exit;
  4.  
  5. /** General *******************************************************************/
  6.  
  7. function bp_core_screen_general_settings() {
  8. global $bp;
  9.  
  10. if ( bp_action_variables() ) {
  11. bp_do_404();
  12. return;
  13. }
  14.  
  15. // Setup private variables
  16. $bp_settings_updated = $pass_error = $email_error = $pwd_error = false;
  17.  
  18. if ( isset( $_POST['submit'] ) ) {
  19.  
  20. // Nonce check
  21. check_admin_referer('bp_settings_general');
  22.  
  23. // Validate the user again for the current password when making a big change
  24. if ( is_super_admin() || ( !empty( $_POST['pwd'] ) && $_POST['pwd'] != '' && wp_check_password( $_POST['pwd'], $bp->displayed_user->userdata->user_pass, $bp->displayed_user->id ) ) ) {
  25.  
  26. $update_user = get_userdata( $bp->displayed_user->id );
  27.  
  28. // The structure of the $update_user object changed in WP 3.3, but
  29. // wp_update_user() still expects the old format
  30. if ( isset( $update_user->data ) && is_object( $update_user->data ) ) {
  31. $update_user = $update_user->data;
  32. }
  33.  
  34. // Make sure changing an email address does not already exist
  35. if ( $_POST['email'] != '' ) {
  36.  
  37. // What is missing from the profile page vs signup - lets double check the goodies
  38. $user_email = sanitize_email( esc_html( trim( $_POST['email'] ) ) );
  39.  
  40. // Is email valid
  41. if ( !is_email( $user_email ) )
  42. $email_error = true;
  43.  
  44. // Get blocked email domains
  45. $limited_email_domains = get_site_option( 'limited_email_domains', 'buddypress' );
  46.  
  47. // If blocked email domains exist, see if this is one of them
  48. if ( is_array( $limited_email_domains ) && empty( $limited_email_domains ) == false ) {
  49. $emaildomain = substr( $user_email, 1 + strpos( $user_email, '@' ) );
  50.  
  51. if ( in_array( $emaildomain, (array)$limited_email_domains ) == false ) {
  52. $email_error = true;
  53. }
  54. }
  55.  
  56. // No errors, and email address doesn't match
  57. if ( ( false === $email_error ) && ( $bp->displayed_user->userdata->user_email != $user_email ) ) {
  58.  
  59. // We don't want email dupes in the system
  60. if ( email_exists( $user_email ) )
  61. $email_error = true;
  62.  
  63. // Set updated user email to this email address
  64. $update_user->user_email = $user_email;
  65. }
  66. }
  67.  
  68. // Password change
  69. if ( !empty( $_POST['pass1'] ) && !empty( $_POST['pass2'] ) ) {
  70.  
  71. // Password change attempt is successful
  72. if ( $_POST['pass1'] == $_POST['pass2'] && !strpos( " " . $_POST['pass1'], "\\" ) ) {
  73. $update_user->user_pass = $_POST['pass1'];
  74.  
  75. // Password change attempt was unsuccessful
  76. } else {
  77. $pass_error = true;
  78. }
  79.  
  80. // One of the password boxes was left empty
  81. } else if ( ( empty( $_POST['pass1'] ) && !empty( $_POST['pass2'] ) ) || ( !empty( $_POST['pass1'] ) && empty( $_POST['pass2'] ) ) ) {
  82. $pass_error = true;
  83.  
  84. // Not a password change attempt so empty the user_pass
  85. } else {
  86. unset( $update_user->user_pass );
  87. }
  88.  
  89. // Make sure these changes are in $bp for the current page load
  90. if ( ( false === $email_error ) && ( false === $pass_error ) && ( wp_update_user( get_object_vars( $update_user ) ) ) ) {
  91. $bp->displayed_user->userdata = bp_core_get_core_userdata( $bp->displayed_user->id, true );
  92. $bp_settings_updated = true;
  93. }
  94.  
  95. // Password Error
  96. } else {
  97. $pwd_error = true;
  98. }
  99.  
  100. // Add user feedback messages
  101. if ( empty( $pass_error ) && empty( $pwd_error ) && ( empty( $email_error ) ) )
  102. bp_core_add_message( __( 'Changes saved.', 'buddypress' ), 'success' );
  103.  
  104. elseif ( !empty( $pass_error ) )
  105. bp_core_add_message( __( 'Your new passwords did not match.', 'buddypress' ), 'error' );
  106.  
  107. elseif ( !empty( $pwd_error ) )
  108. bp_core_add_message( __( 'Your existing password is incorrect.', 'buddypress' ), 'error' );
  109.  
  110. elseif ( !empty( $email_error ) )
  111. bp_core_add_message( __( 'Sorry, that email address is already used or is invalid.', 'buddypress' ), 'error' );
  112.  
  113. // Execute additional code
  114. do_action( 'bp_core_general_settings_after_save' );
  115. }
  116.  
  117. // Load the template
  118. bp_core_load_template( apply_filters( 'bp_core_screen_general_settings', 'members/single/settings/general' ) );
  119. }
  120.  
  121. /** Notifications *************************************************************/
  122.  
  123. function bp_core_screen_notification_settings() {
  124. global $bp;
  125.  
  126. if ( bp_action_variables() ) {
  127. bp_do_404();
  128. return;
  129. }
  130.  
  131. if ( isset( $_POST['submit'] ) ) {
  132. check_admin_referer('bp_settings_notifications');
  133.  
  134. if ( isset( $_POST['notifications'] ) ) {
  135. foreach ( (array)$_POST['notifications'] as $key => $value ) {
  136. if ( $meta_key = bp_get_user_meta_key( $key ) )
  137. bp_update_user_meta( (int)$bp->displayed_user->id, $meta_key, $value );
  138. }
  139. }
  140.  
  141. bp_core_add_message( __( 'Changes saved.', 'buddypress' ), 'success' );
  142.  
  143. do_action( 'bp_core_notification_settings_after_save' );
  144. }
  145.  
  146. bp_core_load_template( apply_filters( 'bp_core_screen_notification_settings', 'members/single/settings/notifications' ) );
  147. }
  148.  
  149. /** Delete Account ************************************************************/
  150.  
  151. function bp_core_screen_delete_account() {
  152. global $bp;
  153.  
  154. if ( bp_action_variables() ) {
  155. bp_do_404();
  156. return;
  157. }
  158.  
  159. if ( isset( $_POST['delete-account-understand'] ) ) {
  160. // Nonce check
  161. check_admin_referer( 'delete-account' );
  162.  
  163. // delete the users account
  164. if ( bp_core_delete_account( $bp->displayed_user->id ) ) {
  165. bp_core_redirect( home_url() );
  166. }
  167. }
  168.  
  169. // Load the template
  170. bp_core_load_template( apply_filters( 'bp_core_screen_delete_account', 'members/single/settings/delete-account' ) );
  171. }
  172.  
  173. ?>
Add Comment
Please, Sign In to add comment