Making WordPress.org


Ignore:
Timestamp:
09/17/2023 06:18:29 PM (10 months ago)
Author:
Clorith
Message:

Support Forums: Improved topic report flows.

Where previously, a reported topic would store the report in post meta and be limited to the sidebar view, and any reaction would be secret, unless a moderator contacted reporters publicly, this is no longer the case.

When a report is made, while we maintain the modlook tag as before for compatibility reasons, the report is added as a custom post type entry. This allows for tracking vigilant users who help out a lot, as well as giving us access to valuable data about what kind of reports are being made.

The reports are also presented as "replies" within a topic, giving valuable contextual information to those reviewing reports during the time of the report. This element is also presented in such a way that a moderator is able to respond to a report directly, letting the user view their previous reports and their outcomes within their forum profile, as well as them getting notified of the outcome by email when a topic is handled.

Fixes #5715.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-users.php

    r12012 r12892  
    77    public function __construct() {
    88        // Add custom fields to user's profile.
    9         add_action( 'bbp_user_edit_after_name',        array( $this, 'add_custom_title_input' ) );
    10         add_action( 'bbp_user_edit_after',             array( $this, 'add_options_section_header' ), 0 );
    11         add_action( 'bbp_user_edit_after',             array( $this, 'add_auto_topic_subscription_checkbox' ) );
     9        add_action( 'bbp_user_edit_after_name',         array( $this, 'add_custom_title_input' ) );
     10        add_action( 'bbp_user_edit_after',              array( $this, 'add_options_section_header' ), 0 );
     11        add_action( 'bbp_user_edit_after',              array( $this, 'add_auto_topic_subscription_checkbox' ) );
    1212
    1313        // Save custom field values.
    14         add_action( 'personal_options_update',         array( $this, 'save_custom_fields' ), 10, 2 );
    15         add_action( 'edit_user_profile_update',        array( $this, 'save_custom_fields' ), 10, 2 );
     14        add_action( 'personal_options_update',          array( $this, 'save_custom_fields' ), 10, 2 );
     15        add_action( 'edit_user_profile_update',         array( $this, 'save_custom_fields' ), 10, 2 );
    1616
    1717        // Adjust display of user fields
    18         add_filter( 'bbp_get_displayed_user_field',    array( $this, 'modify_user_fields' ), 10, 3 );
     18        add_filter( 'bbp_get_displayed_user_field',     array( $this, 'modify_user_fields' ), 10, 3 );
    1919
    2020        // Custom user contact methods.
    21         add_filter( 'user_contactmethods',             array( $this, 'custom_contact_methods' ) );
     21        add_filter( 'user_contactmethods',              array( $this, 'custom_contact_methods' ) );
    2222
    2323        // Add "My Account" submenu items to admin bar for quick access.
    24         add_action( 'admin_bar_menu',                  array( $this, 'add_my_account_submenu_items' ) );
     24        add_action( 'admin_bar_menu',                   array( $this, 'add_my_account_submenu_items' ) );
    2525
    2626        // Only allow 3 published topics from a user in the first 24 hours.
    27         add_action( 'bbp_new_topic_pre_insert',        array( $this, 'limit_new_user_topics' ) );
     27        add_action( 'bbp_new_topic_pre_insert',         array( $this, 'limit_new_user_topics' ) );
    2828
    2929        // Add query vars and rewrite rules for user's topic and review queries.
    30         add_filter( 'query_vars',                      array( $this, 'add_query_vars' ) );
    31         add_action( 'bbp_add_rewrite_rules',           array( $this, 'add_rewrite_rules' ) );
     30        add_filter( 'query_vars',                       array( $this, 'add_query_vars' ) );
     31        add_action( 'bbp_add_rewrite_rules',            array( $this, 'add_rewrite_rules' ) );
    3232
    3333        // Don't allow attempting to set an email to one that is banned-from-use on WordPress.org.
    34         add_action( 'bbp_post_request',                array( $this, 'check_email_safe_for_use' ), 0 ); // bbPress is at 1
     34        add_action( 'bbp_post_request',                 array( $this, 'check_email_safe_for_use' ), 0 ); // bbPress is at 1
    3535
    3636        // Parse user's topic and review queries.
    37         add_action( 'parse_query',                     array( $this, 'parse_user_topics_query' ) );
    38         add_filter( 'posts_groupby',                   array( $this, 'parse_user_topics_posts_groupby' ), 10, 2 );
    39         add_filter( 'bbp_after_has_topics_parse_args', array( $this, 'parse_user_topics_query_args' ) );
    40         add_filter( 'bbp_topic_pagination',            array( $this, 'parse_user_topics_pagination_args' ) );
    41         add_filter( 'bbp_replies_pagination',          array( $this, 'parse_user_topics_pagination_args' ) );
    42         add_filter( 'bbp_before_title_parse_args',     array( $this, 'parse_user_topics_title_args' ) );
     37        add_action( 'parse_query',                      array( $this, 'parse_user_topics_query' ) );
     38        add_filter( 'posts_groupby',                    array( $this, 'parse_user_topics_posts_groupby' ), 10, 2 );
     39        add_filter( 'bbp_after_has_topics_parse_args',  array( $this, 'parse_user_topics_query_args' ) );
     40        add_filter( 'bbp_after_has_replies_parse_args', array( $this, 'parse_user_replies_query_args' ) );
     41        add_filter( 'bbp_topic_pagination',             array( $this, 'parse_user_topics_pagination_args' ) );
     42        add_filter( 'bbp_replies_pagination',           array( $this, 'parse_user_topics_pagination_args' ) );
     43        add_filter( 'bbp_before_title_parse_args',      array( $this, 'parse_user_topics_title_args' ) );
    4344
    4445        // Clear user's topics and reviews count cache.
    45         add_action( 'bbp_new_topic',                   array( $this, 'clear_user_topics_count_cache' ) );
    46         add_action( 'bbp_spammed_topic',               array( $this, 'clear_user_topics_count_cache' ) );
    47         add_action( 'bbp_unspammed_topic',             array( $this, 'clear_user_topics_count_cache' ) );
    48         add_action( 'bbp_approved_topic',              array( $this, 'clear_user_topics_count_cache' ) );
    49         add_action( 'bbp_unapproved_topic',            array( $this, 'clear_user_topics_count_cache' ) );
    50         add_action( 'wporg_bbp_archived_topic',        array( $this, 'clear_user_topics_count_cache' ) );
    51         add_action( 'wporg_bbp_unarchived_topic',      array( $this, 'clear_user_topics_count_cache' ) );
     46        add_action( 'bbp_new_topic',                    array( $this, 'clear_user_topics_count_cache' ) );
     47        add_action( 'bbp_spammed_topic',                array( $this, 'clear_user_topics_count_cache' ) );
     48        add_action( 'bbp_unspammed_topic',              array( $this, 'clear_user_topics_count_cache' ) );
     49        add_action( 'bbp_approved_topic',               array( $this, 'clear_user_topics_count_cache' ) );
     50        add_action( 'bbp_unapproved_topic',             array( $this, 'clear_user_topics_count_cache' ) );
     51        add_action( 'wporg_bbp_archived_topic',         array( $this, 'clear_user_topics_count_cache' ) );
     52        add_action( 'wporg_bbp_unarchived_topic',       array( $this, 'clear_user_topics_count_cache' ) );
    5253    }
    5354
     
    7677            return;
    7778        }
    78        
     79
    7980        $title = get_user_option( 'title', bbp_get_displayed_user_id() );
    8081        ?>
    81         <div>
    82             <label for="title"><?php esc_html_e( 'Custom Title', 'wporg-forums' ); ?></label>
    83             <input type="text" name="title" id="title" value="<?php echo esc_attr( $title ); ?>" class="regular-text" />
    84         </div>
     82        <div>
     83            <label for="title"><?php esc_html_e( 'Custom Title', 'wporg-forums' ); ?></label>
     84            <input type="text" name="title" id="title" value="<?php echo esc_attr( $title ); ?>" class="regular-text" />
     85        </div>
    8586        <?php
    8687    }
     
    102103        $auto_topic_subscription = get_user_option( 'auto_topic_subscription', bbp_get_displayed_user_id() );
    103104        ?>
    104         <p>
    105             <input name="auto_topic_subscription" id="auto_topic_subscription" type="checkbox" value="yes" <?php checked( $auto_topic_subscription ); ?> />
    106             <label for="auto_topic_subscription"><?php esc_html_e( 'Always notify me via email of follow-up posts in any topics I reply to', 'wporg-forums' ); ?></label>
    107         </p>
     105        <p>
     106            <input name="auto_topic_subscription" id="auto_topic_subscription" type="checkbox" value="yes" <?php checked( $auto_topic_subscription ); ?> />
     107            <label for="auto_topic_subscription"><?php esc_html_e( 'Always notify me via email of follow-up posts in any topics I reply to', 'wporg-forums' ); ?></label>
     108        </p>
    108109        <?php
    109110    }
     
    132133        }
    133134        return $value;
    134     }   
     135    }
    135136
    136137    /**
     
    257258
    258259    /**
    259      * Add query vars for user's "Reviews Written" and "Topics Replied To" views.
     260     * Add query vars for user's "Reviews Written",
     261     * "Topics Replied To", and "Reports Submitted" views.
    260262     *
    261263     * @param array $query_vars Query vars.
     
    265267        $query_vars[] = 'wporg_single_user_reviews';
    266268        $query_vars[] = 'wporg_single_user_topics_replied_to';
     269        $query_vars[] = 'wporg_single_user_reported_topics';
    267270        return $query_vars;
    268271    }
    269272
    270273    /**
    271      * Add rewrite rules for user's "Reviews Written" and "Topics Replied To" views.
     274     * Add rewrite rules for user's "Reviews Written",
     275     * "Topics Replied To", and "Reports Submitted" views.
    272276     */
    273277    public function add_rewrite_rules() {
     
    276280        $user_reviews_rule           = bbp_get_user_slug() . '/([^/]+)/reviews/';
    277281        $user_topics_replied_to_rule = bbp_get_user_slug() . '/([^/]+)/replied-to/';
     282        $user_reports_submitted      = bbp_get_user_slug() . '/([^/]+)/reports/';
    278283
    279284        $feed_id    = 'feed';
     
    297302        add_rewrite_rule( $user_topics_replied_to_rule . $paged_rule, 'index.php?' . $user_id . '=$matches[1]&wporg_single_user_topics_replied_to=1&' . $paged_id . '=$matches[2]', $priority );
    298303        add_rewrite_rule( $user_topics_replied_to_rule . $feed_rule,  'index.php?' . $user_id . '=$matches[1]&wporg_single_user_topics_replied_to=1&' . $feed_id  . '=$matches[2]', $priority );
     304
     305        // Add users "Reports Submitted" page rewrite rules.
     306        add_rewrite_rule( $user_reports_submitted . $base_rule,  'index.php?' . $user_id . '=$matches[1]&wporg_single_user_reported_topics=1',                               $priority );
     307        add_rewrite_rule( $user_reports_submitted . $paged_rule, 'index.php?' . $user_id . '=$matches[1]&wporg_single_user_reported_topics=1&' . $paged_id . '=$matches[2]', $priority );
     308        add_rewrite_rule( $user_reports_submitted . $feed_rule,  'index.php?' . $user_id . '=$matches[1]&wporg_single_user_reported_topics=1&' . $feed_id  . '=$matches[2]', $priority );
    299309    }
    300310
    301311    /**
    302312     * Verify that the a new email is valid for use.
    303      * 
     313     *
    304314     * @param string $action The current action.
    305315     */
     
    332342
    333343    /**
    334      * Set WP_Query::bbp_is_single_user_profile to false on user's "Reviews Written"
    335      * and "Topics Replied To" views.
     344     * Set WP_Query::bbp_is_single_user_profile to false on user's "Reviews Written",
     345     * "Topics Replied To", and "Reports Submitted" views.
    336346     *
    337347     * @param WP_Query $query Current query object.
     
    340350        if (
    341351            get_query_var( 'wporg_single_user_reviews' )
    342         ||
     352            ||
    343353            get_query_var( 'wporg_single_user_topics_replied_to' )
     354            ||
     355            get_query_var( 'wporg_single_user_reported_topics' )
    344356        ) {
    345357            $query->bbp_is_single_user_profile = false;
     
    386398
    387399    /**
    388      * Set 'base' argument for pagination links on user's "Reviews Written"
    389      * and "Topics Replied To" views.
     400     * Set the arguments for user's "Reports Submitted" query.
     401     *
     402     * @param array $args WO_Query arguments.
     403     * @return array Filtered query arguments.
     404     */
     405    public function parse_user_replies_query_args( $args ) {
     406        if ( get_query_var( 'wporg_single_user_reported_topics' ) ) {
     407            $args['post_type'] = 'reported_topics';
     408            unset( $args['meta_key'] );
     409            unset( $args['meta_type'] );
     410        }
     411
     412        return $args;
     413    }
     414
     415    /**
     416     * Set 'base' argument for pagination links on user's "Reviews Written",
     417     * "Topics Replied To", and "Reports Submitted" views.
    390418     *
    391419     * @param array $args Pagination arguments.
     
    403431        }
    404432
     433        if ( get_query_var( 'wporg_single_user_reported_topics' ) ) {
     434            $args['base']  = bbp_get_user_profile_url( bbp_get_displayed_user_id() ) . 'reports/';
     435            $args['base'] .= bbp_get_paged_slug() . '/%#%/';
     436        }
     437
    405438        return $args;
    406439    }
    407440
    408441    /**
    409      * Set title for user's "Reviews Written" and "Topics Replied To" views.
     442     * Set title for user's "Reviews Written", "Topics Replied To", and "Reports Submitted" views.
    410443     *
    411444     * @param array $title Title parts.
     
    430463                /* translators: user's display name */
    431464                $title['format'] = __( 'Topics %s Has Replied To', 'wporg-forums' );
     465            }
     466        }
     467
     468        if ( get_query_var( 'wporg_single_user_reported_topics' ) ) {
     469            if ( bbp_is_user_home() ) {
     470                $title['text'] = __( "Reports You've Submitted", 'wporg-forums' );
     471            } elseif ( bbp_get_user_id() ) {
     472                $title['text'] = get_userdata( bbp_get_user_id() )->display_name;
     473                /* translators: user's display name */
     474                $title['format'] = __( 'Reports %s Has Submitted', 'wporg-forums' );
    432475            }
    433476        }
     
    476519
    477520    /**
     521     * Return the raw database count of reports by a user.
     522     *
     523     * @global wpdb $wpdb WordPress database abstraction object.
     524     *
     525     * @param int $user_id User ID to get count for.
     526     * @return int Raw DB count of reports.
     527     */
     528    public function get_user_report_count( $user_id = 0 ) {
     529        global $wpdb;
     530
     531        $user_id = bbp_get_user_id( $user_id );
     532        if ( empty( $user_id ) ) {
     533            return 0;
     534        }
     535
     536        if ( ! class_exists( 'WordPressdotorg\Forums\Plugin' ) ) {
     537            return 0;
     538        }
     539
     540        // Check cache.
     541        $count = wp_cache_get( $user_id, 'user-report-count' );
     542        if ( false === $count ) {
     543            $count = (int) $wpdb->get_var( $wpdb->prepare(
     544                "SELECT COUNT(*)
     545                    FROM {$wpdb->posts}
     546                    WHERE post_type = 'reported_topics'
     547                        AND post_status IN ( 'publish', 'closed' )
     548                        AND post_author = %d",
     549                $user_id
     550            ) );
     551            wp_cache_set( $user_id, $count, 'user-report-count' );
     552        }
     553
     554        return $count;
     555    }
     556
     557    /**
    478558     * Return the raw database count of reviews by a user.
    479559     *
     
    521601    public function clear_user_topics_count_cache( $topic_id ) {
    522602        $post = get_post( $topic_id );
    523        
     603
    524604        if ( Plugin::REVIEWS_FORUM_ID != $post->post_parent ) {
    525605            wp_cache_delete( $post->post_author, 'user-topics-count' );
Note: See TracChangeset for help on using the changeset viewer.