bbp_make_ham_user( int $user_id )
Mark a users topics and replies as spam when the user is marked as spam
Description
Parameters
- $user_id
-
(Optional) User ID to unspam. Defaults to displayed user.
Return
(If) no user ID passed
Source
File: bp-forums/users/capabilities.php
496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 | function bbp_make_ham_user( $user_id = 0 ) { // Use displayed user if it's not yourself if ( empty ( $user_id ) && bbp_is_single_user() && !bbp_is_user_home() ) $user_id = bbp_get_displayed_user_id(); // Bail if no user ID if ( empty ( $user_id ) ) return false; // Bail if user ID is keymaster if ( bbp_is_user_keymaster( $user_id ) ) return false; // Arm the torpedos global $wpdb ; // Get the blog IDs of the user to mark as spam $blogs = get_blogs_of_user( $user_id , true ); // If user has no blogs, they are a guest on this site if ( empty ( $blogs ) ) $blogs [ $wpdb ->blogid] = array (); // Make array of post types to mark as spam $post_types = array ( bbp_get_topic_post_type(), bbp_get_reply_post_type() ); $post_types = "'" . implode( "', '" , $post_types ) . "'" ; // Loop through blogs and remove their posts foreach ( ( array ) array_keys ( $blogs ) as $blog_id ) { // Switch to the blog ID switch_to_blog( $blog_id ); // Get topics and replies $posts = $wpdb ->get_col( $wpdb ->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_author = %d AND post_status = '%s' AND post_type IN ( {$post_types} )" , $user_id , bbp_get_spam_status_id() ) ); // Loop through posts and spam them if ( ! empty ( $posts ) ) { foreach ( $posts as $post_id ) { // The routines for topics ang replies are different, so use the // correct one based on the post type switch ( get_post_type( $post_id ) ) { case bbp_get_topic_post_type() : bbp_unspam_topic( $post_id ); break ; case bbp_get_reply_post_type() : bbp_unspam_reply( $post_id ); break ; } } } // Switch back to current blog restore_current_blog(); } // Success return true; } |
Changelog
Version | Description |
---|---|
bbPress (r3405) | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.