Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
11/02/2015 01:58:52 AM (9 years ago)
Author:
tw2113
Message:

More documentation cleanup for the Members component.

See #6402.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-members/bp-members-functions.php

    r10276 r10322  
    3939    $bp = buddypress();
    4040
    41     // No custom members slug
     41    // No custom members slug.
    4242    if ( !defined( 'BP_MEMBERS_SLUG' ) ) {
    4343        if ( !empty( $bp->pages->members ) ) {
     
    4848    }
    4949
    50     // No custom registration slug
     50    // No custom registration slug.
    5151    if ( !defined( 'BP_REGISTER_SLUG' ) ) {
    5252        if ( !empty( $bp->pages->register ) ) {
     
    5757    }
    5858
    59     // No custom activation slug
     59    // No custom activation slug.
    6060    if ( !defined( 'BP_ACTIVATION_SLUG' ) ) {
    6161        if ( !empty( $bp->pages->activate ) ) {
     
    9898function bp_core_get_users( $args = '' ) {
    9999
    100     // Parse the user query arguments
     100    // Parse the user query arguments.
    101101    $r = bp_parse_args( $args, array(
    102         'type'                => 'active',     // active, newest, alphabetical, random or popular
    103         'user_id'             => false,        // Pass a user_id to limit to only friend connections for this user
    104         'exclude'             => false,        // Users to exclude from results
    105         'search_terms'        => false,        // Limit to users that match these search terms
    106         'meta_key'            => false,        // Limit to users who have this piece of usermeta
    107         'meta_value'          => false,        // With meta_key, limit to users where usermeta matches this value
     102        'type'                => 'active',     // Active, newest, alphabetical, random or popular.
     103        'user_id'             => false,        // Pass a user_id to limit to only friend connections for this user.
     104        'exclude'             => false,        // Users to exclude from results.
     105        'search_terms'        => false,        // Limit to users that match these search terms.
     106        'meta_key'            => false,        // Limit to users who have this piece of usermeta.
     107        'meta_value'          => false,        // With meta_key, limit to users where usermeta matches this value.
    108108        'member_type'         => '',
    109109        'member_type__in'     => '',
    110110        'member_type__not_in' => '',
    111         'include'             => false,        // Pass comma separated list of user_ids to limit to only these users
    112         'per_page'            => 20,           // The number of results to return per page
    113         'page'                => 1,            // The page to return if limiting per page
    114         'populate_extras'     => true,         // Fetch the last active, where the user is a friend, total friend count, latest update
    115         'count_total'         => 'count_query' // What kind of total user count to do, if any. 'count_query', 'sql_calc_found_rows', or false
     111        'include'             => false,        // Pass comma separated list of user_ids to limit to only these users.
     112        'per_page'            => 20,           // The number of results to return per page.
     113        'page'                => 1,            // The page to return if limiting per page.
     114        'populate_extras'     => true,         // Fetch the last active, where the user is a friend, total friend count, latest update.
     115        'count_total'         => 'count_query' // What kind of total user count to do, if any. 'count_query', 'sql_calc_found_rows', or false.
    116116    ), 'core_get_users' );
    117117
     
    131131        );
    132132
    133     // Default behavior as of BuddyPress 1.7
     133    // Default behavior as of BuddyPress 1.7.0.
    134134    } else {
    135135
     
    161161 * @param string|bool $user_nicename Optional. user_nicename of the user.
    162162 * @param string|bool $user_login    Optional. user_login of the user.
    163  *
    164163 * @return string
    165164 */
     
    200199 *
    201200 * @param int $user_id The ID of the user.
    202  *
    203201 * @return array
    204202 */
     
    231229 *
    232230 * @param string $user_login user_login of the user being queried.
    233  *
    234231 * @return int
    235232 */
     
    244241 *
    245242 * @param string $username user_login to check.
    246  *
    247243 * @return int|null The ID of the matched user on success, null on failure.
    248244 */
     
    271267 *
    272268 * @param string $user_nicename user_nicename to check.
    273  *
    274269 * @return int|null The ID of the matched user on success, null on failure.
    275270 */
     
    301296 * @param string|bool $user_nicename Optional. user_nicename of user being checked.
    302297 * @param string|bool $user_login    Optional. user_login of user being checked.
    303  *
    304298 * @return string|bool The username of the matched user, or false.
    305299 */
     
    307301    $bp = buddypress();
    308302
    309     // Check cache for user nicename
     303    // Check cache for user nicename.
    310304    $username = wp_cache_get( 'bp_user_username_' . $user_id, 'bp' );
    311305    if ( false === $username ) {
    312306
    313         // Cache not found so prepare to update it
     307        // Cache not found so prepare to update it.
    314308        $update_cache = true;
    315309
    316         // Nicename and login were not passed
     310        // Nicename and login were not passed.
    317311        if ( empty( $user_nicename ) && empty( $user_login ) ) {
    318312
    319             // User ID matches logged in user
     313            // User ID matches logged in user.
    320314            if ( bp_loggedin_user_id() == $user_id ) {
    321315                $userdata = &$bp->loggedin_user->userdata;
    322316
    323             // User ID matches displayed in user
     317            // User ID matches displayed in user.
    324318            } elseif ( bp_displayed_user_id() == $user_id ) {
    325319                $userdata = &$bp->displayed_user->userdata;
    326320
    327             // No user ID match
     321            // No user ID match.
    328322            } else {
    329323                $userdata = false;
    330324            }
    331325
    332             // No match so go dig
     326            // No match so go dig.
    333327            if ( empty( $userdata ) ) {
    334328
    335                 // User not found so return false
     329                // User not found so return false.
    336330                if ( !$userdata = bp_core_get_core_userdata( $user_id ) ) {
    337331                    return false;
     
    339333            }
    340334
    341             // Update the $user_id for later
     335            // Update the $user_id for later.
    342336            $user_id       = $userdata->ID;
    343337
    344             // Two possible options
     338            // Two possible options.
    345339            $user_nicename = $userdata->user_nicename;
    346340            $user_login    = $userdata->user_login;
    347341        }
    348342
    349         // Pull an audible and maybe use the login over the nicename
     343        // Pull an audible and maybe use the login over the nicename.
    350344        $username = bp_is_username_compatibility_mode() ? $user_login : $user_nicename;
    351345
    352     // Username found in cache so don't update it again
     346    // Username found in cache so don't update it again.
    353347    } else {
    354348        $update_cache = false;
    355349    }
    356350
    357     // Add this to cache
     351    // Add this to cache.
    358352    if ( ( true === $update_cache ) && !empty( $username ) ) {
    359353        wp_cache_set( 'bp_user_username_' . $user_id, $username, 'bp' );
    360354
    361355    // @todo bust this cache if no $username found?
    362     //} else {
    363     //  wp_cache_delete( 'bp_user_username_' . $user_id );
     356    // } else {
     357    // wp_cache_delete( 'bp_user_username_' . $user_id );
    364358    }
    365359
     
    385379 *
    386380 * @param int $user_id User ID to check.
    387  *
    388381 * @return string|bool The username of the matched user, or false.
    389382 */
     
    394387        $update_cache = true;
    395388
    396         // User ID matches logged in user
     389        // User ID matches logged in user.
    397390        if ( bp_loggedin_user_id() == $user_id ) {
    398391            $userdata = &$bp->loggedin_user->userdata;
    399392
    400         // User ID matches displayed in user
     393        // User ID matches displayed in user.
    401394        } elseif ( bp_displayed_user_id() == $user_id ) {
    402395            $userdata = &$bp->displayed_user->userdata;
    403396
    404         // No user ID match
     397        // No user ID match.
    405398        } else {
    406399            $userdata = false;
    407400        }
    408401
    409         // No match so go dig
     402        // No match so go dig.
    410403        if ( empty( $userdata ) ) {
    411404
    412             // User not found so return false
     405            // User not found so return false.
    413406            if ( !$userdata = bp_core_get_core_userdata( $user_id ) ) {
    414407                return false;
     
    416409        }
    417410
    418         // User nicename found
     411        // User nicename found.
    419412        $user_nicename = $userdata->user_nicename;
    420413
    421     // Nicename found in cache so don't update it again
     414    // Nicename found in cache so don't update it again.
    422415    } else {
    423416        $update_cache = false;
    424417    }
    425418
    426     // Add this to cache
     419    // Add this to cache.
    427420    if ( true == $update_cache && !empty( $user_nicename ) ) {
    428421        wp_cache_set( 'bp_members_user_nicename_' . $user_id, $user_nicename, 'bp' );
     
    443436 *
    444437 * @param int $uid User ID to check.
    445  *
    446438 * @return string The email for the matched user. Empty string if no user
    447439 *                matched the $uid.
     
    451443    if ( !$email = wp_cache_get( 'bp_user_email_' . $uid, 'bp' ) ) {
    452444
    453         // User exists
     445        // User exists.
    454446        $ud = bp_core_get_core_userdata( $uid );
    455447        if ( ! empty( $ud ) ) {
    456448            $email = $ud->user_email;
    457449
    458         // User was deleted
     450        // User was deleted.
    459451        } else {
    460452            $email = '';
     
    477469 * Return a HTML formatted link for a user with the user's full name as the link text.
    478470 *
    479  * eg: <a href="http://andy.example.com/">Andy Peatling</a>
     471 * Eg: <a href="http://andy.example.com/">Andy Peatling</a>
    480472 *
    481473 * Optional parameters will return just the name or just the URL.
     
    486478 * @param bool $just_link Disable full name and HTML and just return the URL
    487479 *                        text. Default false.
    488  *
    489480 * @return string|bool The link text based on passed parameters, or false on
    490481 *                     no match.
     
    528519 * @since 2.0.0
    529520 *
    530  * @param array $user_ids
    531  *
     521 * @param array $user_ids Array of user IDs to get display names for.
    532522 * @return array
    533523 */
    534524function bp_core_get_user_displaynames( $user_ids ) {
    535525
    536     // Sanitize
     526    // Sanitize.
    537527    $user_ids = wp_parse_id_list( $user_ids );
    538528
    539     // Remove dupes and empties
     529    // Remove dupes and empties.
    540530    $user_ids = array_unique( array_filter( $user_ids ) );
    541531
     
    551541    }
    552542
    553     // Prime caches
     543    // Prime caches.
    554544    if ( ! empty( $uncached_ids ) ) {
    555545        if ( bp_is_active( 'xprofile' ) ) {
    556546            $fullname_data = BP_XProfile_ProfileData::get_value_byid( 1, $uncached_ids );
    557547
    558             // Key by user_id
     548            // Key by user_id.
    559549            $fullnames = array();
    560550            foreach ( $fullname_data as $fd ) {
     
    565555
    566556            // If xprofiledata is not found for any users,  we'll look
    567             // them up separately
     557            // them up separately.
    568558            $no_xprofile_ids = array_diff( $uncached_ids, array_keys( $fullnames ) );
    569559        } else {
     
    573563
    574564        if ( ! empty( $no_xprofile_ids ) ) {
    575             // Use WP_User_Query because we don't need BP information
     565            // Use WP_User_Query because we don't need BP information.
    576566            $query = new WP_User_Query( array(
    577567                'include'     => $no_xprofile_ids,
     
    585575
    586576                // If xprofile is active, set this value as the
    587                 // xprofile display name as well
     577                // xprofile display name as well.
    588578                if ( bp_is_active( 'xprofile' ) ) {
    589579                    xprofile_set_field_data( 1, $qr->ID, $fullnames[ $qr->ID ] );
     
    609599 *
    610600 * @param int|string|bool $user_id_or_username User ID or username.
    611  *
    612601 * @return string|bool The display name for the user in question, or false if
    613602 *                     user not found.
     
    655644 *
    656645 * @param string $email The email address for the user.
    657  *
    658646 * @return string The link to the users home base. False on no match.
    659647 */
     
    677665 *                         this should be user_login, otherwise it should
    678666 *                         be user_nicename.
    679  *
    680667 * @return string|bool The link to the user's domain, false on no match.
    681668 */
     
    739726        $bp = buddypress();
    740727
    741         // Avoid a costly join by splitting the lookup
     728        // Avoid a costly join by splitting the lookup.
    742729        if ( is_multisite() ) {
    743730            $sql = "SELECT ID FROM {$wpdb->users} WHERE (user_status != 0 OR deleted != 0 OR user_status != 0)";
     
    781768 *                              performed this cleanup independently, as when hooked
    782769 *                              to 'make_spam_user'.
    783  *
    784770 * @return bool True on success, false on failure.
    785771 */
     
    787773    global $wpdb;
    788774
    789     // Bail if no user ID
     775    // Bail if no user ID.
    790776    if ( empty( $user_id ) ) {
    791777        return;
    792778    }
    793779
    794     // Bail if user ID is super admin
     780    // Bail if user ID is super admin.
    795781    if ( is_super_admin( $user_id ) ) {
    796782        return;
    797783    }
    798784
    799     // Get the functions file
     785    // Get the functions file.
    800786    if ( is_multisite() ) {
    801787        require_once( ABSPATH . 'wp-admin/includes/ms.php' );
     
    804790    $is_spam = ( 'spam' == $status );
    805791
    806     // Only you can prevent infinite loops
     792    // Only you can prevent infinite loops.
    807793    remove_action( 'make_spam_user', 'bp_core_mark_user_spam_admin' );
    808794    remove_action( 'make_ham_user',  'bp_core_mark_user_ham_admin'  );
    809795
    810     // force the cleanup of WordPress content and status for multisite configs
     796    // Force the cleanup of WordPress content and status for multisite configs.
    811797    if ( $do_wp_cleanup ) {
    812798
    813         // Get the blogs for the user
     799        // Get the blogs for the user.
    814800        $blogs = get_blogs_of_user( $user_id, true );
    815801
    816802        foreach ( (array) array_values( $blogs ) as $details ) {
    817803
    818             // Do not mark the main or current root blog as spam
     804            // Do not mark the main or current root blog as spam.
    819805            if ( 1 == $details->userblog_id || bp_get_root_blog_id() == $details->userblog_id ) {
    820806                continue;
    821807            }
    822808
    823             // Update the blog status
     809            // Update the blog status.
    824810            update_blog_status( $details->userblog_id, 'spam', $is_spam );
    825811        }
    826812
    827         // Finally, mark this user as a spammer
     813        // Finally, mark this user as a spammer.
    828814        if ( is_multisite() ) {
    829815            update_user_status( $user_id, 'spam', $is_spam );
     
    831817    }
    832818
    833     // Update the user status
     819    // Update the user status.
    834820    $wpdb->update( $wpdb->users, array( 'user_status' => $is_spam ), array( 'ID' => $user_id ) );
    835821
    836     // Clean user cache
     822    // Clean user cache.
    837823    clean_user_cache( $user_id );
    838824
    839825    if ( ! is_multisite() ) {
    840         // Call multisite actions in single site mode for good measure
     826        // Call multisite actions in single site mode for good measure.
    841827        if ( true === $is_spam ) {
    842828
     
    862848    }
    863849
    864     // Hide this user's activity
     850    // Hide this user's activity.
    865851    if ( ( true === $is_spam ) && bp_is_active( 'activity' ) ) {
    866852        bp_activity_hide_user_activity( $user_id );
    867853    }
    868854
    869     // We need a special hook for is_spam so that components can delete data at spam time
     855    // We need a special hook for is_spam so that components can delete data at spam time.
    870856    if ( true === $is_spam ) {
    871857
     
    900886    do_action( 'bp_core_process_spammer_status', $user_id, $is_spam );
    901887
    902     // Put things back how we found them
     888    // Put things back how we found them.
    903889    add_action( 'make_spam_user', 'bp_core_mark_user_spam_admin' );
    904890    add_action( 'make_ham_user',  'bp_core_mark_user_ham_admin'  );
     
    934920 *
    935921 * @param int $user_id The ID for the user.
    936  *
    937922 * @return bool True if spammer, otherwise false.
    938923 */
    939924function bp_is_user_spammer( $user_id = 0 ) {
    940925
    941     // No user to check
     926    // No user to check.
    942927    if ( empty( $user_id ) ) {
    943928        return false;
     
    946931    $bp = buddypress();
    947932
    948     // Assume user is not spam
     933    // Assume user is not spam.
    949934    $is_spammer = false;
    950935
    951     // Setup our user
     936    // Setup our user.
    952937    $user = false;
    953938
    954     // Get locally-cached data if available
     939    // Get locally-cached data if available.
    955940    switch ( $user_id ) {
    956941        case bp_loggedin_user_id() :
     
    963948    }
    964949
    965     // Manually get userdata if still empty
     950    // Manually get userdata if still empty.
    966951    if ( empty( $user ) ) {
    967952        $user = get_userdata( $user_id );
    968953    }
    969954
    970     // No user found
     955    // No user found.
    971956    if ( empty( $user ) ) {
    972957        $is_spammer = false;
    973958
    974     // User found
     959    // User found.
    975960    } else {
    976961
    977         // Check if spam
     962        // Check if spam.
    978963        if ( !empty( $user->spam ) ) {
    979964            $is_spammer = true;
     
    999984 *
    1000985 * @param int $user_id The ID for the user.
    1001  *
    1002986 * @return bool True if deleted, otherwise false.
    1003987 */
    1004988function bp_is_user_deleted( $user_id = 0 ) {
    1005989
    1006     // No user to check
     990    // No user to check.
    1007991    if ( empty( $user_id ) ) {
    1008992        return false;
     
    1011995    $bp = buddypress();
    1012996
    1013     // Assume user is not deleted
     997    // Assume user is not deleted.
    1014998    $is_deleted = false;
    1015999
    1016     // Setup our user
     1000    // Setup our user.
    10171001    $user = false;
    10181002
    1019     // Get locally-cached data if available
     1003    // Get locally-cached data if available.
    10201004    switch ( $user_id ) {
    10211005        case bp_loggedin_user_id() :
     
    10281012    }
    10291013
    1030     // Manually get userdata if still empty
     1014    // Manually get userdata if still empty.
    10311015    if ( empty( $user ) ) {
    10321016        $user = get_userdata( $user_id );
    10331017    }
    10341018
    1035     // No user found
     1019    // No user found.
    10361020    if ( empty( $user ) ) {
    10371021        $is_deleted = true;
    10381022
    1039     // User found
     1023    // User found.
    10401024    } else {
    10411025
    1042         // Check if deleted
     1026        // Check if deleted.
    10431027        if ( !empty( $user->deleted ) ) {
    10441028            $is_deleted = true;
     
    10711055 *
    10721056 * @param int $user_id The user ID to check.
    1073  *
    10741057 * @return bool True if active, otherwise false.
    10751058 */
    10761059function bp_is_user_active( $user_id = 0 ) {
    10771060
    1078     // Default to current user
     1061    // Default to current user.
    10791062    if ( empty( $user_id ) && is_user_logged_in() ) {
    10801063        $user_id = bp_loggedin_user_id();
    10811064    }
    10821065
    1083     // No user to check
     1066    // No user to check.
    10841067    if ( empty( $user_id ) ) {
    10851068        return false;
    10861069    }
    10871070
    1088     // Check spam
     1071    // Check spam.
    10891072    if ( bp_is_user_spammer( $user_id ) ) {
    10901073        return false;
    10911074    }
    10921075
    1093     // Check deleted
     1076    // Check deleted.
    10941077    if ( bp_is_user_deleted( $user_id ) ) {
    10951078        return false;
    10961079    }
    10971080
    1098     // Assume true if not spam or deleted
     1081    // Assume true if not spam or deleted.
    10991082    return true;
    11001083}
     
    11131096 *
    11141097 * @param int $user_id The user ID to check.
    1115  *
    11161098 * @return bool True if inactive, otherwise false.
    11171099 */
    11181100function bp_is_user_inactive( $user_id = 0 ) {
    11191101
    1120     // Default to current user
     1102    // Default to current user.
    11211103    if ( empty( $user_id ) && is_user_logged_in() ) {
    11221104        $user_id = bp_loggedin_user_id();
    11231105    }
    11241106
    1125     // No user to check
     1107    // No user to check.
    11261108    if ( empty( $user_id ) ) {
    11271109        return false;
    11281110    }
    11291111
    1130     // Return the inverse of active
     1112    // Return the inverse of active.
    11311113    return !bp_is_user_active( $user_id );
    11321114}
     
    11391121 * @param int    $user_id ID of the user being updated.
    11401122 * @param string $time    Time of last activity, in 'Y-m-d H:i:s' format.
    1141  *
    11421123 * @return bool True on success, false on failure.
    11431124 */
    11441125function bp_update_user_last_activity( $user_id = 0, $time = '' ) {
    11451126
    1146     // Fall back on current user
     1127    // Fall back on current user.
    11471128    if ( empty( $user_id ) ) {
    11481129        $user_id = bp_loggedin_user_id();
    11491130    }
    11501131
    1151     // Bail if the user id is 0, as there's nothing to update
     1132    // Bail if the user id is 0, as there's nothing to update.
    11521133    if ( empty( $user_id ) ) {
    11531134        return false;
    11541135    }
    11551136
    1156     // Fall back on current time
     1137    // Fall back on current time.
    11571138    if ( empty( $time ) ) {
    11581139        $time = bp_core_current_time();
     
    11831164 * @access private For internal use only.
    11841165 *
    1185  * @param null   $retval
     1166 * @param null   $retval Null retval value.
    11861167 * @param int    $object_id ID of the user.
    11871168 * @param string $meta_key  Meta key being fetched.
    1188  *
    11891169 * @return mixed
    11901170 */
     
    11931173
    11941174    if ( 'last_activity' === $meta_key ) {
    1195         // Don't send the warning more than once per pageload
     1175        // Don't send the warning more than once per pageload.
    11961176        if ( false === $warned ) {
    11971177            _doing_it_wrong( 'get_user_meta( $user_id, \'last_activity\' )', __( 'User last_activity data is no longer stored in usermeta. Use bp_get_user_last_activity() instead.', 'buddypress' ), '2.0.0' );
     
    12351215 *
    12361216 * @param int $user_id The ID of the user.
    1237  *
    12381217 * @return string Time of last activity, in 'Y-m-d H:i:s' format, or an empty
    12391218 *                string if none is found.
     
    12741253    // Wipe out existing last_activity data in the activity table -
    12751254    // this helps to prevent duplicates when pulling from the usermeta
    1276     // table
     1255    // table.
    12771256    $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->members->table_name_last_activity} WHERE component = %s AND type = 'last_activity'", $bp->members->id ) );
    12781257
     
    12951274 *
    12961275 * @param int $user_id ID of the user being queried.
    1297  *
    12981276 * @return array Post IDs.
    12991277 */
     
    13191297function bp_core_delete_account( $user_id = 0 ) {
    13201298
    1321     // Use logged in user ID if none is passed
     1299    // Use logged in user ID if none is passed.
    13221300    if ( empty( $user_id ) ) {
    13231301        $user_id = bp_loggedin_user_id();
    13241302    }
    13251303
    1326     // Site admins cannot be deleted
     1304    // Site admins cannot be deleted.
    13271305    if ( is_super_admin( $user_id ) ) {
    13281306        return false;
    13291307    }
    13301308
    1331     // Extra checks if user is not deleting themselves
     1309    // Extra checks if user is not deleting themselves.
    13321310    if ( bp_loggedin_user_id() !== absint( $user_id ) ) {
    13331311
    1334         // Bail if current user cannot delete any users
     1312        // Bail if current user cannot delete any users.
    13351313        if ( ! bp_current_user_can( 'delete_users' ) ) {
    13361314            return false;
    13371315        }
    13381316
    1339         // Bail if current user cannot delete this user
     1317        // Bail if current user cannot delete this user.
    13401318        if ( ! current_user_can_for_blog( bp_get_root_blog_id(), 'delete_user', $user_id ) ) {
    13411319            return false;
     
    13521330    do_action( 'bp_core_pre_delete_account', $user_id );
    13531331
    1354     // Specifically handle multi-site environment
     1332    // Specifically handle multi-site environment.
    13551333    if ( is_multisite() ) {
    13561334        require_once( ABSPATH . '/wp-admin/includes/ms.php'   );
     
    13591337        $retval = wpmu_delete_user( $user_id );
    13601338
    1361     // Single site user deletion
     1339    // Single site user deletion.
    13621340    } else {
    13631341        require_once( ABSPATH . '/wp-admin/includes/user.php' );
     
    13831361 *
    13841362 * @param int $user_id ID of the user who is about to be deleted.
    1385  *
    13861363 * @return bool True on success, false on failure.
    13871364 */
     
    14011378 *
    14021379 * @param string $str String to be upper-cased.
    1403  *
    14041380 * @return string
    14051381 */
     
    14231399 * @param WP_User|WP_Error $user Either the WP_User object or the WP_Error
    14241400 *                               object, as passed to the 'authenticate' filter.
    1425  *
    14261401 * @return WP_User|WP_Error If the user is not a spammer, return the WP_User
    14271402 *                          object. Otherwise a new WP_Error object.
     
    14291404function bp_core_boot_spammer( $user ) {
    14301405
    1431     // check to see if the $user has already failed logging in, if so return $user as-is
     1406    // Check to see if the $user has already failed logging in, if so return $user as-is.
    14321407    if ( is_wp_error( $user ) || empty( $user ) ) {
    14331408        return $user;
    14341409    }
    14351410
    1436     // the user exists; now do a check to see if the user is a spammer
     1411    // The user exists; now do a check to see if the user is a spammer
    14371412    // if the user is a spammer, stop them in their tracks!
    14381413    if ( is_a( $user, 'WP_User' ) && ( ( is_multisite() && (int) $user->spam ) || 1 == $user->user_status ) ) {
     
    14401415    }
    14411416
    1442     // user is good to go!
     1417    // User is good to go!
    14431418    return $user;
    14441419}
     
    14521427function bp_core_remove_data( $user_id ) {
    14531428
    1454     // Remove last_activity data
     1429    // Remove last_activity data.
    14551430    BP_Core_User::delete_last_activity( $user_id );
    14561431
    1457     // Flush the cache to remove the user from all cached objects
     1432    // Flush the cache to remove the user from all cached objects.
    14581433    wp_cache_flush();
    14591434}
     
    14991474 *                               Multisite settings.
    15001475 * @param array|string $oldvalue The old value of the option.
    1501  *
    15021476 * @return array Merged and unique array of illegal names.
    15031477 */
    15041478function bp_core_get_illegal_names( $value = '', $oldvalue = '' ) {
    15051479
    1506     // Make sure $value is array
     1480    // Make sure $value is array.
    15071481    if ( empty( $value ) ) {
    15081482        $db_illegal_names = array();
     
    15311505    );
    15321506
    1533     // Core constants
     1507    // Core constants.
    15341508    $slug_constants = array(
    15351509        'BP_GROUPS_SLUG',
     
    15611535    $filtered_illegal_names = apply_filters( 'bp_core_illegal_usernames', array_merge( array( 'www', 'web', 'root', 'admin', 'main', 'invite', 'administrator' ), $bp_component_slugs ) );
    15621536
    1563     // Merge the arrays together
     1537    // Merge the arrays together.
    15641538    $merged_names           = array_merge( (array) $filtered_illegal_names, (array) $db_illegal_names );
    15651539
    1566     // Remove duplicates
     1540    // Remove duplicates.
    15671541    $illegal_names          = array_unique( (array) $merged_names );
    15681542
     
    15901564 *
    15911565 * @param string $user_email The email being checked.
    1592  *
    15931566 * @return bool|array True if the address passes all checks; otherwise an array
    15941567 *                    of error codes.
     
    16051578
    16061579    // Is the email on the Banned Email Domains list?
    1607     // Note: This check only works on Multisite
     1580    // Note: This check only works on Multisite.
    16081581    if ( function_exists( 'is_email_address_unsafe' ) && is_email_address_unsafe( $user_email ) ) {
    16091582        $errors['domain_banned'] = 1;
     
    16111584
    16121585    // Is the email on the Limited Email Domains list?
    1613     // Note: This check only works on Multisite
     1586    // Note: This check only works on Multisite.
    16141587    $limited_email_domains = get_site_option( 'limited_email_domains' );
    16151588    if ( is_array( $limited_email_domains ) && empty( $limited_email_domains ) == false ) {
     
    16681641 * @param string $user_name  Username to validate.
    16691642 * @param string $user_email Email address to validate.
    1670  *
    16711643 * @return array Results of user validation including errors, if any.
    16721644 */
    16731645function bp_core_validate_user_signup( $user_name, $user_email ) {
    16741646
    1675     // Make sure illegal names include BuddyPress slugs and values
     1647    // Make sure illegal names include BuddyPress slugs and values.
    16761648    bp_core_flush_illegal_names();
    16771649
     
    16831655    // When not running Multisite, we perform our own validation. What
    16841656    // follows reproduces much of the logic of wpmu_validate_user_signup(),
    1685     // minus the multisite-specific restrictions on user_login
     1657    // minus the multisite-specific restrictions on user_login.
    16861658    } else {
    16871659        $errors = new WP_Error();
     
    16961668        $user_name = apply_filters( 'pre_user_login', $user_name );
    16971669
    1698         // User name can't be empty
     1670        // User name can't be empty.
    16991671        if ( empty( $user_name ) ) {
    17001672            $errors->add( 'user_name', __( 'Please enter a username', 'buddypress' ) );
    17011673        }
    17021674
    1703         // user name can't be on the blacklist
     1675        // User name can't be on the blacklist.
    17041676        $illegal_names = get_site_option( 'illegal_names' );
    17051677        if ( in_array( $user_name, (array) $illegal_names ) ) {
     
    17071679        }
    17081680
    1709         // User name must pass WP's validity check
     1681        // User name must pass WP's validity check.
    17101682        if ( ! validate_username( $user_name ) ) {
    17111683            $errors->add( 'user_name', __( 'Usernames can contain only letters, numbers, ., -, and @', 'buddypress' ) );
    17121684        }
    17131685
    1714         // Minimum of 4 characters
     1686        // Minimum of 4 characters.
    17151687        if ( strlen( $user_name ) < 4 ) {
    17161688            $errors->add( 'user_name',  __( 'Username must be at least 4 characters', 'buddypress' ) );
     
    17291701        }
    17301702
    1731         // Check into signups
     1703        // Check into signups.
    17321704        $signups = BP_Signup::get( array(
    17331705            'user_login' => $user_name,
     
    17421714
    17431715        // Validate the email address and process the validation results into
    1744         // error messages
     1716        // error messages.
    17451717        $validate_email = bp_core_validate_email_address( $user_email );
    17461718        bp_core_add_validation_error_messages( $errors, $validate_email );
    17471719
    1748         // Assemble the return array
     1720        // Assemble the return array.
    17491721        $result = array(
    17501722            'user_name'  => $user_name,
     
    17531725        );
    17541726
    1755         // Apply WPMU legacy filter
     1727        // Apply WPMU legacy filter.
    17561728        $result = apply_filters( 'wpmu_validate_user_signup', $result );
    17571729    }
     
    17741746 * @param string $blog_url   Blog URL requested during registration.
    17751747 * @param string $blog_title Blog title requested during registration.
    1776  *
    17771748 * @return array
    17781749 */
     
    18021773 * @param array  $usermeta      Miscellaneous metadata about the user (blog-specific
    18031774 *                              signup data, xprofile data, etc).
    1804  *
    18051775 * @return bool|WP_Error True on success, WP_Error on failure.
    18061776 */
     
    18081778    $bp = buddypress();
    18091779
    1810     // We need to cast $user_id to pass to the filters
     1780    // We need to cast $user_id to pass to the filters.
    18111781    $user_id = false;
    18121782
    1813     // Multisite installs have their own install procedure
     1783    // Multisite installs have their own install procedure.
    18141784    if ( is_multisite() ) {
    18151785        wpmu_signup_user( $user_login, $user_email, $usermeta );
    18161786
    18171787    } else {
    1818         // Format data
     1788        // Format data.
    18191789        $user_login     = preg_replace( '/\s+/', '', sanitize_user( $user_login, true ) );
    18201790        $user_email     = sanitize_email( $user_email );
     
    18991869 * @param string $user_email  Email address of requesting user.
    19001870 * @param string $usermeta    Miscellaneous metadata for the user.
    1901  *
    19021871 * @return bool
    19031872 */
     
    19081877
    19091878    /**
    1910      * Filters the result of wpmu_signup_blog()
     1879     * Filters the result of wpmu_signup_blog().
    19111880     *
    19121881     * This filter provides no value and is retained for
     
    19241893 *
    19251894 * @param string $key Activation key.
    1926  *
    19271895 * @return int|bool User ID on success, false on failure.
    19281896 */
     
    19321900    $user = false;
    19331901
    1934     // Multisite installs have their own activation routine
     1902    // Multisite installs have their own activation routine.
    19351903    if ( is_multisite() ) {
    19361904        $user = wpmu_activate_signup( $key );
    19371905
    1938         // If there were errors, add a message and redirect
     1906        // If there were errors, add a message and redirect.
    19391907        if ( ! empty( $user->errors ) ) {
    19401908            return $user;
     
    19621930        }
    19631931
    1964         // password is hashed again in wp_insert_user
     1932        // Password is hashed again in wp_insert_user.
    19651933        $password = wp_generate_password( 12, false );
    19661934
    19671935        $user_id = username_exists( $signup->user_login );
    19681936
    1969         // Create the user
     1937        // Create the user.
    19701938        if ( ! $user_id ) {
    19711939            $user_id = wp_create_user( $signup->user_login, $password, $signup->user_email );
     
    19741942        // created locally for backward compatibility. Process it.
    19751943        } elseif ( $key == wp_hash( $user_id ) ) {
    1976             // Change the user's status so they become active
     1944            // Change the user's status so they become active.
    19771945            if ( ! $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->users} SET user_status = 0 WHERE ID = %d", $user_id ) ) ) {
    19781946                return new WP_Error( 'invalid_key', __( 'Invalid activation key.', 'buddypress' ) );
     
    19941962        }
    19951963
    1996         // Fetch the signup so we have the data later on
     1964        // Fetch the signup so we have the data later on.
    19971965        $signups = BP_Signup::get( array(
    19981966            'activation_key' => $key,
     
    20011969        $signup = isset( $signups['signups'] ) && ! empty( $signups['signups'][0] ) ? $signups['signups'][0] : false;
    20021970
    2003         // Activate the signup
     1971        // Activate the signup.
    20041972        BP_Signup::validate( $key );
    20051973
     
    20081976        }
    20091977
    2010         // Set up data to pass to the legacy filter
     1978        // Set up data to pass to the legacy filter.
    20111979        $user = array(
    20121980            'user_id'  => $user_id,
     
    20151983        );
    20161984
    2017         // Notify the site admin of a new user registration
     1985        // Notify the site admin of a new user registration.
    20181986        wp_new_user_notification( $user_id );
    20191987
     
    20342002    }
    20352003
    2036     // Set any profile data
     2004    // Set any profile data.
    20372005    if ( bp_is_active( 'xprofile' ) ) {
    20382006        if ( ! empty( $user['meta']['profile_field_ids'] ) ) {
     
    20462014                }
    20472015
    2048                 // Save the visibility level
     2016                // Save the visibility level.
    20492017                $visibility_level = ! empty( $user['meta']['field_' . $field_id . '_visibility'] ) ? $user['meta']['field_' . $field_id . '_visibility'] : 'public';
    20502018                xprofile_set_field_visibility_level( $field_id, $user_id, $visibility_level );
     
    20532021    }
    20542022
    2055     // Update the display_name
     2023    // Update the display_name.
    20562024    wp_update_user( array(
    20572025        'ID'           => $user_id,
     
    20592027    ) );
    20602028
    2061     // Set the password on multisite installs
     2029    // Set the password on multisite installs.
    20622030    if ( ! empty( $user['meta']['password'] ) ) {
    20632031        $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->users} SET user_pass = %s WHERE ID = %d", $user['meta']['password'], $user_id ) );
     
    21022070
    21032071        // Fetch activation keys separately, to avoid the all_with_meta
    2104         // overhead
     2072        // overhead.
    21052073        $status_2_ids_sql = implode( ',', $status_2_ids );
    21062074        $ak_data = $wpdb->get_results( "SELECT user_id, meta_value FROM {$wpdb->usermeta} WHERE meta_key = 'activation_key' AND user_id IN ({$status_2_ids_sql})" );
    21072075
    2108         // Rekey
     2076        // Rekey.
    21092077        $activation_keys = array();
    21102078        foreach ( $ak_data as $ak_datum ) {
     
    21142082        unset( $status_2_ids_sql, $status_2_ids, $ak_data );
    21152083
    2116         // Merge
     2084        // Merge.
    21172085        foreach ( $signups as &$signup ) {
    21182086            if ( isset( $activation_keys[ $signup->ID ] ) ) {
     
    21212089        }
    21222090
    2123         // Reset the signup var as we're using it to process the migration
     2091        // Reset the signup var as we're using it to process the migration.
    21242092        unset( $signup );
    21252093
     
    21312099        $meta = array();
    21322100
    2133         // Rebuild the activation key, if missing
     2101        // Rebuild the activation key, if missing.
    21342102        if ( empty( $signup->activation_key ) ) {
    21352103            $signup->activation_key = wp_hash( $signup->ID );
     
    21532121        ) );
    21542122
    2155         // Deleting these options will remove signups from users count
     2123        // Deleting these options will remove signups from users count.
    21562124        delete_user_option( $signup->ID, 'capabilities' );
    21572125        delete_user_option( $signup->ID, 'user_level'   );
     
    21662134 *
    21672135 * @param int $user_id ID of the user.
    2168  *
    21692136 * @return bool
    21702137 */
     
    21762143    }
    21772144
    2178     // Add the user's fullname to Xprofile
     2145    // Add the user's fullname to Xprofile.
    21792146    if ( bp_is_active( 'xprofile' ) ) {
    21802147        $firstname = bp_get_user_meta( $user_id, 'first_name', true );
     
    22962263 * @param string           $username The inputted, attempted username.
    22972264 * @param string           $password The inputted, attempted password.
    2298  *
    22992265 * @return WP_User|WP_Error
    23002266 */
    23012267function bp_core_signup_disable_inactive( $user = null, $username = '', $password ='' ) {
    2302     // login form not used
     2268    // Login form not used.
    23032269    if ( empty( $username ) && empty( $password ) ) {
    23042270        return $user;
     
    23122278
    23132279    // If no WP_User is found corresponding to the username, this
    2314     // is a potential signup
     2280    // is a potential signup.
    23152281    } elseif ( is_wp_error( $user ) && 'invalid_username' == $user->get_error_code() ) {
    23162282        $user_login = $username;
    23172283
    2318     // This is an activated user, so bail
     2284    // This is an activated user, so bail.
    23192285    } else {
    23202286        return $user;
    23212287    }
    23222288
    2323     // Look for the unactivated signup corresponding to the login name
     2289    // Look for the unactivated signup corresponding to the login name.
    23242290    $signup = BP_Signup::get( array( 'user_login' => sanitize_user( $user_login ) ) );
    23252291
     
    23302296
    23312297    // Unactivated user account found!
    2332     // Set up the feedback message
     2298    // Set up the feedback message.
    23332299    $signup_id = $signup['signups'][0]->signup_id;
    23342300
     
    23632329    }
    23642330
    2365     // verify nonce
     2331    // Verify nonce.
    23662332    if ( ! wp_verify_nonce( $_GET['_wpnonce'], 'bp-resend-activation' ) ) {
    23672333        die( 'Security check' );
     
    23702336    $signup_id = (int) $_GET['id'];
    23712337
    2372     // resend the activation email
    2373     // also updates the 'last sent' and '# of emails sent' values
     2338    // Resend the activation email.
     2339    // also updates the 'last sent' and '# of emails sent' values.
    23742340    $resend = BP_Signup::resend( array( $signup_id ) );
    23752341
    2376     // add feedback message
     2342    // Add feedback message.
    23772343    if ( ! empty( $resend['errors'] ) ) {
    23782344        $error = __( '<strong>ERROR</strong>: Your account has already been activated.', 'buddypress' );
     
    23882354function bp_core_wpsignup_redirect() {
    23892355
    2390     // Bail in admin or if custom signup page is broken
     2356    // Bail in admin or if custom signup page is broken.
    23912357    if ( is_admin() || ! bp_has_custom_signup_page() ) {
    23922358        return;
     
    23952361    $action = !empty( $_GET['action'] ) ? $_GET['action'] : '';
    23962362
    2397     // Not at the WP core signup page and action is not register
     2363    // Not at the WP core signup page and action is not register.
    23982364    if ( ! empty( $_SERVER['SCRIPT_NAME'] ) && false === strpos( $_SERVER['SCRIPT_NAME'], 'wp-signup.php' ) && ( 'register' != $action ) ) {
    23992365        return;
     
    24262392 */
    24272393function bp_stop_live_spammer() {
    2428     // if we're on the login page, stop now to prevent redirect loop
     2394    // If we're on the login page, stop now to prevent redirect loop.
    24292395    $is_login = false;
    24302396    if ( isset( $GLOBALS['pagenow'] ) && ( false !== strpos( $GLOBALS['pagenow'], 'wp-login.php' ) ) ) {
     
    24382404    }
    24392405
    2440     // user isn't logged in, so stop!
     2406    // User isn't logged in, so stop!
    24412407    if ( ! is_user_logged_in() ) {
    24422408        return;
    24432409    }
    24442410
    2445     // if spammer, redirect to wp-login.php and reauthorize
     2411    // If spammer, redirect to wp-login.php and reauthorize.
    24462412    if ( bp_is_user_spammer( bp_loggedin_user_id() ) ) {
    2447         // setup login args
     2413        // Setup login args.
    24482414        $args = array(
    2449             // custom action used to throw an error message
     2415            // Custom action used to throw an error message.
    24502416            'action' => 'bp-spam',
    24512417
    2452             // reauthorize user to login
     2418            // Reauthorize user to login.
    24532419            'reauth' => 1
    24542420        );
     
    24632429        $login_url = apply_filters( 'bp_live_spammer_redirect', add_query_arg( $args, wp_login_url() ) );
    24642430
    2465         // redirect user to login page
     2431        // Redirect user to login page.
    24662432        wp_redirect( $login_url );
    24672433        die();
     
    24802446    $error = __( '<strong>ERROR</strong>: Your account has been marked as a spammer.', 'buddypress' );
    24812447
    2482     // shake shake shake!
     2448    // Shake shake shake!
    24832449    add_action( 'login_head', 'wp_shake_js', 12 );
    24842450}
     
    25872553 *
    25882554 * @param string $member_type The name of the member type.
    2589  *
    25902555 * @return object A member type object.
    25912556 */
     
    26142579 *                               element from the array needs to match; 'and' means all elements
    26152580 *                               must match. Accepts 'or' or 'and'. Default 'and'.
    2616  *
    26172581 * @return array A list of member type names or objects.
    26182582 */
     
    26522616 * @param bool   $append      Optional. True to append this to existing types for user,
    26532617 *                            false to replace. Default: false.
    2654  * @return See {@see bp_set_object_terms()}.
     2618 * @return array $retval See {@see bp_set_object_terms()}.
    26552619 */
    26562620function bp_set_member_type( $user_id, $member_type, $append = false ) {
     
    26882652 * @param int    $user_id     ID of the user.
    26892653 * @param string $member_type Member Type.
    2690  *
    26912654 * @return bool|WP_Error
    26922655 */
     
    27222685 * @since 2.2.0
    27232686 *
    2724  * @param int               $user_id ID of the user.
    2725  * @param bool              $single  Optional. Whether to return a single type string. If multiple types are found
    2726  *                                   for the user, the oldest one will be returned. Default: true.
    2727  *
     2687 * @param int  $user_id ID of the user.
     2688 * @param bool $single  Optional. Whether to return a single type string. If multiple types are found
     2689 *                      for the user, the oldest one will be returned. Default: true.
    27282690 * @return string|array|bool On success, returns a single member type (if $single is true) or an array of member
    27292691 *                           types (if $single is false). Returns false on failure.
     
    27692731 * @param int    $user_id     $user_id ID of the user.
    27702732 * @param string $member_type Member Type.
    2771  *
    27722733 * @return bool Whether the user has the given member type.
    27732734 */
     
    27942755 *
    27952756 * @param int $user_id ID of the user.
    2796  *
    2797  * @return See {@see bp_set_member_type()}.
     2757 * @return array $value See {@see bp_set_member_type()}.
    27982758 */
    27992759function bp_remove_member_type_on_user_delete( $user_id ) {
Note: See TracChangeset for help on using the changeset viewer.