ap_answer_post_ajax_response( integer|object $question_id, integer|object $answer_id )
Description #
Send ajax response after posting an answer.
Parameters #
- $question_idinteger | object (Required) Question ID or object.
- $answer_idinteger | object (Required) Answer ID or object.
Source #
File: includes/functions.php
function ap_answer_post_ajax_response( $question_id, $answer_id ) {
$question = ap_get_post( $question_id );
// Get existing answer count.
$current_ans = ap_count_published_answers( $question_id );
global $post;
$post = ap_get_post( $answer_id ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
setup_postdata( $post );
ob_start();
global $withcomments;
$withcomments = true; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
ap_get_template_part( 'answer' );
$html = ob_get_clean();
// translators: %d is answer count.
$count_label = sprintf( _n( '%d Answer', '%d Answers', $current_ans, 'anspress-question-answer' ), $current_ans );
$result = array(
'success' => true,
'ID' => $answer_id,
'form' => 'answer',
'div_id' => '#post-' . get_the_ID(),
'can_answer' => ap_user_can_answer( $post->ID ),
'html' => $html,
'snackbar' => array( 'message' => __( 'Answer submitted successfully', 'anspress-question-answer' ) ),
'answersCount' => array(
'text' => $count_label,
'number' => $current_ans,
),
);
ap_ajax_json( $result );
}
Expand full source code Collapse full source code View on GitHub: includes/functions.php:2136
Add your comment