bbp_edit_user_handler

Handles the front end user editing.

Description

bbp_edit_user_handler( (string) $action = '' ); 

Parameters (1)

0. $action — Optional. (string) => ''
The requested action to compare this function to

Usage

  1. if ( !function_exists( 'bbp_edit_user_handler' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/users/functions.php'; 
  3.  
  4. // The requested action to compare this function to 
  5. $action = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bbp_edit_user_handler($action); 
  9.  

Defined (1)

The function is defined in the following location(s).

/includes/users/functions.php  
  1. function bbp_edit_user_handler( $action = '' ) { 
  2.  
  3. // Bail if action is not 'bbp-update-user' 
  4. if ( 'bbp-update-user' !== $action ) 
  5. return; 
  6.  
  7. // Get the displayed user ID 
  8. $user_id = bbp_get_displayed_user_id(); 
  9.  
  10. // Execute confirmed email change. See send_confirmation_on_profile_email(). 
  11. if ( is_multisite() && bbp_is_user_home_edit() && isset( $_GET['newuseremail'] ) ) { 
  12.  
  13. $new_email = get_option( $user_id . '_new_email' ); 
  14.  
  15. if ( hash_equals( $new_email['hash'], $_GET['newuseremail'] ) ) { 
  16. $user = new WP_User(); 
  17. $user->ID = $user_id; 
  18. $user->user_email = esc_html( trim( $new_email['newemail'] ) ); 
  19.  
  20. global $wpdb; 
  21.  
  22. if ( $wpdb->get_var( $wpdb->prepare( "SELECT user_login FROM {$wpdb->signups} WHERE user_login = %s", bbp_get_displayed_user_field( 'user_login', 'raw' ) ) ) ) { 
  23. $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->signups} SET user_email = %s WHERE user_login = %s", $user->user_email, bbp_get_displayed_user_field( 'user_login', 'raw' ) ) ); 
  24.  
  25. wp_update_user( get_object_vars( $user ) ); 
  26. delete_option( $user_id . '_new_email' ); 
  27.  
  28. wp_safe_redirect( add_query_arg( array( 'updated' => 'true' ), bbp_get_user_profile_edit_url( $user_id ) ) ); 
  29. exit(); 
  30.  
  31. // Delete new email address from user options 
  32. } elseif ( is_multisite() && bbp_is_user_home_edit() && !empty( $_GET['dismiss'] ) && ( $user_id . '_new_email' === $_GET['dismiss'] ) ) { 
  33. delete_option( $user_id . '_new_email' ); 
  34. wp_safe_redirect( add_query_arg( array( 'updated' => 'true' ), bbp_get_user_profile_edit_url( $user_id ) ) ); 
  35. exit(); 
  36.  
  37. // Nonce check 
  38. if ( ! bbp_verify_nonce_request( 'update-user_' . $user_id ) ) { 
  39. bbp_add_error( 'bbp_update_user_nonce', __( '<strong>ERROR</strong>: Are you sure you wanted to do that?', bbpress ) ); 
  40. return; 
  41.  
  42. // Cap check 
  43. if ( ! current_user_can( 'edit_user', $user_id ) ) { 
  44. bbp_add_error( 'bbp_update_user_capability', __( '<strong>ERROR</strong>: Are you sure you wanted to do that?', bbpress ) ); 
  45. return; 
  46.  
  47. // Do action based on who's profile you're editing 
  48. $edit_action = bbp_is_user_home_edit() ? 'personal_options_update' : 'edit_user_profile_update'; 
  49. do_action( $edit_action, $user_id ); 
  50.  
  51. // Prevent edit_user() from wiping out the user's Toolbar on front setting 
  52. if ( !isset( $_POST['admin_bar_front'] ) && _get_admin_bar_pref( 'front', $user_id ) ) { 
  53. $_POST['admin_bar_front'] = 1; 
  54.  
  55. // Handle user edit 
  56. $edit_user = edit_user( $user_id ); 
  57.  
  58. // Error(s) editng the user, so copy them into the global 
  59. if ( is_wp_error( $edit_user ) ) { 
  60. bbpress)->errors = $edit_user; 
  61.  
  62. // Successful edit to redirect 
  63. } elseif ( is_integer( $edit_user ) ) { 
  64.  
  65. // Maybe update super admin ability 
  66. if ( is_multisite() && ! bbp_is_user_home_edit() && current_user_can( 'manage_network_options' ) && is_super_admin() ) { 
  67. empty( $_POST['super_admin'] ) ? revoke_super_admin( $edit_user ) : grant_super_admin( $edit_user ); 
  68.  
  69. $redirect = add_query_arg( array( 'updated' => 'true' ), bbp_get_user_profile_edit_url( $edit_user ) ); 
  70.  
  71. wp_safe_redirect( $redirect ); 
  72. exit;