Changeset 10322 for trunk/src/bp-members/bp-members-functions.php
- Timestamp:
- 11/02/2015 01:58:52 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-members/bp-members-functions.php
r10276 r10322 39 39 $bp = buddypress(); 40 40 41 // No custom members slug 41 // No custom members slug. 42 42 if ( !defined( 'BP_MEMBERS_SLUG' ) ) { 43 43 if ( !empty( $bp->pages->members ) ) { … … 48 48 } 49 49 50 // No custom registration slug 50 // No custom registration slug. 51 51 if ( !defined( 'BP_REGISTER_SLUG' ) ) { 52 52 if ( !empty( $bp->pages->register ) ) { … … 57 57 } 58 58 59 // No custom activation slug 59 // No custom activation slug. 60 60 if ( !defined( 'BP_ACTIVATION_SLUG' ) ) { 61 61 if ( !empty( $bp->pages->activate ) ) { … … 98 98 function bp_core_get_users( $args = '' ) { 99 99 100 // Parse the user query arguments 100 // Parse the user query arguments. 101 101 $r = bp_parse_args( $args, array( 102 'type' => 'active', // active, newest, alphabetical, random or popular103 '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. 108 108 'member_type' => '', 109 109 'member_type__in' => '', 110 110 '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. 116 116 ), 'core_get_users' ); 117 117 … … 131 131 ); 132 132 133 // Default behavior as of BuddyPress 1.7 133 // Default behavior as of BuddyPress 1.7.0. 134 134 } else { 135 135 … … 161 161 * @param string|bool $user_nicename Optional. user_nicename of the user. 162 162 * @param string|bool $user_login Optional. user_login of the user. 163 *164 163 * @return string 165 164 */ … … 200 199 * 201 200 * @param int $user_id The ID of the user. 202 *203 201 * @return array 204 202 */ … … 231 229 * 232 230 * @param string $user_login user_login of the user being queried. 233 *234 231 * @return int 235 232 */ … … 244 241 * 245 242 * @param string $username user_login to check. 246 *247 243 * @return int|null The ID of the matched user on success, null on failure. 248 244 */ … … 271 267 * 272 268 * @param string $user_nicename user_nicename to check. 273 *274 269 * @return int|null The ID of the matched user on success, null on failure. 275 270 */ … … 301 296 * @param string|bool $user_nicename Optional. user_nicename of user being checked. 302 297 * @param string|bool $user_login Optional. user_login of user being checked. 303 *304 298 * @return string|bool The username of the matched user, or false. 305 299 */ … … 307 301 $bp = buddypress(); 308 302 309 // Check cache for user nicename 303 // Check cache for user nicename. 310 304 $username = wp_cache_get( 'bp_user_username_' . $user_id, 'bp' ); 311 305 if ( false === $username ) { 312 306 313 // Cache not found so prepare to update it 307 // Cache not found so prepare to update it. 314 308 $update_cache = true; 315 309 316 // Nicename and login were not passed 310 // Nicename and login were not passed. 317 311 if ( empty( $user_nicename ) && empty( $user_login ) ) { 318 312 319 // User ID matches logged in user 313 // User ID matches logged in user. 320 314 if ( bp_loggedin_user_id() == $user_id ) { 321 315 $userdata = &$bp->loggedin_user->userdata; 322 316 323 // User ID matches displayed in user 317 // User ID matches displayed in user. 324 318 } elseif ( bp_displayed_user_id() == $user_id ) { 325 319 $userdata = &$bp->displayed_user->userdata; 326 320 327 // No user ID match 321 // No user ID match. 328 322 } else { 329 323 $userdata = false; 330 324 } 331 325 332 // No match so go dig 326 // No match so go dig. 333 327 if ( empty( $userdata ) ) { 334 328 335 // User not found so return false 329 // User not found so return false. 336 330 if ( !$userdata = bp_core_get_core_userdata( $user_id ) ) { 337 331 return false; … … 339 333 } 340 334 341 // Update the $user_id for later 335 // Update the $user_id for later. 342 336 $user_id = $userdata->ID; 343 337 344 // Two possible options 338 // Two possible options. 345 339 $user_nicename = $userdata->user_nicename; 346 340 $user_login = $userdata->user_login; 347 341 } 348 342 349 // Pull an audible and maybe use the login over the nicename 343 // Pull an audible and maybe use the login over the nicename. 350 344 $username = bp_is_username_compatibility_mode() ? $user_login : $user_nicename; 351 345 352 // Username found in cache so don't update it again 346 // Username found in cache so don't update it again. 353 347 } else { 354 348 $update_cache = false; 355 349 } 356 350 357 // Add this to cache 351 // Add this to cache. 358 352 if ( ( true === $update_cache ) && !empty( $username ) ) { 359 353 wp_cache_set( 'bp_user_username_' . $user_id, $username, 'bp' ); 360 354 361 355 // @todo bust this cache if no $username found? 362 // } else {363 // 356 // } else { 357 // wp_cache_delete( 'bp_user_username_' . $user_id ); 364 358 } 365 359 … … 385 379 * 386 380 * @param int $user_id User ID to check. 387 *388 381 * @return string|bool The username of the matched user, or false. 389 382 */ … … 394 387 $update_cache = true; 395 388 396 // User ID matches logged in user 389 // User ID matches logged in user. 397 390 if ( bp_loggedin_user_id() == $user_id ) { 398 391 $userdata = &$bp->loggedin_user->userdata; 399 392 400 // User ID matches displayed in user 393 // User ID matches displayed in user. 401 394 } elseif ( bp_displayed_user_id() == $user_id ) { 402 395 $userdata = &$bp->displayed_user->userdata; 403 396 404 // No user ID match 397 // No user ID match. 405 398 } else { 406 399 $userdata = false; 407 400 } 408 401 409 // No match so go dig 402 // No match so go dig. 410 403 if ( empty( $userdata ) ) { 411 404 412 // User not found so return false 405 // User not found so return false. 413 406 if ( !$userdata = bp_core_get_core_userdata( $user_id ) ) { 414 407 return false; … … 416 409 } 417 410 418 // User nicename found 411 // User nicename found. 419 412 $user_nicename = $userdata->user_nicename; 420 413 421 // Nicename found in cache so don't update it again 414 // Nicename found in cache so don't update it again. 422 415 } else { 423 416 $update_cache = false; 424 417 } 425 418 426 // Add this to cache 419 // Add this to cache. 427 420 if ( true == $update_cache && !empty( $user_nicename ) ) { 428 421 wp_cache_set( 'bp_members_user_nicename_' . $user_id, $user_nicename, 'bp' ); … … 443 436 * 444 437 * @param int $uid User ID to check. 445 *446 438 * @return string The email for the matched user. Empty string if no user 447 439 * matched the $uid. … … 451 443 if ( !$email = wp_cache_get( 'bp_user_email_' . $uid, 'bp' ) ) { 452 444 453 // User exists 445 // User exists. 454 446 $ud = bp_core_get_core_userdata( $uid ); 455 447 if ( ! empty( $ud ) ) { 456 448 $email = $ud->user_email; 457 449 458 // User was deleted 450 // User was deleted. 459 451 } else { 460 452 $email = ''; … … 477 469 * Return a HTML formatted link for a user with the user's full name as the link text. 478 470 * 479 * eg: <a href="http://andy.example.com/">Andy Peatling</a>471 * Eg: <a href="http://andy.example.com/">Andy Peatling</a> 480 472 * 481 473 * Optional parameters will return just the name or just the URL. … … 486 478 * @param bool $just_link Disable full name and HTML and just return the URL 487 479 * text. Default false. 488 *489 480 * @return string|bool The link text based on passed parameters, or false on 490 481 * no match. … … 528 519 * @since 2.0.0 529 520 * 530 * @param array $user_ids 531 * 521 * @param array $user_ids Array of user IDs to get display names for. 532 522 * @return array 533 523 */ 534 524 function bp_core_get_user_displaynames( $user_ids ) { 535 525 536 // Sanitize 526 // Sanitize. 537 527 $user_ids = wp_parse_id_list( $user_ids ); 538 528 539 // Remove dupes and empties 529 // Remove dupes and empties. 540 530 $user_ids = array_unique( array_filter( $user_ids ) ); 541 531 … … 551 541 } 552 542 553 // Prime caches 543 // Prime caches. 554 544 if ( ! empty( $uncached_ids ) ) { 555 545 if ( bp_is_active( 'xprofile' ) ) { 556 546 $fullname_data = BP_XProfile_ProfileData::get_value_byid( 1, $uncached_ids ); 557 547 558 // Key by user_id 548 // Key by user_id. 559 549 $fullnames = array(); 560 550 foreach ( $fullname_data as $fd ) { … … 565 555 566 556 // If xprofiledata is not found for any users, we'll look 567 // them up separately 557 // them up separately. 568 558 $no_xprofile_ids = array_diff( $uncached_ids, array_keys( $fullnames ) ); 569 559 } else { … … 573 563 574 564 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. 576 566 $query = new WP_User_Query( array( 577 567 'include' => $no_xprofile_ids, … … 585 575 586 576 // If xprofile is active, set this value as the 587 // xprofile display name as well 577 // xprofile display name as well. 588 578 if ( bp_is_active( 'xprofile' ) ) { 589 579 xprofile_set_field_data( 1, $qr->ID, $fullnames[ $qr->ID ] ); … … 609 599 * 610 600 * @param int|string|bool $user_id_or_username User ID or username. 611 *612 601 * @return string|bool The display name for the user in question, or false if 613 602 * user not found. … … 655 644 * 656 645 * @param string $email The email address for the user. 657 *658 646 * @return string The link to the users home base. False on no match. 659 647 */ … … 677 665 * this should be user_login, otherwise it should 678 666 * be user_nicename. 679 *680 667 * @return string|bool The link to the user's domain, false on no match. 681 668 */ … … 739 726 $bp = buddypress(); 740 727 741 // Avoid a costly join by splitting the lookup 728 // Avoid a costly join by splitting the lookup. 742 729 if ( is_multisite() ) { 743 730 $sql = "SELECT ID FROM {$wpdb->users} WHERE (user_status != 0 OR deleted != 0 OR user_status != 0)"; … … 781 768 * performed this cleanup independently, as when hooked 782 769 * to 'make_spam_user'. 783 *784 770 * @return bool True on success, false on failure. 785 771 */ … … 787 773 global $wpdb; 788 774 789 // Bail if no user ID 775 // Bail if no user ID. 790 776 if ( empty( $user_id ) ) { 791 777 return; 792 778 } 793 779 794 // Bail if user ID is super admin 780 // Bail if user ID is super admin. 795 781 if ( is_super_admin( $user_id ) ) { 796 782 return; 797 783 } 798 784 799 // Get the functions file 785 // Get the functions file. 800 786 if ( is_multisite() ) { 801 787 require_once( ABSPATH . 'wp-admin/includes/ms.php' ); … … 804 790 $is_spam = ( 'spam' == $status ); 805 791 806 // Only you can prevent infinite loops 792 // Only you can prevent infinite loops. 807 793 remove_action( 'make_spam_user', 'bp_core_mark_user_spam_admin' ); 808 794 remove_action( 'make_ham_user', 'bp_core_mark_user_ham_admin' ); 809 795 810 // force the cleanup of WordPress content and status for multisite configs796 // Force the cleanup of WordPress content and status for multisite configs. 811 797 if ( $do_wp_cleanup ) { 812 798 813 // Get the blogs for the user 799 // Get the blogs for the user. 814 800 $blogs = get_blogs_of_user( $user_id, true ); 815 801 816 802 foreach ( (array) array_values( $blogs ) as $details ) { 817 803 818 // Do not mark the main or current root blog as spam 804 // Do not mark the main or current root blog as spam. 819 805 if ( 1 == $details->userblog_id || bp_get_root_blog_id() == $details->userblog_id ) { 820 806 continue; 821 807 } 822 808 823 // Update the blog status 809 // Update the blog status. 824 810 update_blog_status( $details->userblog_id, 'spam', $is_spam ); 825 811 } 826 812 827 // Finally, mark this user as a spammer 813 // Finally, mark this user as a spammer. 828 814 if ( is_multisite() ) { 829 815 update_user_status( $user_id, 'spam', $is_spam ); … … 831 817 } 832 818 833 // Update the user status 819 // Update the user status. 834 820 $wpdb->update( $wpdb->users, array( 'user_status' => $is_spam ), array( 'ID' => $user_id ) ); 835 821 836 // Clean user cache 822 // Clean user cache. 837 823 clean_user_cache( $user_id ); 838 824 839 825 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. 841 827 if ( true === $is_spam ) { 842 828 … … 862 848 } 863 849 864 // Hide this user's activity 850 // Hide this user's activity. 865 851 if ( ( true === $is_spam ) && bp_is_active( 'activity' ) ) { 866 852 bp_activity_hide_user_activity( $user_id ); 867 853 } 868 854 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. 870 856 if ( true === $is_spam ) { 871 857 … … 900 886 do_action( 'bp_core_process_spammer_status', $user_id, $is_spam ); 901 887 902 // Put things back how we found them 888 // Put things back how we found them. 903 889 add_action( 'make_spam_user', 'bp_core_mark_user_spam_admin' ); 904 890 add_action( 'make_ham_user', 'bp_core_mark_user_ham_admin' ); … … 934 920 * 935 921 * @param int $user_id The ID for the user. 936 *937 922 * @return bool True if spammer, otherwise false. 938 923 */ 939 924 function bp_is_user_spammer( $user_id = 0 ) { 940 925 941 // No user to check 926 // No user to check. 942 927 if ( empty( $user_id ) ) { 943 928 return false; … … 946 931 $bp = buddypress(); 947 932 948 // Assume user is not spam 933 // Assume user is not spam. 949 934 $is_spammer = false; 950 935 951 // Setup our user 936 // Setup our user. 952 937 $user = false; 953 938 954 // Get locally-cached data if available 939 // Get locally-cached data if available. 955 940 switch ( $user_id ) { 956 941 case bp_loggedin_user_id() : … … 963 948 } 964 949 965 // Manually get userdata if still empty 950 // Manually get userdata if still empty. 966 951 if ( empty( $user ) ) { 967 952 $user = get_userdata( $user_id ); 968 953 } 969 954 970 // No user found 955 // No user found. 971 956 if ( empty( $user ) ) { 972 957 $is_spammer = false; 973 958 974 // User found 959 // User found. 975 960 } else { 976 961 977 // Check if spam 962 // Check if spam. 978 963 if ( !empty( $user->spam ) ) { 979 964 $is_spammer = true; … … 999 984 * 1000 985 * @param int $user_id The ID for the user. 1001 *1002 986 * @return bool True if deleted, otherwise false. 1003 987 */ 1004 988 function bp_is_user_deleted( $user_id = 0 ) { 1005 989 1006 // No user to check 990 // No user to check. 1007 991 if ( empty( $user_id ) ) { 1008 992 return false; … … 1011 995 $bp = buddypress(); 1012 996 1013 // Assume user is not deleted 997 // Assume user is not deleted. 1014 998 $is_deleted = false; 1015 999 1016 // Setup our user 1000 // Setup our user. 1017 1001 $user = false; 1018 1002 1019 // Get locally-cached data if available 1003 // Get locally-cached data if available. 1020 1004 switch ( $user_id ) { 1021 1005 case bp_loggedin_user_id() : … … 1028 1012 } 1029 1013 1030 // Manually get userdata if still empty 1014 // Manually get userdata if still empty. 1031 1015 if ( empty( $user ) ) { 1032 1016 $user = get_userdata( $user_id ); 1033 1017 } 1034 1018 1035 // No user found 1019 // No user found. 1036 1020 if ( empty( $user ) ) { 1037 1021 $is_deleted = true; 1038 1022 1039 // User found 1023 // User found. 1040 1024 } else { 1041 1025 1042 // Check if deleted 1026 // Check if deleted. 1043 1027 if ( !empty( $user->deleted ) ) { 1044 1028 $is_deleted = true; … … 1071 1055 * 1072 1056 * @param int $user_id The user ID to check. 1073 *1074 1057 * @return bool True if active, otherwise false. 1075 1058 */ 1076 1059 function bp_is_user_active( $user_id = 0 ) { 1077 1060 1078 // Default to current user 1061 // Default to current user. 1079 1062 if ( empty( $user_id ) && is_user_logged_in() ) { 1080 1063 $user_id = bp_loggedin_user_id(); 1081 1064 } 1082 1065 1083 // No user to check 1066 // No user to check. 1084 1067 if ( empty( $user_id ) ) { 1085 1068 return false; 1086 1069 } 1087 1070 1088 // Check spam 1071 // Check spam. 1089 1072 if ( bp_is_user_spammer( $user_id ) ) { 1090 1073 return false; 1091 1074 } 1092 1075 1093 // Check deleted 1076 // Check deleted. 1094 1077 if ( bp_is_user_deleted( $user_id ) ) { 1095 1078 return false; 1096 1079 } 1097 1080 1098 // Assume true if not spam or deleted 1081 // Assume true if not spam or deleted. 1099 1082 return true; 1100 1083 } … … 1113 1096 * 1114 1097 * @param int $user_id The user ID to check. 1115 *1116 1098 * @return bool True if inactive, otherwise false. 1117 1099 */ 1118 1100 function bp_is_user_inactive( $user_id = 0 ) { 1119 1101 1120 // Default to current user 1102 // Default to current user. 1121 1103 if ( empty( $user_id ) && is_user_logged_in() ) { 1122 1104 $user_id = bp_loggedin_user_id(); 1123 1105 } 1124 1106 1125 // No user to check 1107 // No user to check. 1126 1108 if ( empty( $user_id ) ) { 1127 1109 return false; 1128 1110 } 1129 1111 1130 // Return the inverse of active 1112 // Return the inverse of active. 1131 1113 return !bp_is_user_active( $user_id ); 1132 1114 } … … 1139 1121 * @param int $user_id ID of the user being updated. 1140 1122 * @param string $time Time of last activity, in 'Y-m-d H:i:s' format. 1141 *1142 1123 * @return bool True on success, false on failure. 1143 1124 */ 1144 1125 function bp_update_user_last_activity( $user_id = 0, $time = '' ) { 1145 1126 1146 // Fall back on current user 1127 // Fall back on current user. 1147 1128 if ( empty( $user_id ) ) { 1148 1129 $user_id = bp_loggedin_user_id(); 1149 1130 } 1150 1131 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. 1152 1133 if ( empty( $user_id ) ) { 1153 1134 return false; 1154 1135 } 1155 1136 1156 // Fall back on current time 1137 // Fall back on current time. 1157 1138 if ( empty( $time ) ) { 1158 1139 $time = bp_core_current_time(); … … 1183 1164 * @access private For internal use only. 1184 1165 * 1185 * @param null $retval 1166 * @param null $retval Null retval value. 1186 1167 * @param int $object_id ID of the user. 1187 1168 * @param string $meta_key Meta key being fetched. 1188 *1189 1169 * @return mixed 1190 1170 */ … … 1193 1173 1194 1174 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. 1196 1176 if ( false === $warned ) { 1197 1177 _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' ); … … 1235 1215 * 1236 1216 * @param int $user_id The ID of the user. 1237 *1238 1217 * @return string Time of last activity, in 'Y-m-d H:i:s' format, or an empty 1239 1218 * string if none is found. … … 1274 1253 // Wipe out existing last_activity data in the activity table - 1275 1254 // this helps to prevent duplicates when pulling from the usermeta 1276 // table 1255 // table. 1277 1256 $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->members->table_name_last_activity} WHERE component = %s AND type = 'last_activity'", $bp->members->id ) ); 1278 1257 … … 1295 1274 * 1296 1275 * @param int $user_id ID of the user being queried. 1297 *1298 1276 * @return array Post IDs. 1299 1277 */ … … 1319 1297 function bp_core_delete_account( $user_id = 0 ) { 1320 1298 1321 // Use logged in user ID if none is passed 1299 // Use logged in user ID if none is passed. 1322 1300 if ( empty( $user_id ) ) { 1323 1301 $user_id = bp_loggedin_user_id(); 1324 1302 } 1325 1303 1326 // Site admins cannot be deleted 1304 // Site admins cannot be deleted. 1327 1305 if ( is_super_admin( $user_id ) ) { 1328 1306 return false; 1329 1307 } 1330 1308 1331 // Extra checks if user is not deleting themselves 1309 // Extra checks if user is not deleting themselves. 1332 1310 if ( bp_loggedin_user_id() !== absint( $user_id ) ) { 1333 1311 1334 // Bail if current user cannot delete any users 1312 // Bail if current user cannot delete any users. 1335 1313 if ( ! bp_current_user_can( 'delete_users' ) ) { 1336 1314 return false; 1337 1315 } 1338 1316 1339 // Bail if current user cannot delete this user 1317 // Bail if current user cannot delete this user. 1340 1318 if ( ! current_user_can_for_blog( bp_get_root_blog_id(), 'delete_user', $user_id ) ) { 1341 1319 return false; … … 1352 1330 do_action( 'bp_core_pre_delete_account', $user_id ); 1353 1331 1354 // Specifically handle multi-site environment 1332 // Specifically handle multi-site environment. 1355 1333 if ( is_multisite() ) { 1356 1334 require_once( ABSPATH . '/wp-admin/includes/ms.php' ); … … 1359 1337 $retval = wpmu_delete_user( $user_id ); 1360 1338 1361 // Single site user deletion 1339 // Single site user deletion. 1362 1340 } else { 1363 1341 require_once( ABSPATH . '/wp-admin/includes/user.php' ); … … 1383 1361 * 1384 1362 * @param int $user_id ID of the user who is about to be deleted. 1385 *1386 1363 * @return bool True on success, false on failure. 1387 1364 */ … … 1401 1378 * 1402 1379 * @param string $str String to be upper-cased. 1403 *1404 1380 * @return string 1405 1381 */ … … 1423 1399 * @param WP_User|WP_Error $user Either the WP_User object or the WP_Error 1424 1400 * object, as passed to the 'authenticate' filter. 1425 *1426 1401 * @return WP_User|WP_Error If the user is not a spammer, return the WP_User 1427 1402 * object. Otherwise a new WP_Error object. … … 1429 1404 function bp_core_boot_spammer( $user ) { 1430 1405 1431 // check to see if the $user has already failed logging in, if so return $user as-is1406 // Check to see if the $user has already failed logging in, if so return $user as-is. 1432 1407 if ( is_wp_error( $user ) || empty( $user ) ) { 1433 1408 return $user; 1434 1409 } 1435 1410 1436 // the user exists; now do a check to see if the user is a spammer1411 // The user exists; now do a check to see if the user is a spammer 1437 1412 // if the user is a spammer, stop them in their tracks! 1438 1413 if ( is_a( $user, 'WP_User' ) && ( ( is_multisite() && (int) $user->spam ) || 1 == $user->user_status ) ) { … … 1440 1415 } 1441 1416 1442 // user is good to go!1417 // User is good to go! 1443 1418 return $user; 1444 1419 } … … 1452 1427 function bp_core_remove_data( $user_id ) { 1453 1428 1454 // Remove last_activity data 1429 // Remove last_activity data. 1455 1430 BP_Core_User::delete_last_activity( $user_id ); 1456 1431 1457 // Flush the cache to remove the user from all cached objects 1432 // Flush the cache to remove the user from all cached objects. 1458 1433 wp_cache_flush(); 1459 1434 } … … 1499 1474 * Multisite settings. 1500 1475 * @param array|string $oldvalue The old value of the option. 1501 *1502 1476 * @return array Merged and unique array of illegal names. 1503 1477 */ 1504 1478 function bp_core_get_illegal_names( $value = '', $oldvalue = '' ) { 1505 1479 1506 // Make sure $value is array 1480 // Make sure $value is array. 1507 1481 if ( empty( $value ) ) { 1508 1482 $db_illegal_names = array(); … … 1531 1505 ); 1532 1506 1533 // Core constants 1507 // Core constants. 1534 1508 $slug_constants = array( 1535 1509 'BP_GROUPS_SLUG', … … 1561 1535 $filtered_illegal_names = apply_filters( 'bp_core_illegal_usernames', array_merge( array( 'www', 'web', 'root', 'admin', 'main', 'invite', 'administrator' ), $bp_component_slugs ) ); 1562 1536 1563 // Merge the arrays together 1537 // Merge the arrays together. 1564 1538 $merged_names = array_merge( (array) $filtered_illegal_names, (array) $db_illegal_names ); 1565 1539 1566 // Remove duplicates 1540 // Remove duplicates. 1567 1541 $illegal_names = array_unique( (array) $merged_names ); 1568 1542 … … 1590 1564 * 1591 1565 * @param string $user_email The email being checked. 1592 *1593 1566 * @return bool|array True if the address passes all checks; otherwise an array 1594 1567 * of error codes. … … 1605 1578 1606 1579 // 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. 1608 1581 if ( function_exists( 'is_email_address_unsafe' ) && is_email_address_unsafe( $user_email ) ) { 1609 1582 $errors['domain_banned'] = 1; … … 1611 1584 1612 1585 // 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. 1614 1587 $limited_email_domains = get_site_option( 'limited_email_domains' ); 1615 1588 if ( is_array( $limited_email_domains ) && empty( $limited_email_domains ) == false ) { … … 1668 1641 * @param string $user_name Username to validate. 1669 1642 * @param string $user_email Email address to validate. 1670 *1671 1643 * @return array Results of user validation including errors, if any. 1672 1644 */ 1673 1645 function bp_core_validate_user_signup( $user_name, $user_email ) { 1674 1646 1675 // Make sure illegal names include BuddyPress slugs and values 1647 // Make sure illegal names include BuddyPress slugs and values. 1676 1648 bp_core_flush_illegal_names(); 1677 1649 … … 1683 1655 // When not running Multisite, we perform our own validation. What 1684 1656 // 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. 1686 1658 } else { 1687 1659 $errors = new WP_Error(); … … 1696 1668 $user_name = apply_filters( 'pre_user_login', $user_name ); 1697 1669 1698 // User name can't be empty 1670 // User name can't be empty. 1699 1671 if ( empty( $user_name ) ) { 1700 1672 $errors->add( 'user_name', __( 'Please enter a username', 'buddypress' ) ); 1701 1673 } 1702 1674 1703 // user name can't be on the blacklist1675 // User name can't be on the blacklist. 1704 1676 $illegal_names = get_site_option( 'illegal_names' ); 1705 1677 if ( in_array( $user_name, (array) $illegal_names ) ) { … … 1707 1679 } 1708 1680 1709 // User name must pass WP's validity check 1681 // User name must pass WP's validity check. 1710 1682 if ( ! validate_username( $user_name ) ) { 1711 1683 $errors->add( 'user_name', __( 'Usernames can contain only letters, numbers, ., -, and @', 'buddypress' ) ); 1712 1684 } 1713 1685 1714 // Minimum of 4 characters 1686 // Minimum of 4 characters. 1715 1687 if ( strlen( $user_name ) < 4 ) { 1716 1688 $errors->add( 'user_name', __( 'Username must be at least 4 characters', 'buddypress' ) ); … … 1729 1701 } 1730 1702 1731 // Check into signups 1703 // Check into signups. 1732 1704 $signups = BP_Signup::get( array( 1733 1705 'user_login' => $user_name, … … 1742 1714 1743 1715 // Validate the email address and process the validation results into 1744 // error messages 1716 // error messages. 1745 1717 $validate_email = bp_core_validate_email_address( $user_email ); 1746 1718 bp_core_add_validation_error_messages( $errors, $validate_email ); 1747 1719 1748 // Assemble the return array 1720 // Assemble the return array. 1749 1721 $result = array( 1750 1722 'user_name' => $user_name, … … 1753 1725 ); 1754 1726 1755 // Apply WPMU legacy filter 1727 // Apply WPMU legacy filter. 1756 1728 $result = apply_filters( 'wpmu_validate_user_signup', $result ); 1757 1729 } … … 1774 1746 * @param string $blog_url Blog URL requested during registration. 1775 1747 * @param string $blog_title Blog title requested during registration. 1776 *1777 1748 * @return array 1778 1749 */ … … 1802 1773 * @param array $usermeta Miscellaneous metadata about the user (blog-specific 1803 1774 * signup data, xprofile data, etc). 1804 *1805 1775 * @return bool|WP_Error True on success, WP_Error on failure. 1806 1776 */ … … 1808 1778 $bp = buddypress(); 1809 1779 1810 // We need to cast $user_id to pass to the filters 1780 // We need to cast $user_id to pass to the filters. 1811 1781 $user_id = false; 1812 1782 1813 // Multisite installs have their own install procedure 1783 // Multisite installs have their own install procedure. 1814 1784 if ( is_multisite() ) { 1815 1785 wpmu_signup_user( $user_login, $user_email, $usermeta ); 1816 1786 1817 1787 } else { 1818 // Format data 1788 // Format data. 1819 1789 $user_login = preg_replace( '/\s+/', '', sanitize_user( $user_login, true ) ); 1820 1790 $user_email = sanitize_email( $user_email ); … … 1899 1869 * @param string $user_email Email address of requesting user. 1900 1870 * @param string $usermeta Miscellaneous metadata for the user. 1901 *1902 1871 * @return bool 1903 1872 */ … … 1908 1877 1909 1878 /** 1910 * Filters the result of wpmu_signup_blog() 1879 * Filters the result of wpmu_signup_blog(). 1911 1880 * 1912 1881 * This filter provides no value and is retained for … … 1924 1893 * 1925 1894 * @param string $key Activation key. 1926 *1927 1895 * @return int|bool User ID on success, false on failure. 1928 1896 */ … … 1932 1900 $user = false; 1933 1901 1934 // Multisite installs have their own activation routine 1902 // Multisite installs have their own activation routine. 1935 1903 if ( is_multisite() ) { 1936 1904 $user = wpmu_activate_signup( $key ); 1937 1905 1938 // If there were errors, add a message and redirect 1906 // If there were errors, add a message and redirect. 1939 1907 if ( ! empty( $user->errors ) ) { 1940 1908 return $user; … … 1962 1930 } 1963 1931 1964 // password is hashed again in wp_insert_user1932 // Password is hashed again in wp_insert_user. 1965 1933 $password = wp_generate_password( 12, false ); 1966 1934 1967 1935 $user_id = username_exists( $signup->user_login ); 1968 1936 1969 // Create the user 1937 // Create the user. 1970 1938 if ( ! $user_id ) { 1971 1939 $user_id = wp_create_user( $signup->user_login, $password, $signup->user_email ); … … 1974 1942 // created locally for backward compatibility. Process it. 1975 1943 } 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. 1977 1945 if ( ! $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->users} SET user_status = 0 WHERE ID = %d", $user_id ) ) ) { 1978 1946 return new WP_Error( 'invalid_key', __( 'Invalid activation key.', 'buddypress' ) ); … … 1994 1962 } 1995 1963 1996 // Fetch the signup so we have the data later on 1964 // Fetch the signup so we have the data later on. 1997 1965 $signups = BP_Signup::get( array( 1998 1966 'activation_key' => $key, … … 2001 1969 $signup = isset( $signups['signups'] ) && ! empty( $signups['signups'][0] ) ? $signups['signups'][0] : false; 2002 1970 2003 // Activate the signup 1971 // Activate the signup. 2004 1972 BP_Signup::validate( $key ); 2005 1973 … … 2008 1976 } 2009 1977 2010 // Set up data to pass to the legacy filter 1978 // Set up data to pass to the legacy filter. 2011 1979 $user = array( 2012 1980 'user_id' => $user_id, … … 2015 1983 ); 2016 1984 2017 // Notify the site admin of a new user registration 1985 // Notify the site admin of a new user registration. 2018 1986 wp_new_user_notification( $user_id ); 2019 1987 … … 2034 2002 } 2035 2003 2036 // Set any profile data 2004 // Set any profile data. 2037 2005 if ( bp_is_active( 'xprofile' ) ) { 2038 2006 if ( ! empty( $user['meta']['profile_field_ids'] ) ) { … … 2046 2014 } 2047 2015 2048 // Save the visibility level 2016 // Save the visibility level. 2049 2017 $visibility_level = ! empty( $user['meta']['field_' . $field_id . '_visibility'] ) ? $user['meta']['field_' . $field_id . '_visibility'] : 'public'; 2050 2018 xprofile_set_field_visibility_level( $field_id, $user_id, $visibility_level ); … … 2053 2021 } 2054 2022 2055 // Update the display_name 2023 // Update the display_name. 2056 2024 wp_update_user( array( 2057 2025 'ID' => $user_id, … … 2059 2027 ) ); 2060 2028 2061 // Set the password on multisite installs 2029 // Set the password on multisite installs. 2062 2030 if ( ! empty( $user['meta']['password'] ) ) { 2063 2031 $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->users} SET user_pass = %s WHERE ID = %d", $user['meta']['password'], $user_id ) ); … … 2102 2070 2103 2071 // Fetch activation keys separately, to avoid the all_with_meta 2104 // overhead 2072 // overhead. 2105 2073 $status_2_ids_sql = implode( ',', $status_2_ids ); 2106 2074 $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})" ); 2107 2075 2108 // Rekey 2076 // Rekey. 2109 2077 $activation_keys = array(); 2110 2078 foreach ( $ak_data as $ak_datum ) { … … 2114 2082 unset( $status_2_ids_sql, $status_2_ids, $ak_data ); 2115 2083 2116 // Merge 2084 // Merge. 2117 2085 foreach ( $signups as &$signup ) { 2118 2086 if ( isset( $activation_keys[ $signup->ID ] ) ) { … … 2121 2089 } 2122 2090 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. 2124 2092 unset( $signup ); 2125 2093 … … 2131 2099 $meta = array(); 2132 2100 2133 // Rebuild the activation key, if missing 2101 // Rebuild the activation key, if missing. 2134 2102 if ( empty( $signup->activation_key ) ) { 2135 2103 $signup->activation_key = wp_hash( $signup->ID ); … … 2153 2121 ) ); 2154 2122 2155 // Deleting these options will remove signups from users count 2123 // Deleting these options will remove signups from users count. 2156 2124 delete_user_option( $signup->ID, 'capabilities' ); 2157 2125 delete_user_option( $signup->ID, 'user_level' ); … … 2166 2134 * 2167 2135 * @param int $user_id ID of the user. 2168 *2169 2136 * @return bool 2170 2137 */ … … 2176 2143 } 2177 2144 2178 // Add the user's fullname to Xprofile 2145 // Add the user's fullname to Xprofile. 2179 2146 if ( bp_is_active( 'xprofile' ) ) { 2180 2147 $firstname = bp_get_user_meta( $user_id, 'first_name', true ); … … 2296 2263 * @param string $username The inputted, attempted username. 2297 2264 * @param string $password The inputted, attempted password. 2298 *2299 2265 * @return WP_User|WP_Error 2300 2266 */ 2301 2267 function bp_core_signup_disable_inactive( $user = null, $username = '', $password ='' ) { 2302 // login form not used2268 // Login form not used. 2303 2269 if ( empty( $username ) && empty( $password ) ) { 2304 2270 return $user; … … 2312 2278 2313 2279 // If no WP_User is found corresponding to the username, this 2314 // is a potential signup 2280 // is a potential signup. 2315 2281 } elseif ( is_wp_error( $user ) && 'invalid_username' == $user->get_error_code() ) { 2316 2282 $user_login = $username; 2317 2283 2318 // This is an activated user, so bail 2284 // This is an activated user, so bail. 2319 2285 } else { 2320 2286 return $user; 2321 2287 } 2322 2288 2323 // Look for the unactivated signup corresponding to the login name 2289 // Look for the unactivated signup corresponding to the login name. 2324 2290 $signup = BP_Signup::get( array( 'user_login' => sanitize_user( $user_login ) ) ); 2325 2291 … … 2330 2296 2331 2297 // Unactivated user account found! 2332 // Set up the feedback message 2298 // Set up the feedback message. 2333 2299 $signup_id = $signup['signups'][0]->signup_id; 2334 2300 … … 2363 2329 } 2364 2330 2365 // verify nonce2331 // Verify nonce. 2366 2332 if ( ! wp_verify_nonce( $_GET['_wpnonce'], 'bp-resend-activation' ) ) { 2367 2333 die( 'Security check' ); … … 2370 2336 $signup_id = (int) $_GET['id']; 2371 2337 2372 // resend the activation email2373 // 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. 2374 2340 $resend = BP_Signup::resend( array( $signup_id ) ); 2375 2341 2376 // add feedback message2342 // Add feedback message. 2377 2343 if ( ! empty( $resend['errors'] ) ) { 2378 2344 $error = __( '<strong>ERROR</strong>: Your account has already been activated.', 'buddypress' ); … … 2388 2354 function bp_core_wpsignup_redirect() { 2389 2355 2390 // Bail in admin or if custom signup page is broken 2356 // Bail in admin or if custom signup page is broken. 2391 2357 if ( is_admin() || ! bp_has_custom_signup_page() ) { 2392 2358 return; … … 2395 2361 $action = !empty( $_GET['action'] ) ? $_GET['action'] : ''; 2396 2362 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. 2398 2364 if ( ! empty( $_SERVER['SCRIPT_NAME'] ) && false === strpos( $_SERVER['SCRIPT_NAME'], 'wp-signup.php' ) && ( 'register' != $action ) ) { 2399 2365 return; … … 2426 2392 */ 2427 2393 function bp_stop_live_spammer() { 2428 // if we're on the login page, stop now to prevent redirect loop2394 // If we're on the login page, stop now to prevent redirect loop. 2429 2395 $is_login = false; 2430 2396 if ( isset( $GLOBALS['pagenow'] ) && ( false !== strpos( $GLOBALS['pagenow'], 'wp-login.php' ) ) ) { … … 2438 2404 } 2439 2405 2440 // user isn't logged in, so stop!2406 // User isn't logged in, so stop! 2441 2407 if ( ! is_user_logged_in() ) { 2442 2408 return; 2443 2409 } 2444 2410 2445 // if spammer, redirect to wp-login.php and reauthorize2411 // If spammer, redirect to wp-login.php and reauthorize. 2446 2412 if ( bp_is_user_spammer( bp_loggedin_user_id() ) ) { 2447 // setup login args2413 // Setup login args. 2448 2414 $args = array( 2449 // custom action used to throw an error message2415 // Custom action used to throw an error message. 2450 2416 'action' => 'bp-spam', 2451 2417 2452 // reauthorize user to login2418 // Reauthorize user to login. 2453 2419 'reauth' => 1 2454 2420 ); … … 2463 2429 $login_url = apply_filters( 'bp_live_spammer_redirect', add_query_arg( $args, wp_login_url() ) ); 2464 2430 2465 // redirect user to login page2431 // Redirect user to login page. 2466 2432 wp_redirect( $login_url ); 2467 2433 die(); … … 2480 2446 $error = __( '<strong>ERROR</strong>: Your account has been marked as a spammer.', 'buddypress' ); 2481 2447 2482 // shake shake shake!2448 // Shake shake shake! 2483 2449 add_action( 'login_head', 'wp_shake_js', 12 ); 2484 2450 } … … 2587 2553 * 2588 2554 * @param string $member_type The name of the member type. 2589 *2590 2555 * @return object A member type object. 2591 2556 */ … … 2614 2579 * element from the array needs to match; 'and' means all elements 2615 2580 * must match. Accepts 'or' or 'and'. Default 'and'. 2616 *2617 2581 * @return array A list of member type names or objects. 2618 2582 */ … … 2652 2616 * @param bool $append Optional. True to append this to existing types for user, 2653 2617 * false to replace. Default: false. 2654 * @return See {@see bp_set_object_terms()}.2618 * @return array $retval See {@see bp_set_object_terms()}. 2655 2619 */ 2656 2620 function bp_set_member_type( $user_id, $member_type, $append = false ) { … … 2688 2652 * @param int $user_id ID of the user. 2689 2653 * @param string $member_type Member Type. 2690 *2691 2654 * @return bool|WP_Error 2692 2655 */ … … 2722 2685 * @since 2.2.0 2723 2686 * 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. 2728 2690 * @return string|array|bool On success, returns a single member type (if $single is true) or an array of member 2729 2691 * types (if $single is false). Returns false on failure. … … 2769 2731 * @param int $user_id $user_id ID of the user. 2770 2732 * @param string $member_type Member Type. 2771 *2772 2733 * @return bool Whether the user has the given member type. 2773 2734 */ … … 2794 2755 * 2795 2756 * @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()}. 2798 2758 */ 2799 2759 function bp_remove_member_type_on_user_delete( $user_id ) {
Note: See TracChangeset
for help on using the changeset viewer.