Making WordPress.org


Ignore:
Timestamp:
06/02/2023 02:48:25 PM (21 months ago)
Author:
Clorith
Message:

Support Forums: Show context information about pending posts.

When viewing queues of pending posts, a moderator is expected to check a users history to make sure they un-flag users in as timely a manner as possible. Doing so generally requires going in and checking the users posting history manually via their profiles.

This change reduces the workload of moderators by providing a lot of this information within context of a pending post.

Fixes #6809.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-bbp-user-moderation/inc/class-plugin.php

    r12012 r12616  
    2525    // Meta key to store moderation date on flag/unflag actions.
    2626    const MODERATION_DATE_META = '_wporg_bbp_moderation_date';
     27
     28    /**
     29     * @var array Array of user id's and their most recent posting history.
     30     */
     31    private $user_history = array();
    2732
    2833    /**
     
    341346        return $caps;
    342347    }
     348
     349    /**
     350     * Return recent posting history for a given user id.
     351     *
     352     * Returns the last archived post, and the number of pending and approved posts since the
     353     * last archived posts original publication date.
     354     *
     355     * @param int $user_id User id to look up.
     356     * @return array
     357     */
     358    function get_user_posting_history( $user_id ) {
     359        global $wpdb;
     360
     361        if ( ! isset( $this->user_history[ $user_id ] ) ) {
     362            $details = [
     363                'posts_since_archive' => array(),
     364                'pending_posts'       => array(),
     365                'last_archived_post'  => get_posts( array(
     366                    'post_type'      => [ 'topic', 'reply' ],
     367                    'posts_per_page' => 1,
     368                    'post_status'    => 'archived',
     369                    'author'         => $user_id,
     370                ) ),
     371            ];
     372
     373            if ( $details['last_archived_post'] ) {
     374                $details['posts_since_archive'] = $wpdb->get_var( $wpdb->prepare(
     375                    "SELECT COUNT(DISTINCT `ID`) FROM {$wpdb->posts} WHERE ( `post_type` = 'topic' OR `post_type` = 'reply') AND `post_status` = 'publish' AND `post_author` = %d AND `post_date_gmt` >= %s",
     376                    $user_id,
     377                    $details['last_archived_post'][0]->post_modified_gmt
     378                ) );
     379
     380                $details['pending_posts'] = $wpdb->get_var( $wpdb->prepare(
     381                    "SELECT COUNT(DISTINCT `ID`) FROM {$wpdb->posts} WHERE ( `post_type` = 'topic' OR `post_type` = 'reply') AND `post_status` = 'pending' AND `post_author` = %d",
     382                    $user_id
     383                ) );
     384            }
     385
     386            $this->user_history[ $user_id ] = $details;
     387        }
     388
     389        return $this->user_history[ $user_id ];
     390    }
    343391}
Note: See TracChangeset for help on using the changeset viewer.