Skip to content

Instantly share code, notes, and snippets.

@thefuxia
Created March 16, 2013 10:24
Show Gist options
  • Save thefuxia/5175829 to your computer and use it in GitHub Desktop.
Save thefuxia/5175829 to your computer and use it in GitHub Desktop.
T5 New Comments In Right Now Dashboard
<?php # -*- coding: utf-8 -*-
/**
* Plugin Name: T5 New Comments In Right Now Dashboard
* Description: Show the number of new comments on the Right Now dashboard
* Plugin URI:
* Version: 2013.03.16
* Author: Thomas Scholz
* Author URI: http://toscho.de
* Licence: MIT
* License URI: http://opensource.org/licenses/MIT
*/
add_action( 'right_now_discussion_table_end', 't5_new_comments_right_now' );
function t5_new_comments_right_now()
{
global $wpdb;
// last user access
$last_access = get_user_meta( get_current_user_id(), 'last_access', TRUE );
// comment query
$where = $wpdb->prepare( "WHERE comment_date > %s", $last_access );
$comment_query = $wpdb->get_results(
"SELECT comment_ID,
COUNT( comment_ID ) AS new_comments
FROM {$wpdb->comments} $where",
OBJECT
);
// default values
$num = 0;
$text = _x(
'New comments',
'no new comments on dashboard right now',
'plugin_t5_new_comments'
);
// overwrite default values
if ( isset ( $comment_query[0]->new_comments ) ) {
$num = $comment_query[0]->new_comments;
$text = _n( 'New comment', 'New comments', $num, 'plugin_t5_new_comments' );
}
// prepare for display
$num = number_format_i18n( $num );
$num = "<a href='edit-comments.php'><span class='total-count'>$num</span></a>";
$text = "<a href='edit-comments.php'>$text</a>";
// display extra column
printf(
'<tr>
<td class="b b-comments">%1$s</td>
<td class="last t comments">%2$s</td>
</tr>',
$num,
$text
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment