Make WordPress Core


Ignore:
Timestamp:
10/19/2011 10:35:15 PM (13 years ago)
Author:
ryan
Message:

Turn is_blog_user() into a wrapper around is_user_member_of_blog() and deprecate. Make user_id optional for is_user_member_of_blog(). Props SergeyBiryukov. fixes #16702

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/user.php

    r19005 r19016  
    721721
    722722/**
    723  * Checks if the current user belong to a given blog.
    724  *
    725  * @since MU
    726  *
    727  * @param int $blog_id Blog ID
    728  * @return bool True if the current users belong to $blog_id, false if not.
    729  */
    730 function is_blog_user( $blog_id = 0 ) {
    731     global $wpdb;
    732 
    733     if ( ! $blog_id )
     723 * Find out whether a user is a member of a given blog.
     724 *
     725 * @since MU 1.1
     726 * @uses get_blogs_of_user()
     727 *
     728 * @param int $user_id The unique ID of the user
     729 * @param int $blog Optional. If no blog_id is provided, current site is used
     730 * @return bool
     731 */
     732function is_user_member_of_blog( $user_id = 0, $blog_id = 0 ) {
     733    $user_id = (int) $user_id;
     734    $blog_id = (int) $blog_id;
     735
     736    if ( empty( $user_id ) )
     737        $user_id = get_current_user_id();
     738
     739    if ( empty( $blog_id ) ) {
     740        global $wpdb;
    734741        $blog_id = $wpdb->blogid;
    735 
    736     $blogs = get_blogs_of_user( get_current_user_id() );
    737 
    738     return is_array( $blogs ) && array_key_exists( $blog_id, $blogs );
     742    }
     743
     744    $blogs = get_blogs_of_user( $user_id );
     745    if ( is_array( $blogs ) )
     746        return array_key_exists( $blog_id, $blogs );
     747    else
     748        return false;
    739749}
    740750
Note: See TracChangeset for help on using the changeset viewer.