【问题标题】:Comments Not Posting on Wordpress - Blank Page评论未在 Wordpress 上发布 - 空白页
【发布时间】: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 &lt;IfModule mod_rewrite.c&gt; RewriteEngine On RewriteBase /wordpress/ RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /wordpress/index.php [L] &lt;/IfModule&gt; # END WordPress
  • @Capsule 我被重定向到 wp-cmets-post.php,但它是空白页。当我从前端查看它时甚至有一个空白源,所以它可能没有正确加载?此外,我找不到主机的 PHP 错误日志,很遗憾,我可能无法使用它。
  • @Lilly 如果您将最后的重写规则设为:RewriteRule . /index.php [L]

标签: php mysql wordpress


【解决方案1】:

当您使用检查管理器查看问题页面时,您会发现您的问题是 410 代码错误。

410 消失

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

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

这里是一些检查点列表,可帮助您找到问题:

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 -&gt; Permalinks
  • 切换永久链接设置,
  • 保存,
  • 将其替换为您当前的配置,
  • 再次保存。

3. 停用所有插件。

如果有效,请一一激活插件,以便能够检测出是哪一个造成了此错误。

4. 刷新您的 .htaccess

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

5. 无需修改即可将您的主题切换为默认主题

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

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

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

您可以阅读Changing File permissions in Wordpress 以帮助您了解应该更改什么以及应该做什么。

8. 最终,创建全新安装的 Wordpress

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多