[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:30:38 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):
I have asked ChatGPT; I have no idea if that's feasible. But perhaps it's
a good starting point for solving the problem.
Both as a MU-Plugin
== **Using WP_Query (flexible, precise):** ==
{{{
<?php
/**
* Plugin Name: bbPress Moderation Indicator (Query-based)
* Description: Adds ⚠ indicators to "Pending" and "Spam" views in bbPress
sidebar when items exist.
* Version: 1.0
*/
if (!defined('ABSPATH')) {
exit; // جلوگیری direct access
}
/**
* Check if items exist for a given post status using WP_Query
*/
function bbpmi_has_items_by_status($status) {
// Only moderators should see indicators
if (!current_user_can('moderate')) {
return false;
}
// Allow only specific statuses
$allowed_statuses = array('pending', 'spam');
if (!in_array($status, $allowed_statuses, true)) {
return false;
}
$transient_key = 'bbpmi_q_' . $status;
// Return cached result if available
$cached = get_transient($transient_key);
if ($cached !== false) {
return (bool) $cached;
}
// Query only 1 post to check existence
$query = new WP_Query(array(
'post_type' => array(
bbp_get_topic_post_type(),
bbp_get_reply_post_type()
),
'post_status' => $status,
'posts_per_page' => 1,
'fields' => 'ids',
'no_found_rows' => true,
'cache_results' => true,
'update_post_meta_cache' => false,
'update_post_term_cache' => false,
));
$has_items = $query->have_posts();
// Cache result for short time
set_transient($transient_key, $has_items, 60);
return $has_items;
}
/**
* Inject warning icons into bbPress sidebar 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_has_items_by_status('pending')) {
$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_has_items_by_status('spam')) {
$views[$key] = str_replace(
'</a>',
' <span class="bbpmi-alert bbpmi-spam" title="' .
esc_attr__('Spam items exist', 'bbpress') . '">⚠</span></a>',
$html
);
}
}
return $views;
});
/**
* Clear cache when relevant posts change
*/
function bbpmi_flush_cache($post_id = 0) {
if ($post_id) {
$type = get_post_type($post_id);
if (!in_array($type, array(
bbp_get_topic_post_type(),
bbp_get_reply_post_type()
), true)) {
return;
}
}
delete_transient('bbpmi_q_pending');
delete_transient('bbpmi_q_spam');
}
add_action('save_post', 'bbpmi_flush_cache');
add_action('transition_post_status', 'bbpmi_flush_cache');
/**
* Add inline 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:4>
Making WordPress.org <https://meta.trac.wordpress.org/>
Making WordPress.org
More information about the wp-meta
mailing list