Making WordPress.org

Changeset 12616


Ignore:
Timestamp:
06/02/2023 02:48:25 PM (13 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.

Location:
sites/trunk/wordpress.org/public_html/wp-content
Files:
2 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}
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-support/functions.php

    r12598 r12616  
    604604            $moderator       = get_user_meta( $post->post_author, $plugin_instance::MODERATOR_META, true );
    605605            $moderation_date = get_user_meta( $post->post_author, $plugin_instance::MODERATION_DATE_META, true );
     606
     607            // Include contextual information to pending entries, to help speed up unflagging events.
     608            if ( 'pending' === $post->post_status ) {
     609                $user_posting_history = $plugin_instance->get_user_posting_history( $post->post_author );
     610
     611                if ( ! $user_posting_history['last_archived_post'] ) {
     612                    $notices[] = __( 'The user has no previously archived posts.' ,'wporg-forums' );
     613                } else {
     614                    // Get a DateTime object for when the last archived post was created.
     615                    $last_archive_time = get_post_modified_time( 'U', true, $user_posting_history['last_archived_post'][0] );
     616
     617                    // Generate a differential time between the last archived post, and the current date and time.
     618                    $last_archive_elapsed = human_time_diff( strtotime( $user_posting_history['last_archived_post'][0]->post_modified_gmt ) );
     619
     620                    $lines = array();
     621
     622                    if ( $last_archive_time < DAY_IN_SECONDS ) {
     623                        $lines[] = sprintf(
     624                            // translators: %s: Time since the last archived post.
     625                            __( 'The user last had content archived %s.', 'wporg-forums' ),
     626                            sprintf(
     627                                '<span title="%s">%s</span>',
     628                                esc_attr(
     629                                    sprintf(
     630                                        // translators: %s: The original date and time when the users last archived post was.
     631                                        __( 'Last archived post is from %s', 'wporg-forums' ),
     632                                        $user_posting_history['last_archived_post'][0]->post_modified_gmt
     633                                    )
     634                                ),
     635                                __( 'today', 'wporg-forums' )
     636                            )
     637                        );
     638                    } else {
     639                        $lines[] = sprintf(
     640                            // translators: %s: Time since the last archived post.
     641                            __( 'The user last had content archived %s.', 'wporg-forums' ),
     642                            sprintf(
     643                                '<span title="%s">%s</span>',
     644                                esc_attr(
     645                                    sprintf(
     646                                        // translators: %s: The original date and time when the users last archived post was.
     647                                        __( 'Last archived post is from %s', 'wporg-forums' ),
     648                                        $user_posting_history['last_archived_post'][0]->post_modified_gmt
     649                                    )
     650                                ),
     651                                sprintf(
     652                                    // translators: %d: Amount of days since the last archived post.
     653                                    _n(
     654                                        '%d day ago',
     655                                        '%d days ago',
     656                                        ceil( ( $last_archive_time - time() ) / DAY_IN_SECONDS ),
     657                                        'wporg-forums'
     658                                    ),
     659                                    esc_html( $last_archive_elapsed )
     660                                )
     661                            )
     662                        );
     663                    }
     664
     665                    $lines[] = sprintf(
     666                        // translators: %d: The amount of approved posts since the last archived entry.
     667                        _n(
     668                            'The user has had %d approved post since their last archived content.',
     669                            'The user has had %d approved posts since their last archived content.',
     670                            absint( $user_posting_history['posts_since_archive'] ),
     671                            'wporg-forums'
     672                        ),
     673                        esc_html( $user_posting_history['posts_since_archive'] )
     674                    );
     675                    $lines[] = sprintf(
     676                        // translators: %d: The amount of approved posts since the last archived entry.
     677                        _n(
     678                            'The user has %d pending post at this time.',
     679                            'The user has %d pending posts at this time.',
     680                            absint( $user_posting_history['pending_posts'] ),
     681                            'wporg-forums'
     682                        ),
     683                        esc_html( $user_posting_history['pending_posts'] )
     684                    );
     685
     686                    $notices[] = implode( '<br>', $lines );
     687                }
     688            }
    606689
    607690            if ( $is_user_flagged ) {
Note: See TracChangeset for help on using the changeset viewer.