ap_subscribe_btn( object|integer|false $_post = false, boolean $output = true )
Description #
Output question subscribe button.
Parameters #
- $_postobject | integer | false (Optional) Post object or ID. Default value: false
- $outputboolean (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
}
Expand full source code Collapse full source code View on GitHub: includes/theme.php:945
Add your comment