使用comment\u post\u redirect WordPress筛选器重定向会导致错误

使用comment\u post\u redirect WordPress筛选器重定向会导致错误,wordpress,redirect,internal-server-error,server-error,Wordpress,Redirect,Internal Server Error,Server Error,我正在使用comment\u post\u redirect过滤器在提交评论后将用户重定向到自定义页面。代码可以正常工作,但有时用户不会被重定向,他们会收到一个错误。 这是我的密码: function feedback_submitted_redirect( $location, $comment ) { $location = get_site_url() . '/feedback-validation?commentid=' . $comment->comment_ID;

我正在使用
comment\u post\u redirect
过滤器在提交评论后将用户重定向到自定义页面。代码可以正常工作,但有时用户不会被重定向,他们会收到一个错误。

这是我的密码:

function feedback_submitted_redirect( $location, $comment )
{
    $location = get_site_url() . '/feedback-validation?commentid=' . $comment->comment_ID;
    if_debug_logger( 'Redirecting to feedback validation', array('comment_id' => $comment->comment_ID, 'comment_author' => $comment->comment_author, 'url' => $location) );
    return $location;
}
add_filter( 'comment_post_redirect', 'feedback_submitted_redirect', 11,2 );
从用户那里获得任何关于到底发生了什么的有用反馈几乎是不可能的,我无法在dev和live站点上复制这个问题,这使得修复这个问题变得更加困难。debug.log或public_html文件夹中的日志中也没有错误。

在将一些调试信息添加到日志中后,我可以看到重定向功能始终运行,但偶尔用户不会到达重定向页面。

我相信他们得到的错误是500服务器错误,因为其中一个用户说这是一个“内部服务器错误”(尽管我认为这会记录在错误日志中)。这让我觉得重定向可能花了太长时间,而且被切断了

我看不到代码中的任何内容,尽管这可能会导致问题。我只是返回一个新位置。

关于什么会导致这里出现问题,有什么想法吗?我试图寻找可能的原因,但似乎没有一个是相关的。

是否有可能第二个参数
($comment)
未设置,因此在尝试访问其属性时导致问题?我将向函数添加一些检查,以防万一,但我想不出任何可能的情况,在注释插入数据库后运行过滤器时,
$comment
不会被设置:

function feedback_submitted_redirect( $location, $comment )
{
    if( isset( $comment ) && !empty( $comment->$comment_ID ) ) {
        $location = get_site_url() . '/feedback-validation?commentid=' . $comment->comment_ID;
        if_debug_logger( 'Redirecting to feedback validation', array('comment_id' => $comment->comment_ID, 'comment_author' => $comment->comment_author, 'url' => $location) );
    }else{
        if_debug_logger( 'Redirection to feedback failed', array( 'url' => $location ) );
    }

    return $location;
}
add_filter( 'comment_post_redirect', 'feedback_submitted_redirect', 10,2 );
是不是有一些内容被输出到某个地方,导致了“Headers ready sent”错误?或者服务器可能内存不足


我想我只是想找出任何可能的原因,这样我就可以测试它们,并希望找到问题的根源。不幸的是,正如你所提到的,情况确实如此。难以置信地很难…当用户出现错误时进行诊断不幸的是,正如您所提到的,情况确实如此。难以置信地当收到错误的用户离开时,很难诊断