ap_new_comment_btn( integer $post_id, boolean $output = true )

Description #

Return or print new comment button.

Parameters #

  • $post_id
    integer (Required) Post id.
  • $output
    boolean (Optional) Return or echo. Default is echo. Default value: true

Changelog #

VersionDescription
4.1.8Introduced.

Source #

File: includes/comments.php

function ap_new_comment_btn( $post_id, $output = true ) {
	if ( ap_user_can_comment( $post_id ) ) {
		$html = '';

		$btn_args = wp_json_encode(
			array(
				'action'  => 'comment_modal',
				'post_id' => $post_id,
				'__nonce' => wp_create_nonce( 'new_comment_' . $post_id ),
			)
		);

		$html .= '<a href="#" class="ap-btn-newcomment" aponce="false" apajaxbtn apquery="' . esc_js( $btn_args ) . '">';
		$html .= esc_attr__( 'Add a Comment', 'anspress-question-answer' );
		$html .= '</a>';

		if ( false === $output ) {
			return $html;
		}

		echo $html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
	}
}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment