bb_reset_password

Handles the resetting of users' passwords.

Description

bb_reset_password( (string) $key ); 

Handles resetting a user's password, prompted by an email sent by buddypress/2.8.2/functions/bb_reset_email/" title="bb_reset_email" class="code function">bb_reset_email()

Parameters (1)

0. $key (string)
The key.

Usage

  1. if ( !function_exists( 'bb_reset_password' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-forums/bbpress/bb-includes/functions.bb-users.php'; 
  3.  
  4. // The key. 
  5. $key = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bb_reset_password($key); 
  9.  

Defined (1)

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

/bp-forums/bbpress/bb-includes/functions.bb-users.php  
  1. function bb_reset_password( $key ) 
  2. global $bbdb; 
  3.  
  4. $key = sanitize_user( $key, true ); 
  5.  
  6. if ( empty( $key ) || !is_string( $key ) ) { 
  7. return new WP_Error( 'invalid_key', __( 'Invalid key' ) ); 
  8.  
  9. if ( !$user_id = $bbdb->get_var( $bbdb->prepare( "SELECT user_id FROM $bbdb->usermeta WHERE meta_key = 'newpwdkey' AND meta_value = %s", $key ) ) ) { 
  10. return new WP_Error( 'invalid_key', __( 'Invalid key' ) ); 
  11.  
  12. $user = new BP_User( $user_id ); 
  13.  
  14. if ( !$user || is_wp_error( $user ) ) { 
  15. return new WP_Error( 'invalid_key', __( 'Invalid key' ) ); 
  16.  
  17. if ( bb_has_broken_pass( $user->ID ) ) { 
  18.  
  19. if ( !$user->has_cap( 'change_user_password', $user->ID ) ) { 
  20. return new WP_Error( 'permission_denied', __( 'You are not allowed to change your password.' ) ); 
  21.  
  22. $newpass = bb_generate_password(); 
  23. bb_update_user_password( $user->ID, $newpass ); 
  24. if ( !bb_send_pass( $user->ID, $newpass ) ) { 
  25. return new WP_Error( 'sending_mail_failed', __( 'The email containing the new password could not be sent.' ) ); 
  26.  
  27. bb_update_usermeta( $user->ID, 'newpwdkey', '' ); 
  28. return true;