评论不在Wordpress上发布 - 空白页

时间:2017-06-27 06:19:36

标签: php mysql wordpress

我正在制作一个主题(http://lillykauffman.com/wordpress/2017/06/26/hello-world/),我以前做过,但如果您尝试发表评论,您将被重定向到空白页面。这也发生在其他WP主题上,例如twentysixteen。这是我在wp-comments-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,所以这不应该是问题,但在这一点上,我甚至不知道什么是错的 - 代码,安装,我的托管。任何帮助将不胜感激。

更新:我的主持人宣传了完整的博客,评论和讨论区功能,但我联系了他们,他们就像是“不是真的”。显然他们不支持评论或电子邮件发送。多么浪费。谢谢大家的帮助!

1 个答案:

答案 0 :(得分:1)

当您使用检查管理器查看问题页面时,您可以看到您的问题是410代码错误。 410 error image

  

410 Gone

     

表示请求的资源在服务器上不再可用,并且不再可用。

此错误可能以多种方式发生。

这是帮助您找到问题的某些检查点列表:

1。 在wp-config.php中启用调试

     // Enable WP_DEBUG mode
     define( 'WP_DEBUG', true );

     // Enable Debug logging to the /wp-content/debug.log file
     define( 'WP_DEBUG_LOG', true );

     // Enable display of errors and warnings 
     define( 'WP_DEBUG_DISPLAY', true );
     @ini_set( 'display_errors', 1 );

测试以确定您的错误是否出现。您可以快速修复它。

2。 重置固定链接

不知道为什么,但有时候,Wordpress会对旧的永久链接产生一些奇怪的错误。

我建议你

  • 转到Settings -> Permalinks
  • 切换固定链接设置,
  • 保存,
  • 将其替换为您当前的配置
  • 再次保存。

3. 停用所有插件。

如果有效,可以逐个激活插件,以便能够检测出哪一个创建了这个错误。

4. 刷新.htaccess

放置基本的wordpress .htaccess。有时,某些插件会更改.htaccess中的规则并引发许多重定向错误。

5. 将主题切换为默认主题而不进行修改

它可以帮助您了解主题中的自定义规则是否会产生此错误。

6. 从全新安装中重新上传wp-admin和wp-includes

7. 重置文件夹写入/读取权限

您可以阅读Changing File permissions in Wordpress,以帮助您了解应该更改的内容以及应该做的事情。

8。 ULTIMATELY,全新安装Wordpress