Changeset 25231 for trunk/src/wp-includes/user.php
- Timestamp:
- 09/04/2013 08:58:41 AM (12 years ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/user.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/user.php
r24850 r25231 1551 1551 return apply_filters( 'user_contactmethods', $user_contactmethods, $user ); 1552 1552 } 1553 1554 /** 1555 * Retrieves a user row based on password reset key and login 1556 * 1557 * @uses $wpdb WordPress Database object 1558 * 1559 * @param string $key Hash to validate sending user's password 1560 * @param string $login The user login 1561 * @return object|WP_Error User's database row on success, error object for invalid keys 1562 */ 1563 function check_password_reset_key( $key, $login ) { 1564 global $wpdb; 1565 1566 $key = preg_replace( '/[^a-z0-9]/i', '', $key ); 1567 1568 if ( empty( $key ) || ! is_string( $key ) ) 1569 return new WP_Error( 'invalid_key', __( 'Invalid key' ) ); 1570 1571 if ( empty( $login ) || ! is_string( $login ) ) 1572 return new WP_Error( 'invalid_key', __( 'Invalid key' ) ); 1573 1574 $user = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->users WHERE user_activation_key = %s AND user_login = %s", $key, $login ) ); 1575 1576 if ( empty( $user ) ) 1577 return new WP_Error( 'invalid_key', __( 'Invalid key' ) ); 1578 1579 return $user; 1580 } 1581 1582 /** 1583 * Handles resetting the user's password. 1584 * 1585 * @param object $user The user 1586 * @param string $new_pass New password for the user in plaintext 1587 */ 1588 function reset_password( $user, $new_pass ) { 1589 do_action( 'password_reset', $user, $new_pass ); 1590 1591 wp_set_password( $new_pass, $user->ID ); 1592 update_user_option( $user->ID, 'default_password_nag', false, true ); 1593 1594 wp_password_change_notification( $user ); 1595 } 1596 1597 /** 1598 * Handles registering a new user. 1599 * 1600 * @param string $user_login User's username for logging in 1601 * @param string $user_email User's email address to send password and add 1602 * @return int|WP_Error Either user's ID or error on failure. 1603 */ 1604 function register_new_user( $user_login, $user_email ) { 1605 $errors = new WP_Error(); 1606 1607 $sanitized_user_login = sanitize_user( $user_login ); 1608 $user_email = apply_filters( 'user_registration_email', $user_email ); 1609 1610 // Check the username 1611 if ( $sanitized_user_login == '' ) { 1612 $errors->add( 'empty_username', __( '<strong>ERROR</strong>: Please enter a username.' ) ); 1613 } elseif ( ! validate_username( $user_login ) ) { 1614 $errors->add( 'invalid_username', __( '<strong>ERROR</strong>: This username is invalid because it uses illegal characters. Please enter a valid username.' ) ); 1615 $sanitized_user_login = ''; 1616 } elseif ( username_exists( $sanitized_user_login ) ) { 1617 $errors->add( 'username_exists', __( '<strong>ERROR</strong>: This username is already registered. Please choose another one.' ) ); 1618 } 1619 1620 // Check the e-mail address 1621 if ( $user_email == '' ) { 1622 $errors->add( 'empty_email', __( '<strong>ERROR</strong>: Please type your e-mail address.' ) ); 1623 } elseif ( ! is_email( $user_email ) ) { 1624 $errors->add( 'invalid_email', __( '<strong>ERROR</strong>: The email address isn’t correct.' ) ); 1625 $user_email = ''; 1626 } elseif ( email_exists( $user_email ) ) { 1627 $errors->add( 'email_exists', __( '<strong>ERROR</strong>: This email is already registered, please choose another one.' ) ); 1628 } 1629 1630 do_action( 'register_post', $sanitized_user_login, $user_email, $errors ); 1631 1632 $errors = apply_filters( 'registration_errors', $errors, $sanitized_user_login, $user_email ); 1633 1634 if ( $errors->get_error_code() ) 1635 return $errors; 1636 1637 $user_pass = wp_generate_password( 12, false ); 1638 $user_id = wp_create_user( $sanitized_user_login, $user_pass, $user_email ); 1639 if ( ! $user_id || is_wp_error( $user_id ) ) { 1640 $errors->add( 'registerfail', sprintf( __( '<strong>ERROR</strong>: Couldn’t register you… please contact the <a href="mailto:%s">webmaster</a> !' ), get_option( 'admin_email' ) ) ); 1641 return $errors; 1642 } 1643 1644 update_user_option( $user_id, 'default_password_nag', true, true ); //Set up the Password change nag. 1645 1646 wp_new_user_notification( $user_id, $user_pass ); 1647 1648 return $user_id; 1649 }
Note: See TracChangeset
for help on using the changeset viewer.