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.


Dialogue

13 Responses Jump to comment form

1Benjamin 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.

2Ozh

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?

3Benjamin Sterling

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)

4Jeff Starr

December 2, 2008 at 8:40 am

@Ozh: Blame it on Joost! ;) No, seriously, having access to spam and delete buttons next to each comment makes it super-easy to clean up missed spam, scummy trackbacks, and other garbage. I am continually scouring my old posts’ comments and weeding out junk, which for me is always easier to see from the actual post pages themselves. Thus, having quick and easy access to spam and delete buttons has made my life considerably easier. For me, it’s a real time-saver.

5Jeff Starr

December 2, 2008 at 9:31 am

@Benjamin Sterling: yes, for me, the main benefit here is convenience and expediency. I am always surfing around my site checking pages — especially during updates and redesigns — and frequently clean up junk comments on the spot. Having those buttons right there and ready to go is much faster than checking the comment number, jumping back into admin, searching for the comment, and then deleting it from there. In fact, the very presence of the spam and delete links serves as a constant reminder, encouraging me to stay vigilant in my fight for relevant, spam-free post comments. ;)

6teddY

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!

7H5N1

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

8Jeff Starr

December 3, 2008 at 4:20 pm

@H5N1: Great to see you again! :) Sorry to hear about the ISA server issues.. it seems like we have had this conversation before..? Is this the same server/issue we are talking about, or a different one?

9H5N1

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!

10Jeff Starr

January 1, 2009 at 11:19 am

Hi H5N1! Great to see you again — sorry for the delayed response; we are currently moving into a new home and it has been crazy trying to unpack and get everything setup, connected and running properly. Now that I am back online, I will try to resolve this issue once and for all.

Based on the information you have provided, it sounds as if the problem may reside in one (or more) of the directives used in the 3G Blacklist. I am currently not blocking any types of proxy requests, but the 3G Blacklist does contain rules that may be interfering. Plus, the fact that you are getting 403 errors instead of 404s reinforces this hypothesis because the blacklist is configured to return 403s for any blocked requests.

So, if you can get ahold of a few of the proxy requests used by the ISA server (i.e., the general format of the URLs used to request pages), I will be able to compare the requests to the various character strings blocked by the blacklist. — We can do this!! ;)

11H5N1

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 :)

12Jeff Starr

January 3, 2009 at 6:22 pm

Hey H5N1, that sounds good — remember that you can always send code directly to me via email (which is jeff at this domain). Also, the differences in browsers may be related to me testing and tweaking the next (4G) blacklist live on the site. Depending on the different times that you were posting, there may have been different rules in place. But yes, otherwise that is very strange indeed!

And likewise, a Happy New Year to you as well! :)

Subscribe to comments on this post


Share your thoughts..

TopRead official comment policy

Contact Perishable Press

  • Contact Jeff via form

Search Perishable Press

About Perishable Press

Perishable Press is the virtual playground of Jeff Starr — visionary, founder and lead developer of Monzilla Media, a small web and graphic design company in the lush desert oasis of Moses Lake, Washington. Perishable Press features articles and tutorials on many aspects of digital design..

Read more..

Perishable on Twitter

better to have too many ideas and not enough time than the converse

Perishable on Tumblr

WordPress Tip for Multiple Themes

Sunday, 4 January 2009, 5:16 pm

If your site makes available multiple themes for users to choose from, remember to include the JavaScript (or any other required code) for any statistical applications that you might be using, such as Mint, Google Analytics, and so forth. I am not sure about the various WordPress statistics plugins, but they may need to be included as well. A good way to check if your stats plugin is tracking data across all themes is to either visit a few pages that you know others aren’t hitting, or else activate each of the alternate themes and check the source code of each one for the required code.

Earlier today, I realized that only several of my most recent themes included the required JavaScript for Mint and Google Analytics. I am now in the process of editing each of the 18 themes available for users at Perishable Press. Haven’t decided on whether or not both statistics apps are needed for all themes, but I will certainly be using at least one of them to keep an eye on everything.

Insane Christmas

Monday, 22 December 2008, 9:47 pm

For as long as I can remember, Christmas has always been a relatively peaceful affair. Sure there’s the usual holiday stress — traffic, shopping, presents, relatives, and all that goes with the preparation of a traditional celebration, but when it’s all said and done, you get to relax and enjoy the peace and harmony of gathering together and basking in the reason for the season: the birth of Christ.

This year, however, the stress factor has been kicked up a few notches, making for a rather insane Christmas if I do say so myself. In addition to the usual holiday chaos, we are currently purchasing a brand new home, and quickly realizing the incredible amount of work involved in the process. If you’ve ever bought a newly built home, you know exactly what I am talking about here.

Plus, as if all the paperwork, inspections, insurance, costs, and anxious anticipation weren’t enough to confound the usual holiday stress, we are also packing up everything, dealing with kids, working full-time jobs, and — beginning on Christmas Eve — moving into our new house.

It certainly is all a great joy and blessing to have such amazing things going on, but combined with the work that I do on the Web — blogging, designing, projects, helping people, and so on — it really becomes all too much rather quickly. We are doing are best to get through everything with our sanity intact, but I have to admit that this is the most insane Christmas I have ever experienced.

New (4G) Blacklist Now in Beta

Monday, 22 December 2008, 9:27 pm

Just a quick note to anyone interested in securing their websites against malicious activity, spam, and other nonsense. Several months after releasing my 3G Blacklist, I have finally begun work on the next incarnation of the blacklist: the 4G Firewall!

The first part of the blacklist is now ready for testing, and I plan on setting it up on Perishable Press within the next few days. While testing on my own site, I thought it would beneficial to also invite a few “beta” testers to run the code on their own site(s) as well.

So, if you have a site that receives its share of malicious attacks, and cracker exploits, drop me a line via the contact form at Perishable Press and I will send you the initial block of HTAccess directives. This version of the Blacklist is looking better than ever, and I look forward to releasing the complete version to the public early in 2009.

Thanks for the Free Traffic and Link Juice

Sunday, 7 December 2008, 1:26 pm

Just wanted to thank the fine folks at fafich.ufmg.br for all the free traffic and link juice. Thanks to their misapplication of my comprehensive canonicalization code, every non-canonical version of their 21,700 indexed pages points directly to my site, Perishable Press. This means that every one of their permalink URLs that is mistyped, lacks the “www” prefix, or contains the superfluous “index.php” file name is directed via permanent redirect directly to the home page of my site.

I have tried contacting the site owner(s) about this situation, but it has been over a week and I have yet to hear anything back. Hopefully, they will take notice soon and correct the issue by properly configuring their htaccess file, but in the meantime, I certainly don’t mind the extra link juice and free traffic! :)

No Plugin Needed for Feed Delay

Monday, 24 November 2008, 10:01 am

I recently saw a WordPress plugin that was designed to delay the publication of your WordPress feed by any specified time interval. While it is a good idea to carefully proofread your content before posting it, a plugin certainly is not required to do so.

As savvy WordPress users already know, WordPress has a built-in post-preview feature that enables authors to view their unpublished content as a published post. This enables authors to do any amount of proofreading and browser checking until they are satisfied with the results.

To do this, simply write your post as usual, and then click on the “Preview this post” button on the right-hand side of the screen. In older versions of WordPress (less than 2.5, I think), you actually need to save (without publishing!) the post first and then re-open it as if to continue editing. You will then see a “Preview »” link sort of hidden (due to poor CSS design) in the upper-right corner near the edit post field. Right-click on that link to open in new tab and you are good to go.

No extra plugin needed! :)

Read more on Tumblr..

Subscribe to Comments Recent Dialogue

  • Jeff Starr: Hi heywho, glad to hear you are doing well! ;) I wish I could join in the festivities.. it has been so long that I almost have forgot...
  • Rob Barrett: Thanks for posting about the Stealth Publish plugin -- just what I needed for my site. Works perfectly!...
  • Jeff Starr: Hi Chiwan, I got your email and have sent some information that may help you with this. Cheers, Jeff...
  • Chiwan: Hi. This is cool. So I can I replace the clock that comes with your Apathy theme with this clock? If that's not possible, how do ...
  • Brass Engraved: Thankyou very much for this, worked like a dream!...
  • Patrix: I'm using FeedBurner and the Feedsmith plugin for my filter blog, DesiPundit. I found your post via the WordPress page for RSS feeds ...
  • teddY: @Jessi Hance: Sorry to hear about your experience with Twitter spammers/flamers. I was once a victim of flamers and it sucks that peo...
  • heywho: Hey.... Very Nice...... I'm TOTALLY not a programmer..... but I have this thing I want to do...... so I just decided to start doi...
  • Rodrigo Nunes: NIce SEE MY BLOG http://designrn.wordpress.com/...
  • zubfatal: The Quintessential theme looks great to me, however when scrolling up or down on the page, it makes my laptop work harder than it sho...

Read more recent comments..

Attention: Do NOT follow this link!