| 645 | |
| 646 | /** |
| 647 | * Adds an action to user's row to mark him as spam/ham |
| 648 | * |
| 649 | * @param array $actions |
| 650 | * @param object $user_object |
| 651 | * @uses current_user_can() |
| 652 | * @uses bp_loggedin_user_id() |
| 653 | * @uses bp_get_admin_url() |
| 654 | * @uses bp_is_user_spammer() |
| 655 | * @uses wp_nonce_url() |
| 656 | * @return array $actions |
| 657 | */ |
| 658 | function bp_core_admin_user_row_actions( $actions, $user_object ) { |
| 659 | |
| 660 | if ( current_user_can( 'edit_user', $user_object->ID ) && bp_loggedin_user_id() != $user_object->ID ) { |
| 661 | |
| 662 | $url = bp_get_admin_url( 'users.php' ); |
| 663 | |
| 664 | if( bp_is_user_spammer( $user_object->ID ) ) |
| 665 | $actions['ham'] = "<a href='" . wp_nonce_url( $url."?action=ham&user=$user_object->ID", 'bp-spam-user' ) . "'>" . __( 'Unmark as spammer' ) . "</a>"; |
| 666 | else |
| 667 | $actions['spam'] = "<a class='submitdelete' href='" . wp_nonce_url( $url."?action=spam&user=$user_object->ID", 'bp-spam-user' ) . "'>" . __( 'Mark as spammer' ) . "</a>"; |
| 668 | } |
| 669 | |
| 670 | return $actions; |
| 671 | } |
| 672 | |
| 673 | /** |
| 674 | * Checks for a spam/ham user admin request and mark user as requested |
| 675 | * |
| 676 | * @uses check_admin_referer() |
| 677 | * @uses wp_get_referer() |
| 678 | * @uses bp_core_process_spammer_status() |
| 679 | * @uses add_query_arg() |
| 680 | * @uses wp_redirect(); |
| 681 | * @uses bp_core_add_admin_notice() |
| 682 | */ |
| 683 | function bp_core_admin_user_manage_spammers() { |
| 684 | add_action( 'admin_footer', 'bp_core_admin_user_spammed_js' ); |
| 685 | |
| 686 | $action = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : false; |
| 687 | $updated = isset( $_REQUEST['updated'] ) ? $_REQUEST['updated'] : false; |
| 688 | $bp = buddypress(); |
| 689 | |
| 690 | if( !empty( $action ) && in_array( $action, array( 'spam', 'ham' ) ) ) { |
| 691 | |
| 692 | check_admin_referer( 'bp-spam-user' ); |
| 693 | |
| 694 | $user_id = !empty( $_REQUEST['user'] ) ? intval( $_REQUEST['user'] ) : false; |
| 695 | |
| 696 | if( empty( $user_id ) ) |
| 697 | return; |
| 698 | |
| 699 | $redirect = wp_get_referer(); |
| 700 | |
| 701 | $status = ( $action == 'spam' ) ? 'spam' : 'ham'; |
| 702 | |
| 703 | // Treat user.. |
| 704 | $bp->user_admin_spam = true; |
| 705 | bp_core_process_spammer_status( $user_id, $status ); |
| 706 | |
| 707 | $redirect = add_query_arg( array( 'updated' => 'marked-'.$status ), $redirect); |
| 708 | |
| 709 | wp_redirect( $redirect ); |
| 710 | exit(); |
| 711 | } |
| 712 | |
| 713 | // admin feedback if needed |
| 714 | if( !empty( $updated ) && in_array( $updated, array( 'marked-spam', 'marked-ham' ) ) ) { |
| 715 | |
| 716 | if ( 'marked-spam' == $_REQUEST['updated'] ) { |
| 717 | $notice = __( 'User marked as spammer. Spam users are visible only to site admins.', 'buddypress' ); |
| 718 | } else { |
| 719 | $notice = __( 'User removed as spammer.', 'buddypress' ); |
| 720 | } |
| 721 | |
| 722 | $_SERVER['REQUEST_URI'] = remove_query_arg( 'updated' ); |
| 723 | |
| 724 | if( !empty( $notice ) ) { |
| 725 | bp_core_add_admin_notice( $notice ); |
| 726 | } |
| 727 | } |
| 728 | } |
| 729 | |
| 730 | function bp_core_admin_user_spammed_js() { |
| 731 | ?> |
| 732 | <script type="text/javascript"> |
| 733 | jQuery( document ).ready( function($) { |
| 734 | $( '.row-actions .ham').each( function() { |
| 735 | $(this).parent().parent().parent().addClass( 'site-spammed' ); |
| 736 | }); |
| 737 | }); |
| 738 | </script> |
| 739 | <?php |
| 740 | } |