PHP code example of alimir / wp-ulike

1. Go to this page and download the library: Download alimir/wp-ulike library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

alimir / wp-ulike example snippets


echo do_shortcode('[wp_ulike for="post" id="1" style="wpulike-heart"]');

add_filter('wp_ulike_format_number','wp_ulike_new_format_number',10,3);
function wp_ulike_new_format_number($value, $num, $plus){
	if ($num >= 1000 && get_option('wp_ulike_format_number') == '1'):
	$value = round($num/1000, 2) . 'K';
	else:
	$value = $num;
	endif;
	return $value;
}

add_filter('wp_ulike_count_box_template', 'wp_ulike_change_my_count_box_template', 10, 2);
function wp_ulike_change_my_count_box_template($string, $counter) {
	$num = preg_replace("/[^0-9,.]/", "", $counter);
	if($num == 0) return;
	else return $string;
}

add_filter('wp_ulike_login_alert_template', 'wp_ulike_change_login_alert_template', 10);
function wp_ulike_change_login_alert_template(){
	return '<p class="alert alert-info fade in" role="alert"><button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>Please login to your account! :)</p>';
}

if (function_exists('wp_ulike_get_post_likes')):
	echo wp_ulike_get_post_likes(get_the_ID());
endif;

if (function_exists('wp_ulike_get_comment_likes')):
	echo wp_ulike_get_comment_likes(get_comment_ID());
endif;

/**
 * Get most liked posts in query
 *
 * @param integer $numberposts		The number of items
 * @param array|string $post_type	Select post type
 * @param string $method			keep this as default value (post, comment, activity, topic)
 * @param string $period			Date period (all|today|yeterday|week|month|year)
 * @param string $status			Log status (like|unlike|dislike|undislike)
 * @return WP_Post[]|int[] 			Array of post objects or post IDs.
 */
$wp_query = wp_ulike_get_most_liked_posts( 10, array( 'post' ), 'post', 'all', 'like' );

define( 'WP_MEMORY_LIMIT', '256M' );