WordPress.org

Make WordPress Core

Changeset 23438


Ignore:
Timestamp:
02/16/13 03:02:15 (3 years ago)
Author:
nacin
Message:

Deprecate get_user_id_from_string() in favor of get_user_by( $field ) where $field is 'email' or 'login'. props SergeyBiryukov. fixes #23190.

Location:
trunk/wp-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/ms-deprecated.php

    r21480 r23438  
    271271    return $url; 
    272272} 
     273 
     274/** 
     275 * Get a numeric user ID from either an email address or a login. 
     276 * 
     277 * A numeric string is considered to be an existing user ID 
     278 * and is simply returned as such. 
     279 * 
     280 * @since MU 
     281 * @deprecated 3.6.0 
     282 * @deprecated Use get_user_by() 
     283 * @uses get_user_by() 
     284 * 
     285 * @param string $string Either an email address or a login. 
     286 * @return int 
     287 */ 
     288function get_user_id_from_string( $string ) { 
     289    _deprecated_function( __FUNCTION__, '3.6', 'get_user_by()' ); 
     290 
     291    if ( is_email( $string ) ) 
     292        $user = get_user_by( 'email', $string ); 
     293    elseif ( is_numeric( $string ) ) 
     294        return $string; 
     295    else 
     296        $user = get_user_by( 'login', $string ); 
     297 
     298    if ( $user ) 
     299        return $user->ID; 
     300    return 0; 
     301} 
  • trunk/wp-includes/ms-functions.php

    r23432 r23438  
    909909 
    910910    $user = new WP_User( $user_id ); 
    911      
     911 
    912912    // Newly created users have no roles or caps until they are added to a blog. 
    913913    delete_user_option( $user_id, $user->cap_key ); 
     
    13151315    global $current_site; 
    13161316    return $current_site; 
    1317 } 
    1318  
    1319 /** 
    1320  * Get a numeric user ID from either an email address or a login. 
    1321  * 
    1322  * @since MU 
    1323  * @uses is_email() 
    1324  * 
    1325  * @param string $string 
    1326  * @return int 
    1327  */ 
    1328 function get_user_id_from_string( $string ) { 
    1329     $user_id = 0; 
    1330     if ( is_email( $string ) ) { 
    1331         $user = get_user_by('email', $string); 
    1332         if ( $user ) 
    1333             $user_id = $user->ID; 
    1334     } elseif ( is_numeric( $string ) ) { 
    1335         $user_id = $string; 
    1336     } else { 
    1337         $user = get_user_by('login', $string); 
    1338         if ( $user ) 
    1339             $user_id = $user->ID; 
    1340     } 
    1341  
    1342     return $user_id; 
    13431317} 
    13441318 
     
    17311705 
    17321706/** 
    1733  * Check to see whether a user is marked as a spammer, based on username 
     1707 * Check to see whether a user is marked as a spammer, based on user login. 
    17341708 * 
    17351709 * @since MU 
    17361710 * @uses get_user_by() 
    17371711 * 
    1738  * @param string $username 
     1712 * @param string $user_login Optional. Defaults to current user. 
    17391713 * @return bool 
    17401714 */ 
    1741 function is_user_spammy( $username = 0 ) { 
    1742     if ( $username == 0 ) { 
     1715function is_user_spammy( $user_login = null ) { 
     1716    if ( $user_login ) 
     1717        $user = get_user_by( 'login', $user_login ); 
     1718    else 
    17431719        $user = wp_get_current_user(); 
    1744     } else { 
    1745         $user = get_user_by( 'login', $username ); 
    1746     } 
    1747  
    1748     return ( isset( $user->spam ) && $user->spam == 1 ); 
     1720 
     1721    return $user && isset( $user->spam ) && 1 == $user->spam; 
    17491722} 
    17501723 
Note: See TracChangeset for help on using the changeset viewer.