Backwards-Compatible Spam and Delete Buttons for WordPress
Published Monday, December 1, 2008 @ 8:22 am • 13 Responses
Recently, Joost de Valk shared an excellent technique for adding spam and delete buttons to comments on your WordPress-powered blog. The idea is to save administration time by providing links to either “spam” or “delete” individual comments without having to navigate through the WordPress admin area. Joost provides the following plug-n-play solution:
// add this code to your theme's function.php file:
<?php function delete_comment_link($id) {
if (current_user_can('edit_post')) {
echo '| <a href="'.admin_url("comment.php?action=cdc&c=$id").'">del</a> ';
echo '| <a href="'.admin_url("comment.php?action=cdc&dt=spam&c=$id").'">spam</a>';
}
} ?>
// then, add this tag to a location in your comments.php file:
<?php delete_comment_link(get_comment_ID()); ?>
Nice! Joost’s code works great for all versions of WordPress that support the admin_url() function, which I think is any version greater than or equal to 2.6. So, to get this code working in older versions (less than v2.6) of WordPress, we need to provide the required path information without using admin_url(). One way of doing this is to replace the version-specific admin_url() function with the get_bloginfo() template tag. We can then use the wpurl parameter to return the WordPress installation directory, which is subsequently echoed in the following reformatted function:
// spam & delete links for all versions of WordPress
<?php function delete_comment_link($id) {
if (current_user_can('edit_post')) {
echo '| <a href="'.get_bloginfo('wpurl').'/wp-admin/comment.php?action=cdc&c='.$id.'">del</a> ';
echo '| <a href="'.get_bloginfo('wpurl').'/wp-admin/comment.php?action=cdc&dt=spam&c='.$id.'">spam</a>';
}
} ?>
Place this function in your theme’s functions.php file, and then call the function by adding the following code to the desired location in your comments.php file:
<?php delete_comment_link(get_comment_ID()); ?>
And that’s all there is to it! Depending on placement of the function call, your comments area should now feature quick and easy “spam” and “delete” buttons next to each individual comment. Even better, this improved function is version-independent, backwards-compatible, and thus will work for any version of WordPress.
About this article
Related articles
- WordPress Tip: Remove Spam from the Comment Subscription Manager
- WordPress Spam Battle: 3 Seconds that will Save You Hours of Time
- Block Spam by Denying Access to No-Referrer Requests
- WordPress Tip: Quick Hack to Block Spam for the Wordspew Shoutbox Chat Plugin
- WordPress Search Function Notes
- WordPress RDF Source Makeover
- Delete index.dat on Windows 98SE
Dialogue
13 Responses Jump to comment form
December 2, 2008 at 4:30 am
What a weird idea.
Why would someone prefer to visit their blog pages, one by one, instead of the admin area where everything is gathered conveniently?
December 2, 2008 at 6:48 am
I would say that if you are already on the page and you notice the spam or the comment you want to edit it would be easier they going to your admin area to make the change. But if your concern is having to load and reload things, just apply some Ajax to the mix (with the proper security measures in place of course)
December 2, 2008 at 6:26 pm
Jeff, thanks again for sharing! You never fail to posts stuff that will be of interest to Wordpress developers as well as amateurish designers (like me, hah!). I’ve tried out the plug and play method and it worked! I will save me a lot of time - instead of going back and forth between the comment area and the admin panel (which is a frustrating stuff when a new spam bot appears and Akismet or whatever fails to catch it).
Anyway, users that are using versions of Wordpress that are less than 2.6 should be upgrading ;) it’s a little outdated and has too many security holes here and there (think of being a goldfish trapped in a leaky plastic bag!)
Have a great week ahead! I wonder how’s the holiday festive mood over there. I went downtown yesterday and the lights were pretty nice. Since we don’t really celebrate Christmas over here (we just have an X’mas tree and that’s all. Perhaps a turkey), I don’t have to worry about X’mas shopping. Good luck!
December 3, 2008 at 12:14 am
Thanks for sharing knowledge! :)
By the way, I’d like to let you know I’m having some problems accessing this site behind the ISA server.
Now I’m in a customer facility without proxy and I can see this site, but when I’m behind the ISA-Proxy server I got a 403 error page :D
Greetings! :D
December 28, 2008 at 9:32 pm
Hi Jeff.
I’m back in my hometown again (Rome, anyway) and I can finally interact with your site :)
In my customer’s office (yes, the same place frome where we have that conversation) there’s an ISA server functioning as proxy.
The configuration of this server is very rough, indeed: i.e. it accept SSL connections only at the standard port 443 for HTTPS protocol so we can’t use any site redirecting (you know, for a little more security) the connection to another port.
The ISA server is running on a Windows 2003 Server SR2 and it’s none of my business since my work there consist in helping people for the clients issues (not the servers issues) :)
I’d like to say that’s because I have no competence for this, but… well, I’m not payed enough, thou! :)
I think that your server has strange thoughts (!) about who is visiting what when meet an ISA/proxy HTTP request so it produce a 403 error! ;)
I hope you can solve it!
January 1, 2009 at 4:57 pm
Hi Jeff, next week I’ll be in my customer’ offices and then I can provide the entire HTTP request string (thank to Firefox and its addons it’ll be easier!).
But the problem is that It’ll be difficult to post it if I cannot enter here! :D
By the way there’s another chance: there they have another DSL line (optic fiber) bet that network is not working (we are trasfering the switches, the servers, cables etc from a place to another one).
So when the not-filtered-by-proxy line will be available again I can provide all you need.
The strange thing is that when I wrote my first post this issue came only when I used Firefox but not whit Internet Explorer, but now I cannot access neither using IE or Opera or Google Chrome… strange… uh!?! :D
By the way I want to wish you happy new year :)
Trackbacks / Pingbacks
Share your thoughts..
← Previous post • Next post →
« How to Write Valid URL Query String Parameters • Custom OpenSearch Functionality for Your Website »
1 • Benjamin Sterling
December 1, 2008 at 8:48 am
great tip cause god knows when you are getting a ton of comments its sometimes easier to see the comments in the context of the post.