我用AJAX提交评论,然后将其加载到响应中。长话短说,除了页面上没有呈现回复链接外,一切正常。据我所知,问题是不能通过$args
对它。如何访问$args
或max_depth
在回调之外?
回调函数:
function prefix_format_comment( $comment, $args, $depth ) {
$GLOBALS[\'comment\'] = $comment;
?>
<div class="comment" id="comment-<?php echo $comment->ID; ?>"
...Comment code – not published here for brevity...
<?php comment_reply_link( array_merge( $args, array(
\'reply_text\' => \'Reply\'
\'depth\' => $depth,
\'max_depth\' => $args[\'max_depth\']
) ) ); ?>
</div>
<?php
}
注释处理功能(为了简洁起见,删除了一些部分)
function prefix_submit_ajax_comment(){
$comment = wp_handle_comment_submission( wp_unslash( $_POST ) );
...handle errors and get $comment_depth...
$GLOBALS[\'comment\'] = $comment;
$GLOBALS[\'comment_depth\'] = $comment_depth;
op_format_comment($comment, $args, $comment_depth); // how to pass args here???
}
最合适的回答,由SO网友:Runnick 整理而成
看来你可以max_depth
通过选项get_option(\'thread_comments_depth\')
:
function prefix_submit_ajax_comment(){
$comment = wp_handle_comment_submission( wp_unslash( $_POST ) );
...handle errors and get $comment_depth...
$GLOBALS[\'comment\'] = $comment;
$GLOBALS[\'comment_depth\'] = $comment_depth;
$args[\'max_depth\'] = get_option( \'thread_comments_depth\' ); // solution
op_format_comment($comment, $args, $comment_depth);
}