ap_subscribe_btn( object|integer|false $_post = false, boolean $output = true )

Description #

Output question subscribe button.

Parameters #

  • $_post
    object | integer | false (Optional) Post object or ID. Default value: false
  • $output
    boolean (Optional) Echo or return. Default value: true

Source #

File: includes/theme.php

function ap_subscribe_btn( $_post = false, $output = true ) {
	$_post = ap_get_post( $_post );

	$args        = wp_json_encode(
		array(
			'__nonce' => wp_create_nonce( 'subscribe_' . $_post->ID ),
			'id'      => $_post->ID,
		)
	);
	$subscribers = (int) ap_get_post_field( 'subscribers', $_post );
	$subscribed  = ap_is_user_subscriber( 'question', $_post->ID );
	$label       = $subscribed ? __( 'Unsubscribe', 'anspress-question-answer' ) : __( 'Subscribe', 'anspress-question-answer' );

	$html = '<a href="#" class="ap-btn ap-btn-subscribe ap-btn-small ' . ( $subscribed ? 'active' : '' ) . '" apsubscribe apquery="' . esc_js( $args ) . '"><span class="apsubscribers-title">' . esc_html( $label ) . '</span><span class="apsubscribers-count">' . esc_html( $subscribers ) . '</span></a>';

	if ( ! $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