0 ' . esc_html__( 'Likes', 'mwt' ) . '';
}
if ( $count == 1 ) {
$html = '1 ' . esc_html__( 'Like', 'mwt' ) . '';
}
if ( $count > 1 ) {
$html = '' . $count . ' ' . esc_html__( 'Likes', 'mwt' ) . '';
}
}
return $html;
} //mwt_print_post_likes()
endif;
if ( ! function_exists( 'mwt_post_likes_scripts' ) ) :
// Add the JS
function mwt_post_likes_scripts() {
wp_enqueue_script( 'post-likes', plugin_dir_url(__FILE__) . '/static/js/mod-post-likes.js', array( 'jquery' ), '1.0.0', true );
wp_localize_script( 'post-likes', 'MyAjax', array(
// URL to wp-admin/admin-ajax.php to process the request
'ajaxurl' => admin_url( 'admin-ajax.php' ),
// generate a nonce with a unique ID "myajax-post-comment-nonce"
// so that you can check it later when an AJAX request is sent
'security' => wp_create_nonce( 'increment-post-likes' )//,
//'post_id' => get_the_ID()
) );
} //mwt_post_likes_scripts()
endif;
add_action( 'wp_enqueue_scripts', 'mwt_post_likes_scripts' );
if ( ! function_exists( 'mwt_inc_post_like_callback' ) ) :
// The function that handles the AJAX request
function mwt_inc_post_like_callback() {
check_ajax_referer( 'increment-post-likes', 'security' );
$pID = intval( $_POST['pID'] );
mwt_set_post_likes( $pID );
echo mwt_print_post_likes( mwt_get_post_likes( $pID ) );
die(); // this is required to return a proper result
} //mwt_inc_post_like_callback()
endif;
add_action( 'wp_ajax_add_like', 'mwt_inc_post_like_callback' );
add_action( 'wp_ajax_nopriv_add_like', 'mwt_inc_post_like_callback' );
if ( ! function_exists( 'mwt_post_like_button' ) ) :
/**
* Print like button
*/
function mwt_post_like_button( $postID ) {
$output = '';
if ( empty( $_COOKIE["$postID"] ) ) {
if ( is_single() ) {
$output = '';
} else {
$output = '';
}
} else {
$output = '';
}
echo apply_filters( 'mwt_like_button', $output );
} //mwt_post_like_button()
endif;
add_action( 'mwt_post_meta', 'mwt_post_like_button', 10, 1 );
if ( ! function_exists( 'mwt_post_like_count' ) ) :
/**
* Print like counter value
*/
function mwt_post_like_count( $postID ) {
echo apply_filters( 'mwt_like_count', '' . mwt_print_post_likes( mwt_get_post_likes( $postID ) ) . '' );
} //mwt_post_like_count()
endif;
add_action( 'mwt_post_meta', 'mwt_post_like_count', 20, 1 );