We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Plugin: Admin Comments

Development and Programming

mrwarren's avatar
mrwarren
31 posts
17 years ago
mrwarren's avatar mrwarren

This solves a few different problems I had, so I figured I’d push it out for you guys too. Just getting some feedback and bug testing, and if I have time I’ll develop it some more.

Admin Comments is a plugin that lets the superuser delete or close any comment. Additionally, users who are logged in members can delete their own comments. That’s it!

Wrap it up in some ajax and you can have some pretty fancy stuff going on here. I didn’t put the ajax in this as that seemed to really make the plugin more heavy than it needs to be. I recommend reading up on jquery and doing that yourself. I found it pretty doable.

Here’s how you use it:

THE LINKS The first thing you want to do is create the links. Make sure these are inside the {exp:comment:entries} tags. I usually put them near the comment meta information (date, time, author link, etc).

Delete Link Parameters

[b]commentid[/b] (Required) - The comment_id of the comment you wish to display a delete link for. (E.g. 47) Usually you can grab this via the {comment_id} tag
[b]template[/b] (Required) - The name of the template containing the {exp:admin_comment:delete} plugin code. (E.g. site/delete)
[b]authorid[/b] (Required) - The author_id of the comment in question. Usually you can grab this via the {author_id} tag. It's always a number.
[b]showconfirm[/b] (Optional) - If this is set to "true" then the javascript "are you sure?" confirmation box will appear. Defaults to false. Danger!

Example usage inside a comment entries tag:

{exp:admin_comment:delete_link 
  commentid="{comment_id}" 
  showconfirm="false" 
  authorid="{author_id}" 
  template="embeds/delete-comment"}
    Delete
{/exp:admin_comment:delete_link}

Close Link

The exact same parameters and behavior applies to the close link as did with the delete link tags.

{exp:admin_comment:close_link 
  commentid="{comment_id}" 
  authorid="{author_id}" 
  template="embeds/close-comment"}
    Close
{/exp:admin_comment:close_link}

THE ACT OF CLOSING/DELETING The next thing you need to do is create templates that house the actual act of deleting and closing the comments. This is quite simple.

  1. Create a template for deleting comments. This is the same template to which you’re referring in the template parameter in the exp:admin_comment:delete_link tag.
  2. Inside this template put the following tag:
{exp:admin_comment:delete returnlink="true"}.

Note: The parameter “returnlink” is optional and defaults to false. If this is set to “true” then a link to the previous page will appear following a successful comment deletion. The text of this link can be adjusted by changing the value of $returntext in pi.admin_comment.php. You can wrap as little or as much HTML around the tag as you like to ensure that the page is styled to suit your site. The user message (e.g. comment successfully deleted) will appear wherever the tag itself is placed. Currently the plugin is only designed to delete one comment at a time, so you should never embed more than one copy of the tag in a page. All of the standard user EE access checks are completed before a user is allowed to delete the comment, so ensure that your member group permissions are set very carefully.

The exact same parameter and behavior applies to the close tag

{exp:admin_comment:close returnlink="true"}

Whew, that’s it. Remember this is a work in progress, and I take no responsibility if you nuke your site. 😊

By the way, thanks to Dom Stubbs of Vaya Design for writing the Delete Entry plugin upon which a bit of this code is based.

[edit: grammar]

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
17 years ago
Mark Bowen's avatar Mark Bowen

Hi Brian,

Well done. Sounds like a neat little addition this one. I just did something similar with a plugin that I have made. Admittedly not for comments but works in kind of the same way. Might be nice if on the close and delete templates you could instead of having the returnlink=”true” parameter perhaps (also / instead) have a template=”“ parameter and if this is used then the person is re-directed straight back to that template. This could then probably even work for multiple pages using an embedded variable sent through to that template.

Just an idea though. The plugin sounds really good and I’m sure a lot of people will find use for this so well done on this one.

Best wishes,

Mark

       
Joobs's avatar
Joobs
362 posts
16 years ago
Joobs's avatar Joobs

Does this allow the author (not a super admin) of the entry to delete any comments posted to it?

       
leadsuccess's avatar
leadsuccess
408 posts
16 years ago
leadsuccess's avatar leadsuccess

Hi, Looks like a very nice add and well on it’s way. I did come across one issue, the previous link gave me grief and came back with this error notice causing the link not to populate correctly. Anything I can do to correct it?

Notice: Undefined index: 1 in /var/www/vhosts/dvancouver/httpdocs/system/plugins/pi.admin_comment.php on line 165
       
bobh's avatar
bobh
145 posts
16 years ago
bobh's avatar bobh

Hi Brian, is there a way to skip the delete template and go straight back to the comment template? And maybe display an inline succes message?

       
mrwarren's avatar
mrwarren
31 posts
16 years ago
mrwarren's avatar mrwarren
Hi Brian, is there a way to skip the delete template and go straight back to the comment template? And maybe display an inline succes message?

There is, if you use a bit of ajax. That’s how I’ve done it in the past.

       
mrwarren's avatar
mrwarren
31 posts
16 years ago
mrwarren's avatar mrwarren
Does this allow the author (not a super admin) of the entry to delete any comments posted to it?

Nope it sure doesn’t, though I imagine it would be possible to add that kind of functionality to the plugin at some point.

       
mrwarren's avatar
mrwarren
31 posts
16 years ago
mrwarren's avatar mrwarren
Hi, Looks like a very nice add and well on it’s way. I did come across one issue, the previous link gave me grief and came back with this error notice causing the link not to populate correctly. Anything I can do to correct it?
Notice: Undefined index: 1 in /var/www/vhosts/dvancouver/httpdocs/system/plugins/pi.admin_comment.php on line 165

What do you mean by the “previous link”?

       
Ryan 2010's avatar
Ryan 2010
265 posts
16 years ago
Ryan 2010's avatar Ryan 2010

Hi MrWarren,

Great plugin! I was wondering if there has been any new versions since the last post that allows the author to delete any comments?

Thanks Ryan

       
Adam Khan's avatar
Adam Khan
315 posts
16 years ago
Adam Khan's avatar Adam Khan

Just what I was asked to provide and didn’t know how to do. Perfect plugin. Thanks. Tipjar somewhere on begoodnotbad.com?

       
hothousegraphix's avatar
hothousegraphix
851 posts
16 years ago
hothousegraphix's avatar hothousegraphix

mrwarren - just what the Dr. ordered! This plugin looks to address a very specific need. Thanks.

Noticed one thing in testing - FYI - the delete function seems to address everything but the update of the recent_comment_date variable in exp_weblog_titles. I only stumbled across this because I’m pulling that data in on my multiple listing pages and after “deleting” several recent comment entries, that date did not revert back to the prior “recent comment”.

Also, wondering if it would be at all possible to see a brief example of how you achieved the ajax delete without users seeing any intermediary message?

Thanks

       
hothousegraphix's avatar
hothousegraphix
851 posts
16 years ago
hothousegraphix's avatar hothousegraphix

Would anyone happen to be able to lend some advice on how to achieve in conjunction with an ajax call?

Conceptually, I get it. Call the script, fire the delete function, and refresh the div.

Assuming I have the jQuery library installed, I can take advantage of their built in ajax functions.

$(document).ready(function() {});
 $("a.deletelink").click(function() {});
 $.ajax({
   url: "someurl.php", // would this be the path to my delete_comment template?
   success: function() {} // set-up a refresh of parent div
 });

Because the plugin dynamically sets up each delete link, how does one bypass that in favor of a function? I also assume there would need to be some way of passing the comment_id onto the above function.

Anyone done this before?

       
hothousegraphix's avatar
hothousegraphix
851 posts
16 years ago
hothousegraphix's avatar hothousegraphix

I too am getting the Undefined Index error displaying in the delete_comment template

Notice: Undefined index: 1 in /home/mysite/public_html/system/plugins/pi.admin_comment.php on line 165 Notice: Undefined index: 1 in /home/mysite/public_html/system/plugins/pi.admin_comment.php on line 165

Not sure what’s causing this but would really appreciate some guidance.

This is not related to my efforts to employ with ajax as it shows up regardless of implementation.

       
vibe9's avatar
vibe9
96 posts
15 years ago
vibe9's avatar vibe9

@hothousegraphix, I have installed the plugin successfully on EE 1.6.8, with a boat load of other plugins and extensions running. However I have not attempted the Ajax route yet so can’t offer you any advice on the errors you are getting.

Wondering if anyone here has had any success either modifying this plugin or knows of some other plugin that can enable non-super admin authors to delete comments associated with entries they have written via the front end? I have posted in the how-to forum already, but have not had any responses there so thought I would try this thread.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.