wordpress批量关闭文章的评论功能

mysql> SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';

mysql> alter table wp_posts alter column comment_status set default 'closed';

mysql> SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';

mysql> update wp_posts set comment_status='closed' where comment_status='open' and post_type='post' and post_status='publish';

mysql> CREATE DEFINER = root EVENT `blog`.`DIS_POSTS_COMMENT` ON SCHEDULE EVERY '5' SECOND COMMENT '关闭文章评论功能' DO update wp_posts set comment_status='closed' where comment_status='open' and post_type='post' and post_status='publish';

执行的这几条 MySQL 命令,核心目的是先调整 SQL 模式,再修改 wp_posts 表中 comment_status 字段的默认值为 closed,最后将该表中所有 post_typepostcomment_statusopen 的记录,统一把 comment_status 更新为 closed(也就是关闭文章的评论功能),再创建一个定时事件,每隔 5 秒自动将新发布的、评论处于开启状态的文章评论关闭。

Categories: 系统运维