2

I've been hacking away at modifying the "Right Now" widget in the WordPress dashboard, and although there are some hooks/filters which apply to just that, they are sparsely documented or explained.

Using the example given here, I've created a new row of information in the "Content" section of the widget... I also tried a few other hooks and one of them placed my row of information in the "Discussion" section of the widget... However, I don't really feel that this data belongs in either of those two sections...

Does anyone know how, or if it's possible to add a new section to the "Right Now" widget? I'd like to add my own section called "Feedback" which would be styled much like the comments ("Discussion") section.

Here's the code I'm using at the moment:

function add_testimonial_counts() {
  if(!post_type_exists('testimonials')) {
    return;
  }

  $num_posts = wp_count_posts('testimonials');
  $num = number_format_i18n($num_posts->publish);
  $text = _n('Approved Testimonial', 'Approved Testimonials', intval($num_posts->publish));

  if(current_user_can('edit_posts')) {
    $num = "<a href='edit.php?post_type=testimonials'>$num</a>";
    $text = "<a href='edit.php?post_type=testimonials'>$text</a>";
  }

  echo '<td class="first b b-testimonials">'.$num.'</td>';
  echo '<td class="t testimonials">'.$text.'</td>';
  echo '</tr>';

  if($num_posts->pending > 0) {
    $num = number_format_i18n($num_posts->pending);
    $text = _n('Testimonial Pending', 'Testimonials Pending', intval($num_posts->pending));

    if(current_user_can('edit_posts')) {
      $num = "<a href='edit.php?post_status=pending&post_type=testimonials'>$num</a>";
      $text = "<a href='edit.php?post_status=pending&post_type=testimonials'>$text</a>";
    }

    echo '<td class="first b b-testimonials">'.$num.'</td>';
    echo '<td class="t testimonials">'.$text.'</td>';
    echo '</tr>';
  }

  if($num_posts->draft > 0) {
    $num = number_format_i18n($num_posts->draft);
    $text = _n('Testimonial Draft', 'Testimonial Drafts', intval($num_posts->draft));

    if(current_user_can('edit_posts')) {
      $num = "<a href='edit.php?post_status=draft&post_type=testimonials'>$num</a>";
      $text = "<a href='edit.php?post_status=draft&post_type=testimonials'>$text</a>";
    }

    echo '<td class="first b b-testimonials">'.$num.'</td>';
    echo '<td class="t testimonials">'.$text.'</td>';
    echo '</tr>';
  }
}
add_action('right_now_content_table_end', 'add_testimonial_counts');

Here's a screenshot of how it currently looks just so you can get a better idea of what I'm jabbering on about. Right Now Widget Mods

1 Answer 1

2

I believe the hook you are looking for is right_now_discussion_table_end

Update:

From your comment i see that i did not explain myself, WordPress closes the table and div just after right_now_discussion_table_end action hook so you can use right_now_discussion_table_end and at the begging of your function close the table and div yourself and open your own, then leave your custom table and div open and let WordPress close them.

4
  • well, right now I'm using the "right_now_content_table_end"... the problem with both of those 2 hooks is that they are run as the last thing in each section... So the one I'm using now adds content to the end of the content table... whereas "right_now_discussion_table_end" adds content to the end of the discussion table... I'm wanting to add my own table called "Feedback" with it's own heading and completely separate from the previous two tables. Nov 30, 2011 at 17:38
  • updated my answer
    – Bainternet
    Nov 30, 2011 at 21:22
  • I believe I tried that once but it didn't seem to be working... I may have missed an element though... So I'll give it another shot and report back soon. Thanks! Dec 1, 2011 at 0:59
  • I went ahead and accepted your answer as it does, in fact, work as you explained it... However, I think I'm gonna opt for just removing the original "Right Now" widget and rolling my own from scratch... Because hacking into that one was getting very very messy and unorganized. At any rate, thanks for the response! Dec 1, 2011 at 4:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.