Skip to:
Content

BuddyPress.org

Ticket #5113: 5113.02.patch

File 5113.02.patch, 6.1 KB (added by boonebgorges, 11 years ago)
  • bp-core/admin/bp-core-functions.php

    diff --git bp-core/admin/bp-core-functions.php bp-core/admin/bp-core-functions.php
    index 43533ac..124fd17 100644
    function bp_admin_wp_nav_menu_restrict_items() { 
    765765        </script>
    766766        <?php
    767767}
     768
     769/**
     770 * Add "Mark as Spam/Ham" button to user row actions.
     771 *
     772 * @since BuddyPress (1.9.0)
     773 *
     774 * @param array $actions User row action links.
     775 * @param object $user_object Current user information.
     776 * @return array $actions User row action links.
     777 */
     778function bp_core_admin_user_row_actions( $actions, $user_object ) {
     779
     780        if ( current_user_can( 'edit_user', $user_object->ID ) && bp_loggedin_user_id() != $user_object->ID ) {
     781
     782                $url = bp_get_admin_url( 'users.php' );
     783
     784                if ( bp_is_user_spammer( $user_object->ID ) ) {
     785                        $actions['ham'] = "<a href='" . wp_nonce_url( $url . "?action=ham&amp;user=$user_object->ID", 'bp-spam-user' ) . "'>" . __( 'Not Spam' ) . "</a>";
     786                } else {
     787                        $actions['spam'] = "<a class='submitdelete' href='" . wp_nonce_url( $url . "?action=spam&amp;user=$user_object->ID", 'bp-spam-user' ) . "'>" . __( 'Mark as Spam' ) . "</a>";
     788                }
     789        }
     790
     791        return $actions;
     792}
     793
     794/**
     795 * Catch requests to mark individual users as spam/ham from users.php.
     796 *
     797 * @since BuddyPress (1.9.0)
     798 */
     799function bp_core_admin_user_manage_spammers() {
     800
     801        // Print our inline scripts on non-Multisite
     802        add_action( 'admin_footer', 'bp_core_admin_user_spammed_js' );
     803
     804        $action  = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : false;
     805        $updated = isset( $_REQUEST['updated'] ) ? $_REQUEST['updated'] : false;
     806        $bp      = buddypress();
     807
     808        // Process a spam/ham request
     809        if ( ! empty( $action ) && in_array( $action, array( 'spam', 'ham' ) ) ) {
     810
     811                check_admin_referer( 'bp-spam-user' );
     812
     813                $user_id = ! empty( $_REQUEST['user'] ) ? intval( $_REQUEST['user'] ) : false;
     814
     815                if ( empty( $user_id ) ) {
     816                        return;
     817                }
     818
     819                $redirect = wp_get_referer();
     820
     821                $status = ( $action == 'spam' ) ? 'spam' : 'ham';
     822
     823                // Process the user
     824                bp_core_process_spammer_status( $user_id, $status );
     825
     826                $redirect = add_query_arg( array( 'updated' => 'marked-' . $status ), $redirect);
     827
     828                wp_redirect( $redirect );
     829        }
     830
     831        // Display feedback
     832        if ( ! empty( $updated ) && in_array( $updated, array( 'marked-spam', 'marked-ham' ) ) ) {
     833
     834                if ( 'marked-spam' === $updated ) {
     835                        $notice = __( 'User marked as spammer. Spam users are visible only to site admins.', 'buddypress' );
     836                } else {
     837                        $notice = __( 'User removed from spam.', 'buddypress' );
     838                }
     839
     840                bp_core_add_admin_notice( $notice );
     841        }
     842}
     843
     844/**
     845 * Inline script that adds the 'site-spammed' class to spammed users.
     846 *
     847 * @since BuddyPress (1.9.0)
     848 */
     849function bp_core_admin_user_spammed_js() {
     850        ?>
     851        <script type="text/javascript">
     852                jQuery( document ).ready( function($) {
     853                        $( '.row-actions .ham' ).each( function() {
     854                                $( this ).closest( 'tr' ).addClass( 'site-spammed' );
     855                        });
     856                });
     857        </script>
     858        <?php
     859}
  • bp-core/bp-core-admin.php

    diff --git bp-core/bp-core-admin.php bp-core/bp-core-admin.php
    index f3e91d0..93c1bd3 100644
    class BP_Admin { 
    150150                // Add settings
    151151                add_action( 'bp_register_admin_settings', array( $this, 'register_admin_settings' ) );
    152152
     153                // On non-multisite, catch
     154                add_action( 'load-users.php', 'bp_core_admin_user_manage_spammers' );
     155
    153156                /** Filters ***********************************************************/
    154157
    155158                // Add link to settings page
    156159                add_filter( 'plugin_action_links',               array( $this, 'modify_plugin_action_links' ), 10, 2 );
    157160                add_filter( 'network_admin_plugin_action_links', array( $this, 'modify_plugin_action_links' ), 10, 2 );
     161
     162                // Add "Mark as Spam" row actions on users.php
     163                add_filter( 'ms_user_row_actions', 'bp_core_admin_user_row_actions', 10, 2 );
     164                add_filter( 'user_row_actions',    'bp_core_admin_user_row_actions', 10, 2 );
    158165        }
    159166
    160167        /**
  • bp-members/bp-members-functions.php

    diff --git bp-members/bp-members-functions.php bp-members/bp-members-functions.php
    index 6fd5849..08291e4 100644
    function bp_core_get_active_member_count() { 
    540540 *
    541541 * @param int $user_id The ID of the user being spammed/hammed.
    542542 * @param string $status 'spam' if being marked as spam, 'ham' otherwise.
     543 * @param bool $do_wp_cleanup True to force the cleanup of WordPress content
     544 *        and status, otherwise false. Generally, this should only be false if
     545 *        WordPress is expected to have performed this cleanup independently,
     546 *        as when hooked to 'make_spam_user'.
     547 * @return bool True on success, false on failure.
    543548 */
    544 function bp_core_process_spammer_status( $user_id, $status ) {
     549function bp_core_process_spammer_status( $user_id, $status, $do_wp_cleanup = true ) {
    545550        global $wpdb;
    546551
    547552        // Bail if no user ID
    function bp_core_process_spammer_status( $user_id, $status ) { 
    558563        }
    559564
    560565        $is_spam = ( 'spam' == $status );
     566        $bp = buddypress();
    561567
    562568        // Only you can prevent infinite loops
    563569        remove_action( 'make_spam_user', 'bp_core_mark_user_spam_admin' );
    564570        remove_action( 'make_ham_user',  'bp_core_mark_user_ham_admin'  );
    565571
    566572        // When marking as spam in the Dashboard, these actions are handled by WordPress
    567         if ( !is_admin() ) {
     573        if ( $do_wp_cleanup ) {
    568574
    569575                // Get the blogs for the user
    570576                $blogs = get_blogs_of_user( $user_id, true );
    function bp_core_process_spammer_status( $user_id, $status ) { 
    622628 * @param int $user_id The user id passed from the make_spam_user hook
    623629 */
    624630function bp_core_mark_user_spam_admin( $user_id ) {
    625         bp_core_process_spammer_status( $user_id, 'spam' );
     631        bp_core_process_spammer_status( $user_id, 'spam', false );
    626632}
    627633add_action( 'make_spam_user', 'bp_core_mark_user_spam_admin' );
    628634
    add_action( 'make_spam_user', 'bp_core_mark_user_spam_admin' ); 
    634640 * @param int $user_id The user id passed from the make_ham_user hook
    635641 */
    636642function bp_core_mark_user_ham_admin( $user_id ) {
    637         bp_core_process_spammer_status( $user_id, 'ham' );
     643        bp_core_process_spammer_status( $user_id, 'ham', false );
    638644}
    639645add_action( 'make_ham_user', 'bp_core_mark_user_ham_admin' );
    640646