Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save DrewAPicture/4228440 to your computer and use it in GitHub Desktop.
Save DrewAPicture/4228440 to your computer and use it in GitHub Desktop.
Comments in Account Menu
<?php
//Plugin Name: Comments in Account Menu
new Comments_in_Account_Menu();
class Comments_in_Account_Menu {
function __construct() {
add_action( 'admin_bar_menu', array( &$this, 'admin_bar_menu' ) );
}
function admin_bar_menu( $wp_admin_bar ) {
$comms = get_comments( array(
'user_id' => get_current_user_id(),
'number' => 15
) );
$wp_admin_bar->add_node( array(
'parent' => 'my-account',
'id' => 'recent-comments',
'title' => 'Your Recent Comments:',
) );
foreach( $comms as $c ) {
$o = strip_tags( $c->comment_content );
$text = substr( $o, 0, 30 );
$text .= $text != $o ? '&hellip;' : '';
$wp_admin_bar->add_node( array(
'parent' => 'my-account',
'id' => 'rc-'. $c->comment_ID,
'href' => get_comment_link( $c->comment_ID ),
'title' => $text,
) );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment