Unapprove Comment

UPDATE Fixed a bug with moderation set on Typekey users. Bit to be edited is the code in edit_comment.tmpl

unapprove_comment.png

The moderation queue is one of the most powerful features that MT 3 has, and some advocate an aggresive use of it when paired with plugins. Currently, you are able to approve a comment but not unapprove a comment. This hack will add an unapprove button to the edit comment screen that will throw the comment back into moderation.

Open lib/MT/App/CMS.pm and around line 32 find

'approve_comment' => \&approve_comment,

and add beneath it

'unapprove_comment' => \&unapprove_comment,

Next find

sub list_commenters {

and add above it

sub unapprove_comment {
my $app = shift;
my $perms = $app->{perms}
or return $app->error($app->translate("No permissions"));
my $q = $app->{query};
my $comment_id = $q->param('id');
my $blog_id = $q->param('blog_id');
my $comment = MT::Comment->load($comment_id);
my $entry = MT::Entry->load($comment->entry_id)
|| return $app->error("Comment on missing entry!");
if (!$perms->can_edit_all_posts()
&& $entry->author_id != $app->{author}->id) {
return $app->error($app->translate(
"You don't have permission to approve this comment."));
}
$comment->visible(0);
$comment->save();
$app->rebuild_entry(Entry => $comment->entry_id, BuildDependencies => 1);
if ($q->param('_return') eq 'list_comments') {
return $app->redirect($app->uri . "?__mode=list_comments&blog_id=" .
$blog_id . "&msg=The+comment+has+been+unapproved");
} else {
return $app->redirect($app->uri . "?__mode=view&_type=comment&blog_id=" .
$blog_id . "&id=" . $comment_id .
"&msg=The+comment+has+been+unapproved");
}
}

Basically this is just sub approve_comment but I changed visible to 0 (the red line). The last change needs to be made on tmpl/cms/edit_comment.tmpl. Find

<TMPL_IF NAME=INVISIBLE_UNREGISTERED> This comment was posted without registration. It is awaiting your approval.<br /> <input type="button" onClick="window.location='<TMPL_VAR NAME="SCRIPT_URL">?__mode=approve_comment&blog_id=<TMPL_VAR NAME="BLOG_ID">&id=<TMPL_VAR NAME="ID">'" value="<MT_TRANS phrase="Approve">"> </TMPL_IF>

and replace it with

<TMPL_IF NAME=VISIBLE><input type="button" onClick="window.location='<TMPL_VAR NAME="SCRIPT_URL">?__mode=unapprove_comment&blog_id=<TMPL_VAR NAME="BLOG_ID">&id=<TMPL_VAR NAME="ID">'" value="<MT_TRANS phrase="Unapprove">"><TMPL_ELSE>This comment was posted without registration. It is awaiting your approval.<br /> <input type="button" onClick="window.location='<TMPL_VAR NAME="SCRIPT_URL">?__mode=approve_comment&blog_id=<TMPL_VAR NAME="BLOG_ID">&id=<TMPL_VAR NAME="ID">'" value="<MT_TRANS phrase="Approve">"></TMPL_IF>

Upload all files and when you edit a comment and that comment has been approved, you will have an Unapprove button along with Delete and Save. If you hit this button, the comment will be thrown back into the moderation queue and the necessary pages will be rebuilt.

1 Comments

Marvin said:
on Apr 23, 2005 6:13 AM | Reply

Have you tried it yet with 3.16. After my upgrade, I get a password must have changed error when attempting to approve the comment from the detailed page (not the listing).

Leave a comment

Preview