Site icon Hip-Hop Website Design and Development

How to refresh the page when an admin trashes a comment from Comments in the admin site?

Goal

Every time an admin clicks on the "Trash" button below a comment, refresh the page. If the comment was trashed while the admin was in the "All" category, he should be in the "All" category again after the refresh. If he was in the "Pending" category, he should be there again after the refresh.

Why

I’m developing a plugin that has a function hooked on init and will trash comments that are past a certain age. The init hook runs when the button "Trash" below a comment is clicked so as the admin is e.g. in the "Pending" category and trashes a comment, it is possible other comments shown in the table have been trashed in the meantime by my function so the admin should no longer see those other comments after he has trashed the comment.

Things tried

  1. Tried hooking the script mentioned in this answer on the trashed_comment action with no success.
add_action( 'trashed_comment', 'my_refresh_function', 10, 2 );

function my_refresh_function( $comment_ID, $comment_obj ) {
    echo '<script>location.reload();</script>';
}
  1. Also tried using set_current_screen( 'edit-comments' ) on the trashed_comment action with no success.
add_action( 'trashed_comment', 'my_refresh_function', 10, 2 );

function my_refresh_function( $comment_ID, $comment_obj ) {
    set_current_screen( 'edit-comments' );
}
  1. Tried hooking the script mentioned in this answer on the trashed_comment action with no success.
add_action( 'trashed_comment', 'my_refresh_function', 10, 2 );

function my_refresh_function( $comment_ID, $comment_obj ) {
    Header('Location: '.$_SERVER['PHP_SELF']);
}
  1. Tried hooking the script mentioned in this answer on the trashed_comment action with no success.
add_action( 'trashed_comment', 'my_refresh_function', 10, 2 );

function my_refresh_function( $comment_ID, $comment_obj ) {
    $page = $_SERVER['PHP_SELF'];
    echo '<meta http-equiv="Refresh" content="0;' . $page . '">;
}