Moving at the Speed of Creativity by Wesley Fryer

Can’t delete Akismet spam comments in latest WordPress

I’ve held my breath and crossed my fingers this evening updating the K-12 Online Conference blog from WordPress version 2.2 to the latest version 2.6.1. Everything seems to have gone smoothly (dare I say that) except when I try to delete identified Akismet spam comments I get the following error:

Warning: Invalid argument supplied for foreach() in /home/k12onlin/public_html/wp-content/plugins/akismet/akismet.php on line 731

Warning: Cannot modify header information – headers already sent by (output started at /home/k12onlin/public_html/wp-content/plugins/akismet/akismet.php:731) in /home/k12onlin/public_html/wp-includes/pluggable.php on line 770

I disabled Akismet, re-downloaded and installed it, and activated it again to no effect. I was able to delete some of the identified spam comments by activating Spam Karma, but not all of them. I’m thinking this may have something to do with permissions settings on the server running WordPress. It’s a little different than the settings to which I’m more accustomed. I viewed the sourcecode for the akismet.php file using TextWrangler (an application I dearly love and literally use every day) and looked on line 731, but the code there was an intelligible to me as Mandarin Chinese:

foreach ( $moderation as $c ) {

I did find some posts (one and two) on the WordPress forums but no resolutions for the latest Akismet (2.1.6) version. If you are a WordPress guru and have any suggestions for me I’m all ears! I am submitting this as a support request to the Akismet team.

Technorati Tags:
, , , , , , ,







8 responses to “Can’t delete Akismet spam comments in latest WordPress”

  1. Jason Avatar

    foreach iterates over an array, and what your error means is that $moderation was not an array. The second error is typically (in my experience) caused by the first. One plugin tried to edit the header (http header that is) data, however it had already been sent because the akismet plugin caused an error and that error was sent to your browser. If you got rid of the first error, the second wouldn’t occur.

    You could try a couple of things. First would be to go into your plugins folder and backup the akismet plugin and then reinstall it. The second, similar to what is described in that second post you link, would be to hack the code so as to fix the problem described there.

    I’m not so familiar with WordPress that I can hack on this without having the issue myself. Let me know if there are other questions you have, or feel free to zip your akismet.php file and email it to me and I can take a look. Good luck!

  2. Jason Avatar

    I actually do have a WordPress Installation to check out and I took a look at my copy of Akismet.php. Seems to be pretty close to yours, however I get the error on line 722. I looked into it and confirmed my understanding of what’s happening. When you have zero comments to check, the call to wpdb (which is a wrapper for ezSQL) returns false ( in the demo explained section). The code doesn’t expect this, and as I said it throws an error because instead of an array of results, it gets false.

    I fixed it by using a small check that is documented at that ezSQL page. essentially, change the line before the foreach to this:
    if($moderation = $wpdb->get_results( “SELECT * FROM $wpdb->comments WHERE comment_approved = ‘0’”, ARRAY_A )){

    and then add a } before the wp_direct(… line (which I think is 747 for you). When no comments need to be reviewed, a click on the check for spam button should essentially do nothing (redirect you back to that page with no message; not the best scenario, but better than an error). If there are results, they should get processed.

    Hope this helps.

  3. Sperge Avatar

    I get exactly the same error messages with the latest Akismet and WP 2.6.1, so it does look like a bug to me.

    When I did the upgrade, I had migrated the website to a new domain at the same time so I thought it may have had something to do with the move. But obviously that isn’t the case since you’re having the same problem.

    I’ll try Jason’s bug fix when I have a spare moment – but hopefully this is something Akismet will fix shortly anyway.

  4. Jason Avatar

    Wesley, I know you said you’re running the same stuff on some other sites with no problems. Do those sites have anything in their queue? Based on what I saw in the code, I’m sticking with my theory above (same as what you saw in the second post you linked): the bug only appears when there are no items in the queue. As long as there’s something in there, you won’t see this bug.

  5. Wesley Fryer Avatar

    Actually I have a lot of spam in the queue. Since I upgraded to WP 2.6.1 on this blog where I’m having this problem, the blog has received LOTS more spam than it was getting running version 2.2, which mystifies me– I would think the security settings would be better on the new version rather than the old in terms of spam protection. Spammers must be targeting their techniques to the latest version of WP.

    I am going to try the solution you suggested later today… But if you’re thinking this will just work when there is NOT something in the queue, then I don’t think it will work… I may also backup the DB and re-install from scratch on a sandbox server and see if that works…

  6. Jason Avatar

    It’s not that I think it will work only if there’s no spam, it’s that I thought that’s where the bug was. However, if you have a lot of spam in the queue then what I told you to do won’t fix anything, it will only seem that way… The implication is that the bug is somewhere else.

    I thought you might have had no spam, in which case you trip a bug where a database query returns false instead of an array of data. The changes I suggested above address that false return as if the query returned no results. You are implying that the lack of results is not because there is no spam, but because the query is wrong: there is spam, however you can’t select it by querying the database for all comments that have comment_approved set to zero.

    The more I think about this, the more I think we’re experiencing two different issues. I’m clicking the ‘Check For Spam’ link on the Comments page, but you’re trying to delete spam, maybe from the Akismet Spam(N) link? My wordpress install is on an intranet and I don’t get any spam there, so I don’t have any comments in the queue to test.

    I thought I could help you with a quick fix, but it seems that’s not the case. I’d not make the changes I suggested in my previous comment since it appears that hides the problem without fixing it. Sorry I couldn’t be of more help here.

  7. Wesley Fryer Avatar

    OK– thanks for the clarification… You are right, I was talking about being on the Akismet Spam page and trying to delete comments there… I do appreciate the offer to help tho. I may try to reinstall on a clean version of WP. I’m also going to reach out to James Farmer of EduBlogs who hosts the k12onlineconference site for us and see if he has ideas.