【发布时间】:2017-06-28 21:13:03
【问题描述】:
我正在研究一个主题 (http://lillykauffman.com/wordpress/2017/06/26/hello-world/),我以前做过,但是如果您尝试发表评论,您将被重定向到一个空白页面。这也发生在其他 WP 主题上,例如二十六。这是我在 wp-cmets-post.php 上的代码:
<?php
/**
* Handles Comment Post to WordPress and prevents duplicate comment posting.
*
* @package WordPress
*/
if ( 'POST' != $_SERVER['REQUEST_METHOD'] ) {
$protocol = $_SERVER['SERVER_PROTOCOL'];
if ( ! in_array( $protocol, array( 'HTTP/1.1', 'HTTP/2', 'HTTP/2.0' ) ) ) {
$protocol = 'HTTP/1.0';
}
header('Allow: POST');
header("$protocol 405 Method Not Allowed");
header('Content-Type: text/plain');
exit;
}
/** Sets up the WordPress Environment. */
require( dirname(__FILE__) . '/wp-load.php' );
nocache_headers();
$comment = wp_handle_comment_submission( wp_unslash( $_POST ) );
if ( is_wp_error( $comment ) ) {
$data = intval( $comment->get_error_data() );
if ( ! empty( $data ) ) {
wp_die( '<p>' . $comment->get_error_message() . '</p>', __( 'Comment Submission Failure' ), array( 'response' => $data, 'back_link' => true ) );
} else {
exit;
}
}
$user = wp_get_current_user();
/**
* Perform other actions when comment cookies are set.
*
* @since 3.4.0
*
* @param WP_Comment $comment Comment object.
* @param WP_User $user User object. The user may not exist.
*/
do_action( 'set_comment_cookies', $comment, $user );
$location = empty( $_POST['redirect_to'] ) ? get_comment_link( $comment ) :
$_POST['redirect_to'] . '#comment-' . $comment->comment_ID;
/**
* Filters the location URI to send the commenter after posting.
*
* @since 2.0.5
*
* @param string $location The 'redirect_to' URI sent via $_POST.
* @param WP_Comment $comment Comment object.
*/
$location = apply_filters( 'comment_post_redirect', $location, $comment );
wp_safe_redirect( $location );
exit;
我不知道为什么这不起作用,因为它是直接来自 WP 的,而其他网上的人也有这个错误,因为他们的文件是空白的,这不是我的情况。所有这些代码看起来都是有序的。我的 MySQL 版本是 5.7,所以这不应该是问题,但在这一点上,我什至不知道出了什么问题——代码、安装、我的主机。任何帮助将不胜感激。
更新:我的主持人宣传完整的博客、评论和讨论区功能,但我联系了他们,他们说,“不是真的”。显然他们不支持 cmets 或电子邮件发送。多么浪费。感谢大家的帮助!
【问题讨论】:
-
网站返回 HTTP 410 状态码 (401 Gone) 这通常与
.htaccess有关,您能帮我们发一下吗? -
检查 PHP 错误日志,看看是否有什么奇怪的地方。你会被重定向到哪里?
-
@FMashiro
# BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase /wordpress/ RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /wordpress/index.php [L] </IfModule> # END WordPress -
@Capsule 我被重定向到 wp-cmets-post.php,但它是空白页。当我从前端查看它时甚至有一个空白源,所以它可能没有正确加载?此外,我找不到主机的 PHP 错误日志,很遗憾,我可能无法使用它。
-
@Lilly 如果您将最后的重写规则设为:
RewriteRule . /index.php [L]?