Changeset 1801 for trunk/bp-core.php
- Timestamp:
- 09/06/2009 11:42:31 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-core.php
r1788 r1801 355 355 add_action( 'admin_menu', 'bp_core_setup_nav', 2 ); 356 356 357 358 /******************************************************************************** 359 * Screen Functions 360 * 361 * Screen functions are the controllers of BuddyPress. They will execute when their 362 * specific URL is caught. They will first save or manipulate data using business 363 * functions, then pass on the user to a template file. 364 */ 365 366 367 /******************************************************************************** 368 * Action Functions 369 * 370 * Action functions are exactly the same as screen functions, however they do not 371 * have a template screen associated with them. Usually they will send the user 372 * back to the default screen after execution. 373 */ 374 375 357 376 /** 358 377 * bp_core_action_directory_members() … … 377 396 } 378 397 add_action( 'wp', 'bp_core_action_directory_members', 2 ); 398 399 /** 400 * bp_core_action_set_spammer_status() 401 * 402 * When a site admin selects "Mark as Spammer/Not Spammer" from the admin menu 403 * this action will fire and mark or unmark the user and their blogs as spam. 404 * Must be a site admin for this function to run. 405 * 406 * @package BuddyPress Core 407 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() 408 */ 409 function bp_core_action_set_spammer_status() { 410 global $bp; 411 412 if ( !is_site_admin() || bp_is_home() || !$bp->displayed_user->id ) 413 return false; 414 415 if ( 'admin' == $bp->current_component && ( 'mark-spammer' == $bp->current_action || 'unmark-spammer' == $bp->current_action ) ) { 416 /* Get the functions file */ 417 require( ABSPATH . 'wp-admin/includes/mu.php' ); 418 419 if ( 'mark-spammer' == $bp->current_action ) 420 $is_spam = 1; 421 else 422 $is_spam = 0; 423 424 /* Get the blogs for the user */ 425 $blogs = get_blogs_of_user( $bp->displayed_user->id, true ); 426 427 foreach ( (array) $blogs as $key => $details ) { 428 /* Do not mark the main or current root blog as spam */ 429 if ( 1 == $details->userblog_id || BP_ROOT_BLOG == $details->userblog_id ) 430 continue; 431 432 /* Update the blog status */ 433 update_blog_status( $details->userblog_id, 'spam', $is_spam ); 434 435 /* Fire the standard WPMU hook */ 436 do_action( 'make_spam_blog', $details->userblog_id ); 437 } 438 439 /* Finally, mark this user as a spammer */ 440 update_user_status( $bp->displayed_user->id, 'spam', $is_spam, 1 ); 441 442 if ( $is_spam ) 443 bp_core_add_message( __( 'User marked as spammer. Spam users are visible only to site admins.', 'buddypress' ) ); 444 else 445 bp_core_add_message( __( 'User removed as spammer.', 'buddypress' ) ); 446 447 do_action( 'bp_core_action_set_spammer_status' ); 448 449 bp_core_redirect( wp_get_referer() ); 450 } 451 } 452 add_action( 'wp', 'bp_core_action_set_spammer_status', 3 ); 453 454 /** 455 * bp_core_action_delete_user() 456 * 457 * Allows a site admin to delete a user from the adminbar menu. 458 * 459 * @package BuddyPress Core 460 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() 461 */ 462 function bp_core_action_delete_user() { 463 global $bp; 464 465 if ( !is_site_admin() || bp_is_home() || !$bp->displayed_user->id ) 466 return false; 467 468 if ( 'admin' == $bp->current_component && 'delete-user' == $bp->current_action ) { 469 $errors = false; 470 471 if ( bp_core_delete_account( $bp->displayed_user->id ) ) { 472 bp_core_add_message( sprintf( __( '%s has been deleted from the system.', 'buddypress' ), $bp->displayed_user->fullname ) ); 473 } else { 474 bp_core_add_message( sprintf( __( 'There was an error deleting %s from the system. Please try again.', 'buddypress' ), $bp->displayed_user->fullname ), 'error' ); 475 $errors = true; 476 } 477 478 do_action( 'bp_core_action_set_spammer_status', $errors ); 479 480 if ( $errors ) 481 bp_core_redirect( $bp->displayed_user->domain ); 482 else 483 bp_core_redirect( $bp->loggedin_user->domain ); 484 } 485 } 486 add_action( 'wp', 'bp_core_action_delete_user', 3 ); 487 488 489 /******************************************************************************** 490 * Business Functions 491 * 492 * Business functions are where all the magic happens in BuddyPress. They will 493 * handle the actual saving or manipulation of information. Usually they will 494 * hand off to a database class for data access, then return 495 * true or false on success or failure. 496 */ 379 497 380 498 /** … … 957 1075 } 958 1076 1077 /** 1078 * bp_core_is_user_spammer() 1079 * 1080 * Checks if the user has been marked as a spammer. 1081 * 1082 * @package BuddyPress Core 1083 * @param $user_id int The id for the user. 1084 * @return int 1 if spammer, 0 if not. 1085 */ 1086 function bp_core_is_user_spammer( $user_id ) { 1087 global $wpdb; 1088 1089 return apply_filters( 'bp_core_is_user_spammer', (int) $wpdb->get_var( $wpdb->prepare( "SELECT spam FROM " . CUSTOM_USER_TABLE . " WHERE ID = %d", $user_id ) ) ); 1090 } 1091 1092 /** 1093 * bp_core_is_user_deleted() 1094 * 1095 * Checks if the user has been marked as deleted. 1096 * 1097 * @package BuddyPress Core 1098 * @param $user_id int The id for the user. 1099 * @return int 1 if deleted, 0 if not. 1100 */ 1101 function bp_core_is_user_deleted( $user_id ) { 1102 global $wpdb; 1103 1104 return apply_filters( 'bp_core_is_user_spammer', (int) $wpdb->get_var( $wpdb->prepare( "SELECT deleted FROM " . CUSTOM_USER_TABLE . " WHERE ID = %d", $user_id ) ) ); 1105 } 959 1106 960 1107 /** … … 1329 1476 * @uses wpmu_delete_user() Deletes a user from the system. 1330 1477 */ 1331 function bp_core_delete_account() { 1332 global $bp; 1478 function bp_core_delete_account( $user_id = false ) { 1479 global $bp; 1480 1481 if ( !$user_id ) 1482 $user_id = $bp->loggedin_user->id; 1333 1483 1334 1484 /* Make sure account deletion is not disabled */ 1335 if ( 1 == (int)get_site_option( 'bp-disable-account-deletion') )1336 return false; 1337 1338 /* Site admins should not be allowed to delete their accounts*/1339 if ( is_site_admin( ) )1485 if ( ( 1 == (int)get_site_option( 'bp-disable-account-deletion' ) && !is_site_admin() ) ) 1486 return false; 1487 1488 /* Site admins should not be allowed to be deleted */ 1489 if ( is_site_admin( bp_core_get_username( $user_id ) ) ) 1340 1490 return false; 1341 1491 … … 1343 1493 require_once( ABSPATH . '/wp-admin/includes/user.php' ); 1344 1494 1345 return wpmu_delete_user( $ bp->loggedin_user->id);1495 return wpmu_delete_user( $user_id ); 1346 1496 } 1347 1497 … … 1515 1665 add_action( 'wpmu_delete_user', 'bp_core_remove_data', 1 ); 1516 1666 add_action( 'delete_user', 'bp_core_remove_data', 1 ); 1517 1667 add_action( 'make_spam_user', 'bp_core_remove_data', 1 ); 1518 1668 1519 1669 /**
Note: See TracChangeset
for help on using the changeset viewer.