Skip to:
Content

BuddyPress.org

Ticket #5113: 5113.diff

File 5113.diff, 4.5 KB (added by imath, 12 years ago)
  • bp-core/admin/bp-core-functions.php

     
    642642
    643643        return $action;
    644644}
     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 */
     658function 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&amp;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&amp;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 */
     683function 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
     730function 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}
  • bp-core/bp-core-admin.php

     
    132132                // Add link to settings page
    133133                add_filter( 'plugin_action_links',               array( $this, 'modify_plugin_action_links' ), 10, 2 );
    134134                add_filter( 'network_admin_plugin_action_links', array( $this, 'modify_plugin_action_links' ), 10, 2 );
     135
     136                /** For non multisite blogs : users spamming management **************/
     137                if( !is_multisite() ) {
     138                        add_filter( 'user_row_actions', 'bp_core_admin_user_row_actions', 10, 2 );
     139                        add_action( 'load-users.php',   'bp_core_admin_user_manage_spammers'    );
     140                }
    135141        }
    136142
    137143        /**
  • bp-members/bp-members-functions.php

     
    559559        }
    560560
    561561        $is_spam = ( 'spam' == $status );
     562        $bp = buddypress();
    562563
    563564        // Only you can prevent infinite loops
    564565        remove_action( 'make_spam_user', 'bp_core_mark_user_spam_admin' );
    565566        remove_action( 'make_ham_user',  'bp_core_mark_user_ham_admin'  );
    566567
    567568        // When marking as spam in the Dashboard, these actions are handled by WordPress
    568         if ( !is_admin() ) {
     569        if ( !is_admin() || !empty( $bp->user_admin_spam ) ) {
    569570
    570571                // Get the blogs for the user
    571572                $blogs = get_blogs_of_user( $user_id, true );