Skip to:
Content

BuddyPress.org

Changeset 8174


Ignore:
Timestamp:
03/27/2014 06:02:00 PM (10 years ago)
Author:
boonebgorges
Message:

Enable Spam admin tools on non-MS users.php Dashboard panel

This change brings non-MS installations of BuddyPress closer to the
functionality that is native to WP Multisite, with respect to the ability to
manage spam/ham users from the Users panel. It also addresses a shortcoming
whereby admins on non-MS sites would have no way at all to spam/unspam users
if the Settings component was disabled, since the front-end Spam tools are in
that optional component.

Fixes #5113

Props imath, r-a-y

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core/admin/bp-core-functions.php

    r8119 r8174  
    826826    bp_core_install_signups();
    827827}
     828
     829/**
     830 * Add "Mark as Spam/Ham" button to user row actions.
     831 *
     832 * @since BuddyPress (2.0.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 (2.0.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 (2.0.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}
  • trunk/bp-core/bp-core-admin.php

    r8140 r8174  
    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
     
    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
  • trunk/bp-members/bp-members-functions.php

    r8170 r8174  
    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  */
    605 function bp_core_process_spammer_status( $user_id, $status ) {
     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.
     609 */
     610function bp_core_process_spammer_status( $user_id, $status, $do_wp_cleanup = true ) {
    606611    global $wpdb;
    607612
     
    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
     
    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' );
     
    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' );
Note: See TracChangeset for help on using the changeset viewer.