Ticket #6809: 6809.2.patch
File 6809.2.patch, 6.4 KB (added by , 22 months ago) |
---|
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-bbp-user-moderation/inc/class-plugin.php
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 b 25 25 // Meta key to store moderation date on flag/unflag actions. 26 26 const MODERATION_DATE_META = '_wporg_bbp_moderation_date'; 27 27 28 /** 29 * @var array Array of user id's and their most recent posting history. 30 */ 31 private $user_history = array(); 32 28 33 /** 29 34 * Always return the same instance of this plugin. 30 35 * … … 340 345 341 346 return $caps; 342 347 } 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 } 343 391 } -
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-support/functions.php
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 b 604 604 $moderator = get_user_meta( $post->post_author, $plugin_instance::MODERATOR_META, true ); 605 605 $moderation_date = get_user_meta( $post->post_author, $plugin_instance::MODERATION_DATE_META, true ); 606 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 } 689 607 690 if ( $is_user_flagged ) { 608 691 if ( $moderator && $moderation_date ) { 609 692 $notices[] = sprintf(