0

I'm submitting comments with AJAX and then loading it on response. Long story short it all works fine except reply link isn’t being rendered on the page. As I understand, the problem is can’t pass $args to it. How would I access $args or max_depth outside the callback?

Callback function:

 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 
 }

Comment handling function (some parts are removed for brevity)

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???



}
0

It appears you can get max_depth from the options via 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);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.