Changeset 28454
- Timestamp:
- 05/16/2014 06:15:00 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/user.php
r28420 r28454 1536 1536 global $wpdb; 1537 1537 1538 if ( is_a( $userdata, 'stdClass' ) ) 1538 if ( is_a( $userdata, 'stdClass' ) ) { 1539 1539 $userdata = get_object_vars( $userdata ); 1540 elseif ( is_a( $userdata, 'WP_User' ) )1540 } elseif ( is_a( $userdata, 'WP_User' ) ) { 1541 1541 $userdata = $userdata->to_array(); 1542 1543 extract( $userdata, EXTR_SKIP ); 1544 1542 } 1545 1543 // Are we updating or creating? 1546 if ( ! empty($ID) ) {1547 $ID = (int) $ ID;1544 if ( ! empty( $userdata['ID'] ) ) { 1545 $ID = (int) $userdata['ID']; 1548 1546 $update = true; 1549 1547 $old_user_data = WP_User::get_data_by( 'id', $ID ); 1548 // hashed in wp_update_user(), plaintext if called directly 1549 $user_pass = $userdata['user_pass']; 1550 1550 } else { 1551 1551 $update = false; 1552 1552 // Hash the password 1553 $user_pass = wp_hash_password( $user_pass);1554 } 1555 1556 $ user_login = sanitize_user($user_login, true);1553 $user_pass = wp_hash_password( $userdata['user_pass'] ); 1554 } 1555 1556 $sanitized_user_login = sanitize_user( $userdata['user_login'], true ); 1557 1557 1558 1558 /** … … 1563 1563 * @since 2.0.3 1564 1564 * 1565 * @param string $ user_login Username after it has been sanitized.1566 */ 1567 $ user_login = apply_filters( 'pre_user_login', $user_login );1565 * @param string $sanitized_user_login Username after it has been sanitized. 1566 */ 1567 $pre_user_login = apply_filters( 'pre_user_login', $sanitized_user_login ); 1568 1568 1569 1569 //Remove any non-printable chars from the login string to see if we have ended up with an empty username 1570 $user_login = trim( $user_login);1571 1572 if ( empty( $user_login) )1570 $user_login = trim( $pre_user_login ); 1571 1572 if ( empty( $user_login ) ) { 1573 1573 return new WP_Error('empty_user_login', __('Cannot create a user with an empty login name.') ); 1574 1575 if ( ! $update && username_exists( $user_login ) )1574 } 1575 if ( ! $update && username_exists( $user_login ) ) { 1576 1576 return new WP_Error( 'existing_user_login', __( 'Sorry, that username already exists!' ) ); 1577 1578 if ( empty( $user_nicename) )1577 } 1578 if ( empty( $userdata['user_nicename'] ) ) { 1579 1579 $user_nicename = sanitize_title( $user_login ); 1580 1580 } else { 1581 $user_nicename = $userdata['user_nicename']; 1582 } 1581 1583 /** 1582 1584 * Filter a user's nicename before the user is created or updated. … … 1588 1590 $user_nicename = apply_filters( 'pre_user_nicename', $user_nicename ); 1589 1591 1590 if ( empty($user_url) ) 1591 $user_url = ''; 1592 $user_url = empty( $userdata['user_url'] ) ? '' : $userdata['user_url']; 1592 1593 1593 1594 /** … … 1600 1601 $user_url = apply_filters( 'pre_user_url', $user_url ); 1601 1602 1602 if ( empty($user_email) ) 1603 $user_email = ''; 1603 $user_email = empty( $userdata['user_email'] ) ? '' : $userdata['user_email']; 1604 1604 1605 1605 /** … … 1612 1612 $user_email = apply_filters( 'pre_user_email', $user_email ); 1613 1613 1614 if ( ! $update && ! defined( 'WP_IMPORTING' ) && email_exists($user_email) )1614 if ( ! $update && ! defined( 'WP_IMPORTING' ) && email_exists( $user_email ) ) { 1615 1615 return new WP_Error( 'existing_user_email', __( 'Sorry, that email address is already used!' ) ); 1616 1617 if ( empty($nickname) ) 1618 $nickname = $user_login; 1619 1616 } 1617 $nickname = empty( $userdata['nickname'] ) ? $user_login : $userdata['nickname']; 1620 1618 /** 1621 1619 * Filter a user's nickname before the user is created or updated. … … 1627 1625 $nickname = apply_filters( 'pre_user_nickname', $nickname ); 1628 1626 1629 if ( empty($first_name) ) 1630 $first_name = ''; 1627 $first_name = empty( $userdata['first_name'] ) ? '' : $userdata['first_name']; 1631 1628 1632 1629 /** … … 1639 1636 $first_name = apply_filters( 'pre_user_first_name', $first_name ); 1640 1637 1641 if ( empty($last_name) ) 1642 $last_name = ''; 1638 $last_name = empty( $userdata['last_name'] ) ? '' : $userdata['last_name']; 1643 1639 1644 1640 /** … … 1651 1647 $last_name = apply_filters( 'pre_user_last_name', $last_name ); 1652 1648 1653 if ( empty( $ display_name) ) {1654 if ( $update ) 1649 if ( empty( $userdata['display_name'] ) ) { 1650 if ( $update ) { 1655 1651 $display_name = $user_login; 1656 elseif ( $first_name && $last_name )1652 } elseif ( $first_name && $last_name ) { 1657 1653 /* translators: 1: first name, 2: last name */ 1658 1654 $display_name = sprintf( _x( '%1$s %2$s', 'Display name based on first name and last name' ), $first_name, $last_name ); 1659 elseif ( $first_name )1655 } elseif ( $first_name ) { 1660 1656 $display_name = $first_name; 1661 elseif ( $last_name )1657 } elseif ( $last_name ) { 1662 1658 $display_name = $last_name; 1663 else1659 } else { 1664 1660 $display_name = $user_login; 1661 } 1662 } else { 1663 $display_name = $userdata['display_name']; 1665 1664 } 1666 1665 … … 1674 1673 $display_name = apply_filters( 'pre_user_display_name', $display_name ); 1675 1674 1676 if ( empty($description) ) 1677 $description = ''; 1675 $description = empty( $userdata['description'] ) ? '' : $userdata['description']; 1678 1676 1679 1677 /** … … 1686 1684 $description = apply_filters( 'pre_user_description', $description ); 1687 1685 1688 if ( empty($rich_editing) ) 1689 $rich_editing = 'true'; 1690 1691 if ( empty($comment_shortcuts) ) 1692 $comment_shortcuts = 'false'; 1693 1694 if ( empty($admin_color) ) 1695 $admin_color = 'fresh'; 1696 $admin_color = preg_replace('|[^a-z0-9 _.\-@]|i', '', $admin_color); 1697 1698 if ( empty($use_ssl) ) 1699 $use_ssl = 0; 1700 1701 if ( empty($user_registered) ) 1702 $user_registered = gmdate('Y-m-d H:i:s'); 1703 1704 if ( empty($show_admin_bar_front) ) 1705 $show_admin_bar_front = 'true'; 1686 $rich_editing = empty( $userdata['rich_editing'] ) ? 'true' : $userdata['rich_editing']; 1687 1688 $comment_shortcuts = empty( $userdata['comment_shortcuts'] ) ? 'false' : $userdata['comment_shortcuts']; 1689 1690 $admin_color = empty( $userdata['admin_color'] ) ? 'fresh' : $userdata['admin_color']; 1691 $admin_color = preg_replace( '|[^a-z0-9 _.\-@]|i', '', $admin_color ); 1692 1693 $use_ssl = empty( $userdata['use_ssl'] ) ? 0 : $userdata['use_ssl']; 1694 1695 $user_registered = empty( $userdata['user_registered'] ) ? gmdate( 'Y-m-d H:i:s' ) : $userdata['user_registered']; 1696 1697 $show_admin_bar_front = empty( $userdata['show_admin_bar_front'] ) ? 'true' : $userdata['show_admin_bar_front']; 1706 1698 1707 1699 $user_nicename_check = $wpdb->get_var( $wpdb->prepare("SELECT ID FROM $wpdb->users WHERE user_nicename = %s AND user_login != %s LIMIT 1" , $user_nicename, $user_login)); … … 1731 1723 1732 1724 foreach ( _get_additional_user_keys( $user ) as $key ) { 1733 if ( isset( $$key ) ) 1725 if ( isset( $$key ) ) { 1734 1726 update_user_meta( $user_id, $key, $$key ); 1735 } 1736 1737 if ( isset($role) ) 1738 $user->set_role($role); 1739 elseif ( !$update ) 1727 } 1728 } 1729 1730 if ( isset( $userdata['role'] ) ) { 1731 $user->set_role( $userdata['role'] ); 1732 } elseif ( ! $update ) { 1740 1733 $user->set_role(get_option('default_role')); 1741 1742 wp_cache_delete( $user_id, 'users');1743 wp_cache_delete( $user_login, 'userlogins');1734 } 1735 wp_cache_delete( $user_id, 'users' ); 1736 wp_cache_delete( $user_login, 'userlogins' ); 1744 1737 1745 1738 if ( $update ) {
Note: See TracChangeset
for help on using the changeset viewer.