Skip to:
Content

BuddyPress.org

Ticket #5113: 5113.03.patch

File 5113.03.patch, 5.8 KB (added by r-a-y, 11 years ago)
  • bp-core/admin/bp-core-functions.php

     
    825825
    826826        bp_core_install_signups();
    827827}
     828
     829/**
     830 * Add "Mark as Spam/Ham" button to user row actions.
     831 *
     832 * @since BuddyPress (1.9.0)
     833 *
     834 * @param array $actions User row action links.
     835 * @param object $user_object Current user information.
     836 * @return array $actions User row action links.
     837 */
     838function bp_core_admin_user_row_actions( $actions, $user_object ) {
     839
     840        if ( current_user_can( 'edit_user', $user_object->ID ) && bp_loggedin_user_id() != $user_object->ID ) {
     841
     842                $url = bp_get_admin_url( 'users.php' );
     843
     844                if ( bp_is_user_spammer( $user_object->ID ) ) {
     845                        $actions['ham'] = "<a href='" . wp_nonce_url( $url . "?action=ham&amp;user=$user_object->ID", 'bp-spam-user' ) . "'>" . __( 'Not Spam' ) . "</a>";
     846                } else {
     847                        $actions['spam'] = "<a class='submitdelete' href='" . wp_nonce_url( $url . "?action=spam&amp;user=$user_object->ID", 'bp-spam-user' ) . "'>" . __( 'Mark as Spam' ) . "</a>";
     848                }
     849        }
     850
     851        return $actions;
     852}
     853
     854/**
     855 * Catch requests to mark individual users as spam/ham from users.php.
     856 *
     857 * @since BuddyPress (1.9.0)
     858 */
     859function bp_core_admin_user_manage_spammers() {
     860
     861        // Print our inline scripts on non-Multisite
     862        add_action( 'admin_footer', 'bp_core_admin_user_spammed_js' );
     863
     864        $action  = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : false;
     865        $updated = isset( $_REQUEST['updated'] ) ? $_REQUEST['updated'] : false;
     866        $mode    = isset( $_POST['mode'] ) ? $_POST['mode'] : false;
     867
     868        // if this is a multisite, bulk request, stop now!
     869        if ( 'list' == $mode ) {
     870                return;
     871        }
     872
     873        // Process a spam/ham request
     874        if ( ! empty( $action ) && in_array( $action, array( 'spam', 'ham' ) ) ) {
     875
     876                check_admin_referer( 'bp-spam-user' );
     877
     878                $user_id = ! empty( $_REQUEST['user'] ) ? intval( $_REQUEST['user'] ) : false;
     879
     880                if ( empty( $user_id ) ) {
     881                        return;
     882                }
     883
     884                $redirect = wp_get_referer();
     885
     886                $status = ( $action == 'spam' ) ? 'spam' : 'ham';
     887
     888                // Process the user
     889                bp_core_process_spammer_status( $user_id, $status );
     890
     891                $redirect = add_query_arg( array( 'updated' => 'marked-' . $status ), $redirect);
     892
     893                wp_redirect( $redirect );
     894        }
     895
     896        // Display feedback
     897        if ( ! empty( $updated ) && in_array( $updated, array( 'marked-spam', 'marked-ham' ) ) ) {
     898
     899                if ( 'marked-spam' === $updated ) {
     900                        $notice = __( 'User marked as spammer. Spam users are visible only to site admins.', 'buddypress' );
     901                } else {
     902                        $notice = __( 'User removed from spam.', 'buddypress' );
     903                }
     904
     905                bp_core_add_admin_notice( $notice );
     906        }
     907}
     908
     909/**
     910 * Inline script that adds the 'site-spammed' class to spammed users.
     911 *
     912 * @since BuddyPress (1.9.0)
     913 */
     914function bp_core_admin_user_spammed_js() {
     915        ?>
     916        <script type="text/javascript">
     917                jQuery( document ).ready( function($) {
     918                        $( '.row-actions .ham' ).each( function() {
     919                                $( this ).closest( 'tr' ).addClass( 'site-spammed' );
     920                        });
     921                });
     922        </script>
     923        <?php
     924}
  • bp-core/bp-core-admin.php

     
    161161                add_action( 'tool_box', 'bp_core_admin_available_tools_intro' );
    162162                add_action( 'bp_network_tool_box', 'bp_core_admin_available_tools_intro' );
    163163
     164                // On non-multisite, catch
     165                add_action( 'load-users.php', 'bp_core_admin_user_manage_spammers' );
     166
    164167                /** Filters ***********************************************************/
    165168
    166169                // Add link to settings page
    167170                add_filter( 'plugin_action_links',               array( $this, 'modify_plugin_action_links' ), 10, 2 );
    168171                add_filter( 'network_admin_plugin_action_links', array( $this, 'modify_plugin_action_links' ), 10, 2 );
     172
     173                // Add "Mark as Spam" row actions on users.php
     174                add_filter( 'ms_user_row_actions', 'bp_core_admin_user_row_actions', 10, 2 );
     175                add_filter( 'user_row_actions',    'bp_core_admin_user_row_actions', 10, 2 );
    169176        }
    170177
    171178        /**
  • bp-members/bp-members-functions.php

     
    601601 *
    602602 * @param int $user_id The ID of the user being spammed/hammed.
    603603 * @param string $status 'spam' if being marked as spam, 'ham' otherwise.
     604 * @param bool $do_wp_cleanup True to force the cleanup of WordPress content
     605 *        and status, otherwise false. Generally, this should only be false if
     606 *        WordPress is expected to have performed this cleanup independently,
     607 *        as when hooked to 'make_spam_user'.
     608 * @return bool True on success, false on failure.
    604609 */
    605 function bp_core_process_spammer_status( $user_id, $status ) {
     610function bp_core_process_spammer_status( $user_id, $status, $do_wp_cleanup = true ) {
    606611        global $wpdb;
    607612
    608613        // Bail if no user ID
     
    631636        }
    632637
    633638        // When marking as spam in the Dashboard, these actions are handled by WordPress
    634         if ( ! $is_admin ) {
     639        if ( $do_wp_cleanup ) {
    635640
    636641                // Get the blogs for the user
    637642                $blogs = get_blogs_of_user( $user_id, true );
     
    689694 * @param int $user_id The user id passed from the make_spam_user hook
    690695 */
    691696function bp_core_mark_user_spam_admin( $user_id ) {
    692         bp_core_process_spammer_status( $user_id, 'spam' );
     697        bp_core_process_spammer_status( $user_id, 'spam', false );
    693698}
    694699add_action( 'make_spam_user', 'bp_core_mark_user_spam_admin' );
    695700
     
    701706 * @param int $user_id The user id passed from the make_ham_user hook
    702707 */
    703708function bp_core_mark_user_ham_admin( $user_id ) {
    704         bp_core_process_spammer_status( $user_id, 'ham' );
     709        bp_core_process_spammer_status( $user_id, 'ham', false );
    705710}
    706711add_action( 'make_ham_user', 'bp_core_mark_user_ham_admin' );
    707712