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
- 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>';
}
- Also tried using
set_current_screen( 'edit-comments' )
on thetrashed_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' );
}
- 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']);
}
- 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 . '">;
}
wp-admin/edit-comments.php
page, right? Have you found a solution?