Edit Comments XT Plugin
Edit Comments XT is a simple WordPress plugin that allows commenters to edit their own comments. To edit a comment, a user must have the same IP address as the user that made the comment and they must also make the edit within a specific time frame. The default edit time window is 30 minutes, but it can be changed easily in the plugin’s option page.
If you’re logged in to WordPress, it will use the more feature-enhanced wp-admin comment editing screen, but if you aren’t then it will just allow you to edit the content of your comment. It’s a good idea to test the plugin from a logged-out view as well.
Edit Comments XT is based on Andrew Sutherland’s great Edit Comments plugin and works with WordPress 2.1.x and 2.2.x. Also, the security issues of Andrew’s plugin have been addressed & resolved.
Screenshot of the options (click to enlarge):
Downloads
zip, 8.8k
Installation
Unfortunately, the edits required to make this plugin work are fairly extensive. They don’t, however, require any core edits, which means upgrading WordPress versions will not affect this plugin. I’ll try to explain the edits the best I can.
- Decompress the .zip archive and upload the files into your plugins folder (located at
/wp-content/plugins/
) or into a sub folder of the plugins folder. - Activate the plugin from your WordPress admin panel.
- Optional: Navigate to WordPress admin panel > Options > Edit Comments XT and modify the options.
- Here’s where it gets tricky. We’re going to need to make some changes to the
comments.php
file of your theme. This file is located in/wp-content/themes/**YOUR THEME NAME***/comments.php
.Before we make any edits, let’s make a backup of comments.php. Copy the file and name it comments-backup.php. You should now have two comment files in your theme directory, one called comments-backup.php and one called comments.php.
NOTE: For people using the default theme, Kubrick, I’ve included a modified copy of the comments.php file. It contains all the edits needed to make the plugin work. If you’re using a Kubrick-based theme, that file may also work for you.
- For the rest of you, it’ll require quite a bit of tweaking to get it right. Make the following edits to your comments.php file:
- First thing to do is add the link that users will click on to edit their comments. This will be added within the comment loop. The beginning of the comment loop looks like this:
<?php foreach ($comments as $comment) : ?>
And the end of the comment loop looks like:
<?php endforeach; /* end for each comment */ ?>
Anything in between those two bits of code will be repeated for each comment. We need to add a tag that will create the link somewhere in this loop. The code is: . An example would be:
<small class="commentmetadata"><a href="#comment-<?php comment_ID() ?>" title=""><?php comment_date('F jS, Y') ?> at <?php comment_time() ?></a> <?php if (function_exists('edit_comments_xt_link')) { edit_comments_xt_link(); } else { edit_comment_link('edit',' ',''); } ?></small>
This will output the comment date and time, and then the edit link. This function replaces the WordPress’s edit_comment_link().
- Now we need to account for three possible scenarios:
– Someone who is logged in and making a comment
– Someone who isn’t logged in and making a comment
– Someone who is editing their comment (logged in or not doesn’t matter)In your file, the first 2 are already accounted for. We need to make room for the last one.
Find this:
<?php if ( $user_ID ) : ?>
. It means there is someone logged in. The next line might be something like<p>Logged in as....."
.Here we go with a big edit. Delete this:
<?php if ( $user_ID ) : ?>
.
And change it to:<?php if ( isset($_GET['edit_comments_xt']) ) : $edit_comment_xt = edit_comments_xt_init(); if (!$edit_comment_xt) : return; endif; elseif ( $user_ID ) : ?>
- Now we need to edit the
<textarea>
where users input their comments. Look for:<textarea name="comment" id="comment" cols="100%" rows="10" tabindex="4"></textarea>
And replace it with:
<textarea name="comment" id="comment" cols="100%" rows="10" tabindex="4"><?php if (function_exists('edit_comments_xt_content')) edit_comments_xt_content($edit_comment_xt); ?></textarea>
- You’re pretty much done! Now, we can just do a bit of beautification and cleanup.
We obviously don’t want to have the „Leave a Reply“ message as the header of the comment area if they’re editing a comment. So change this:
<h3 id="respond">Leave a Reply</h3>
To:
<h3 id="respond"><?php echo (isset($_GET['edit_comments_xt'])) ? "Edit your Comment" : "Leave a Reply"; ?></h3>
The above uses a ternary operator. Basically, if the someone is editing a comment, it will print „Edit your Comment“, and if not it will print „Leave a Reply“ . You could also use this technique for the submit button.
- First thing to do is add the link that users will click on to edit their comments. This will be added within the comment loop. The beginning of the comment loop looks like this:
- Break out a bottle of champagne. You just finished the installation of Edit Comments XT. Enjoy!
FAQs
How does it work?
WordPress logs the IP address of all commenters, so we can compare the IP address of the comment to the IP address of the viewer. The plugin also checks the timestamp of the comment with the current time. If more than 30 minutes (default) has passed since the comment was made, then editing is off-limits. These two checks together make it secure.
It uses some clever use of plugin hooks. You may notice the <form>
action never has to change, it stays wp-comments-post.php
. This plugin uses the ‚init‘ hook of WordPress to do its deeds before the wp-comments-post.php
file fully loads and it adds a new comment. Instead, this plugin spots the existence of a hidden input element, makes the appropriate edits, and then runs away before the file is fully loaded.
Why is there a time limit on editing?
This plugin is useful when a user hits „Submit Comment“ and then realizes he or she made a glaring spelling error, or forgot an important part of what they were going to say.
Also, by having a time limit, users aren’t allowed to go back and change something they said days ago that they now regret. When there’s a discussion, its best if people can’t go back on their words, or else it can get really confusing.
Lastly, it’s good for security. In the extremely unlikely case that someone else gets the same IP address as one of your commenters and then goes and visits your blog, they won’t be able to edit the comment because of the time-limit.
I can’t find any of the code you mentioned in my comments.php file
All themes are different, and some may have a COMPLETELY different structure. The basic idea of this plugin is to use the same interface as your theme uses to make comments. When you’re editing a comment, the only thing that’ll be updated is the content of the comment. So there should only be a box that’ll allow content-editing. That means hiding the other inputs when an edit is happening. So you can try code like this:
<?php
if ( isset($_GET['edit_comments_xt']) ) {
$edit_comment_xt = edit_comments_xt_init();
if (!$edit_comment_xt) : return; endif;
}
?>
<?php if ( !isset($_GET['edit_comments_xt']) ) { ?>...all the inputs for author, email, url, etc....<?php } ?>
<textarea....><?php edit_comments_xt_content($edit_comment_xt); ?></textarea>
Donation
You like this plugin? Any donation would be highly appreciated:
Version History and Changelog
- 1.0 [2007-07-15]:
Initial release.
How to Report a Bug: Before you report a bug, please make sure you have double-checked that you have followed the above installation instructions correctly.
Please send me your bug report by e-mail.
Bug reports are highly appreciated and will help for the continuous improvement of this plugin, however I can’t promise to get back to you in time regarding your reported bug.