[wp-meta] [Making WordPress.org] #8145: Highlight the Spam and Pending menu items when posts are awaiting approval

Making WordPress.org noreply at wordpress.org
Fri Mar 20 20:31:18 UTC 2026


#8145: Highlight the Spam and Pending menu items when posts are awaiting approval
-----------------------------+---------------------
 Reporter:  La Geek          |       Owner:  (none)
     Type:  feature request  |      Status:  new
 Priority:  normal           |   Milestone:
Component:  Support Forums   |  Resolution:
 Keywords:                   |
-----------------------------+---------------------

Comment (by La Geek):

 Or

 == **Using wp_count_posts (high-performance):** ==

 {{{#!php
 <?php
 /**
  * Plugin Name: bbPress Moderation Indicator (Count-based)
  * Description: Adds ⚠ indicators using wp_count_posts (fast, no queries).
  * Version: 1.0
  */

 if (!defined('ABSPATH')) {
     exit; // Prevent direct access
 }

 /**
  * Get count of items for a given status (topics + replies)
  */
 function bbpmi_count_items_by_status($status) {

     if (!current_user_can('moderate')) {
         return 0;
     }

     $allowed_statuses = array('pending', 'spam');
     if (!in_array($status, $allowed_statuses, true)) {
         return 0;
     }

     // Get counts for topics and replies separately
     $topic_counts = wp_count_posts(bbp_get_topic_post_type());
     $reply_counts = wp_count_posts(bbp_get_reply_post_type());

     $topic_count = isset($topic_counts->$status) ? (int)
 $topic_counts->$status : 0;
     $reply_count = isset($reply_counts->$status) ? (int)
 $reply_counts->$status : 0;

     return $topic_count + $reply_count;
 }

 /**
  * Add indicators to bbPress views
  */
 add_filter('bbp_get_views', function ($views) {

     if (!is_array($views)) {
         return $views;
     }

     foreach ($views as $key => $html) {

         if (!is_string($html)) {
             continue;
         }

         // Pending indicator
         if ($key === 'pending' && bbpmi_count_items_by_status('pending') >
 0) {
             $views[$key] = str_replace(
                 '</a>',
                 ' <span class="bbpmi-alert bbpmi-pending" title="' .
 esc_attr__('Pending items exist', 'bbpress') . '">⚠</span></a>',
                 $html
             );
         }

         // Spam indicator
         if ($key === 'spam' && bbpmi_count_items_by_status('spam') > 0) {
             $views[$key] = str_replace(
                 '</a>',
                 ' <span class="bbpmi-alert bbpmi-spam" title="' .
 esc_attr__('Spam items exist', 'bbpress') . '">⚠</span></a>',
                 $html
             );
         }
     }

     return $views;
 });

 /**
  * Add CSS only on bbPress pages
  */
 add_action('wp_enqueue_scripts', function () {

     if (!function_exists('is_bbpress') || !is_bbpress()) {
         return;
     }

     wp_register_style('bbpmi-style', false);
     wp_enqueue_style('bbpmi-style');

     wp_add_inline_style('bbpmi-style', "
         #bbpress-forums .bbpmi-alert {
             margin-left: 4px;
             font-weight: bold;
         }
         #bbpress-forums .bbpmi-pending {
             color: #dba617;
         }
         #bbpress-forums .bbpmi-spam {
             color: #d63638;
         }
     ");
 });

 }}}

-- 
Ticket URL: <https://meta.trac.wordpress.org/ticket/8145#comment:5>
Making WordPress.org <https://meta.trac.wordpress.org/>
Making WordPress.org


More information about the wp-meta mailing list