WordPress.org

Making WordPress.org

Changeset 9342


Ignore:
Timestamp:
12/13/2019 07:43:25 PM (2 months ago)
Author:
johnjamesjacoby
Message:

bbPress: update the tool that forum moderators use to mark Users as spammers.

This commit brings the bespoke Moderator tool up-to-speed with changes coming in bbPress 2.6.4.

See: https://bbpress.trac.wordpress.org/ticket/3305

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/buddypress.org/public_html/wp-content/plugins/bbpress-org/tools.php

    r1027 r9342  
    1111
    1212    // Bail if not capable
    13     if ( ! current_user_can( 'moderate' ) )
     13    if ( ! current_user_can( 'moderate' ) ) {
    1414        return;
     15    }
    1516
    1617    // Bail if not viewing a user
    17     if ( ! bbp_is_single_user() )
     18    if ( ! bbp_is_single_user() ) {
    1819        return;
     20    }
    1921
    2022    // Bail if no refresh
    21     if ( empty( $_GET['spammer'] ) || ( 'true' != $_GET['spammer'] ) )
     23    if ( empty( $_GET['spammer'] ) || ( 'true' != $_GET['spammer'] ) ) {
    2224        return;
     25    }
    2326
    2427    // Get the user ID
    2528    $user_id = bbp_get_displayed_user_id();
    2629
    27     // Bail if empty and protect super admins
    28     if ( empty( $user_id ) || is_super_admin( $user_id ) )
     30    // Bail if empty, and protect keymasters
     31    if ( empty( $user_id ) || bbp_is_user_keymaster( $user_id ) ) {
    2932        return;
     33    }
    3034
    3135    global $wpdb;
     
    3438    $post_types  = array( bbp_get_topic_post_type(), bbp_get_reply_post_type() );
    3539    $post_types  = "'" . implode( "', '", $post_types ) . "'";
    36     $status      = array( bbp_get_public_status_id(), bbp_get_pending_status_id() );
     40
     41    // Make array of post statuses to mark as spam
     42    $status      = array( bbp_get_public_status_id(), bbp_get_closed_status_id(), bbp_get_pending_status_id() );
     43    $status      = "'" . implode( "', '", $status ) . "'";
    3744
    3845    // Loop through blogs and remove their posts
    3946    // Get topics and replies
    40     $posts = $wpdb->get_col( "SELECT ID FROM {$wpdb->posts} WHERE post_author = {$user_id} AND post_status = '{$status}' AND post_type IN ({$post_types})" );
     47    $posts = $wpdb->get_col( "SELECT ID FROM {$wpdb->posts} WHERE post_author = {$user_id} AND post_status IN ( '{$status}' ) AND post_type IN ({$post_types})" );
    4148
    4249    // Loop through posts and spam them
    43     if ( !empty( $posts ) ) {
     50    if ( ! empty( $posts ) ) {
    4451        foreach ( $posts as $post_id ) {
    4552
     
    5865    }
    5966
    60     // Delete the users description from their profile
    61     $user_description = get_user_meta( $user_id, 'description');
    62     if ( !empty( $user_description ) ) {
    63         delete_user_meta( $user_id, 'description' );
    64     }
     67    // Delete user options
     68    bbp_delete_user_options( $user_id );
     69
     70    // Remove their name & descriptive info
     71    wp_update_user( array(
     72        'ID'           => $user_id,
     73        'description'  => '',
     74        'first_name'   => '',
     75        'last_name'    => '',
     76        'display_name' => '',
     77        'user_url'     => ''
     78    ) );
    6579
    6680    // Block the user
     
    6882
    6983    // Redirect without _GET
    70     wp_safe_redirect( bbp_get_user_profile_url( $user_id ) );
    71     die;
     84    bbp_redirect( bbp_get_user_profile_url( $user_id ) );
    7285}
    7386add_action( 'bbp_template_redirect', 'bbporg_make_user_spammer' );
Note: See TracChangeset for help on using the changeset viewer.