WordPress Disable comments on attachments

摘要: After stopped and cleaned the WordPress pingback and trackback spams, those spammers have changed strategy to start spamming comments and trackbacks on the post attachments.

After stopped and cleaned the WordPress pingback and trackback spams, those spammers have changed strategy to start spamming comments and trackbacks on the post attachments.

Solution

1.1 Stop commenting on new and existing attachment. Add below PHP script in theme’s function.php

${theme_folder}/function.php
//disable comments on attachment
function filter_media_comment_status( $open, $post_id ) {
    $post = get_post( $post_id );
    if( $post->post_type == 'attachment' ) {
        return false;
    return $open;
add_filter('comments_open', 'filter_media_comment_status', 10 , 2 );

1.2 Update existing attachments, in wp_posts table, update post attachment ping_status and comment_status to closed

phpMyAdmin or MySQL consoles
UPDATE wp_posts SET ping_status='closed' WHERE post_type = 'attachment';
UPDATE wp_posts SET comment_status='closed' WHERE post_type = 'attachment';

1.3 Delete the existing comment spam. The attachment comments are indicated as trackback comments.

DELETE FROM  `wp_comments` WHERE  `comment_type` =  'trackback'
Note
WordPress should really consider turning off the pingback and trackback features by default, it is attracting many spammers and add less value to the WordPress platform. Btw, who is using trackback?

References

  1. How to Stop WordPress Pingbacks and Trackbacks Spam
  2. WordPress Post Types

上一篇: Spring Boot + Spring Data JPA + Oracle example
下一篇: Spring Boot JDBC + Oracle database + Commons DBCP2 example
 评论 ( What Do You Think )
名称
邮箱
网址
评论
验证
   
 

 


  • 微信公众号

  • 我的微信

站点声明:

1、一号门博客CMS,由Python, MySQL, Nginx, Wsgi 强力驱动

2、部分文章或者资源来源于互联网, 有时候很难判断是否侵权, 若有侵权, 请联系邮箱:summer@yihaomen.com, 同时欢迎大家注册用户,主动发布无版权争议的 文章/资源.

3、鄂ICP备14001754号-3, 鄂公网安备 42280202422812号