WordPress移动wp-comments-post文件防垃圾评论

将wp-comments-post文件移动到主题目录中达到阻止垃圾评论。

需要修改程序文件:

一、首先打开Wordpress程序根目录的wp-comments-pos.php文件,用:

require( dirname(__FILE__) . '/../../../wp-load.php' );

替换第16行的:

require( dirname(__FILE__) . '/wp-load.php' );

之后,将 wp-comments-pos.php 文件移动到当前主题目录中。

二、再打开wordpress程序wp-includes目录的comment-template.php文件,用:

<form action="<?php bloginfo('template_url'); ?>/wp-comments-post.php" method="post" id="<?php echo esc_attr( $args['id_form'] ); ?>" class="comment-form"<?php echo $html5 ? ' novalidate' : ''; ?>>

替换第2046行的:

<form action="<?php echo site_url( '/wp-comments-post.php' ); ?>" method="post" id="<?php echo esc_attr( $args['id_form'] ); ?>" class="comment-form"<?php echo $html5 ? ' novalidate' : ''; ?>>

三、如果主题使用的非WP标准表单函数,可以略过第二步,用:

<form action="<?php bloginfo('template_url'); ?>/wp-comments-post.php" method="post" id="commentform">

替换类似:

<form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform">

注:WP标准表单函数为

<?php comment_form(); ?>

另外,最好将wp-comments-pos.php文件也重新命名,并到后台讨论设置中设置评论超过个2超链接,移动到等审核中。

Related Posts