Subject: [PATCH] 6809
---
===================================================================
diff --git a/sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-bbp-user-moderation/inc/class-plugin.php b/sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-bbp-user-moderation/inc/class-plugin.php
--- a/sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-bbp-user-moderation/inc/class-plugin.php	(revision 12411)
+++ b/sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-bbp-user-moderation/inc/class-plugin.php	(date 1677943724772)
@@ -25,6 +25,11 @@
 	// Meta key to store moderation date on flag/unflag actions.
 	const MODERATION_DATE_META = '_wporg_bbp_moderation_date';
 
+	/**
+	 * @var array Array of user id's and their most recent posting history.
+	 */
+	private $user_history = array();
+
 	/**
 	 * Always return the same instance of this plugin.
 	 *
@@ -340,4 +345,47 @@
 
 		return $caps;
 	}
+
+	/**
+	 * Return recent posting history for a given user id.
+	 *
+	 * Returns the last archived post, and the number of pending and approved posts since the
+	 * last archived posts original publication date.
+	 *
+	 * @param int $user_id User id to look up.
+	 * @return array
+	 */
+	function get_user_posting_history( $user_id ) {
+		global $wpdb;
+
+		if ( ! isset( $this->user_history[ $user_id ] ) ) {
+			$details = [
+				'posts_since_archive' => array(),
+				'pending_posts'       => array(),
+				'last_archived_post'  => get_posts( array(
+					'post_type'      => [ 'topic', 'reply' ],
+					'posts_per_page' => 1,
+					'post_status'    => 'archived',
+					'author'         => $user_id,
+				) ),
+			];
+
+			if ( $details['last_archived_post'] ) {
+				$details['posts_since_archive'] = $wpdb->get_var( $wpdb->prepare(
+					"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",
+					$user_id,
+					$details['last_archived_post'][0]->post_modified_gmt
+				) );
+
+				$details['pending_posts'] = $wpdb->get_var( $wpdb->prepare(
+					"SELECT COUNT(DISTINCT `ID`) FROM {$wpdb->posts} WHERE ( `post_type` = 'topic' OR `post_type` = 'reply') AND `post_status` = 'pending' AND `post_author` = %d",
+					$user_id
+				) );
+			}
+
+			$this->user_history[ $user_id ] = $details;
+		}
+
+		return $this->user_history[ $user_id ];
+	}
 }

===================================================================
diff --git a/sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-support/functions.php b/sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-support/functions.php
--- a/sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-support/functions.php	(revision 12411)
+++ b/sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-support/functions.php	(date 1677943793186)
@@ -604,6 +604,89 @@
 			$moderator       = get_user_meta( $post->post_author, $plugin_instance::MODERATOR_META, true );
 			$moderation_date = get_user_meta( $post->post_author, $plugin_instance::MODERATION_DATE_META, true );
 
+			// Include contextual information to pending entries, to help speed up unflagging events.
+			if ( 'pending' === $post->post_status ) {
+				$user_posting_history = $plugin_instance->get_user_posting_history( $post->post_author );
+
+				if ( ! $user_posting_history['last_archived_post'] ) {
+					$notices[] = __( 'The user has no previously archived posts.' ,'wporg-forums' );
+				} else {
+					// Get a DateTime object for when the last archived post was created.
+					$last_archive_time = get_post_modified_time( 'U', true, $user_posting_history['last_archived_post'][0] );
+
+					// Generate a differential time between the last archived post, and the current date and time.
+					$last_archive_elapsed = human_time_diff( strtotime( $user_posting_history['last_archived_post'][0]->post_modified_gmt ) );
+
+					$lines = array();
+
+					if ( $last_archive_time < DAY_IN_SECONDS ) {
+						$lines[] = sprintf(
+							// translators: %s: Time since the last archived post.
+							__( 'The user last had content archived %s.', 'wporg-forums' ),
+							sprintf(
+								'<span title="%s">%s</span>',
+								esc_attr(
+									sprintf(
+										// translators: %s: The original date and time when the users last archived post was.
+										__( 'Last archived post is from %s', 'wporg-forums' ),
+										$user_posting_history['last_archived_post'][0]->post_modified_gmt
+									)
+								),
+								__( 'today', 'wporg-forums' )
+							)
+						);
+					} else {
+						$lines[] = sprintf(
+							// translators: %s: Time since the last archived post.
+							__( 'The user last had content archived %s.', 'wporg-forums' ),
+							sprintf(
+								'<span title="%s">%s</span>',
+								esc_attr(
+									sprintf(
+										// translators: %s: The original date and time when the users last archived post was.
+										__( 'Last archived post is from %s', 'wporg-forums' ),
+										$user_posting_history['last_archived_post'][0]->post_modified_gmt
+									)
+								),
+								sprintf(
+									// translators: %d: Amount of days since the last archived post.
+									_n(
+										'%d day ago',
+										'%d days ago',
+										ceil( ( $last_archive_time - time() ) / DAY_IN_SECONDS ),
+										'wporg-forums'
+									),
+									esc_html( $last_archive_elapsed )
+								)
+							)
+						);
+					}
+
+					$lines[] = sprintf(
+						// translators: %d: The amount of approved posts since the last archived entry.
+						_n(
+							'The user has had %d approved post since their last archived content.',
+							'The user has had %d approved posts since their last archived content.',
+							absint( $user_posting_history['posts_since_archive'] ),
+							'wporg-forums'
+						),
+						esc_html( $user_posting_history['posts_since_archive'] )
+					);
+					$lines[] = sprintf(
+						// translators: %d: The amount of approved posts since the last archived entry.
+						_n(
+							'The user has %d pending post at this time.',
+							'The user has %d pending posts at this time.',
+							absint( $user_posting_history['pending_posts'] ),
+							'wporg-forums'
+						),
+						esc_html( $user_posting_history['pending_posts'] )
+					);
+
+					$notices[] = implode( '<br>', $lines );
+				}
+			}
+
 			if ( $is_user_flagged ) {
 				if ( $moderator && $moderation_date ) {
 					$notices[] = sprintf(
