Skip to content

Instantly share code, notes, and snippets.

View Alimir's full-sized avatar
👀
looking for purest...

Ali Mirzaei Alimir

👀
looking for purest...
View GitHub Profile
@Alimir
Alimir / wp-ulike-pro.php
Created April 13, 2021 11:03
A sample shortcode to display attachments recently liked by the user (Inside ulike profile panel)
<?php
function wp_ulike_custom_shortcode_attachment(){
global $wp_ulike_user_profile_id;
$post__in = wp_ulike_get_popular_items_ids(array(
'type' => 'post',
'rel_type' => 'attachment',
'status' => array( 'like', 'dislike' ),
'period' => 'all',
@Alimir
Alimir / wp-ulike.php
Created April 6, 2021 18:49
How to disable unlike method at wp ulike
<?php
add_filter( 'wp_ulike_permission_status', function( $status, $args , $settings ){
if( ! empty( $args['prev_status'] ) ){
return false;
}
return $status;
}, 10, 3 );
@Alimir
Alimir / wp-ulike.php
Last active March 27, 2021 19:25
Display wp ulike buttons only in the comments section of buddypress (Don't forget to disable auto display option inside settings panel)
<?php
/**
* Display like button inside comment options section
*/
add_action( 'bp_activity_comment_options', function(){
echo wp_ulike_buddypress('put');
}, 15 );
/**
@Alimir
Alimir / wp-ulike-pro.php
Created March 18, 2021 12:41
wp ulike count total likes and dislikes
<?php
function wp_ulike_custom_count_logs( $atts ){
// Global variable
global $wpdb;
// Default Args
$args = shortcode_atts( array(
"status" => 'like',
"type" => 'post'
@Alimir
Alimir / wp-ulike-pro.php
Created February 27, 2021 17:25
Add filter on recaptcha enqueue scripts
<?php
function wp_ulike_pro_custom_enqueue_recaptcha( $status, $target_page ){
// Set your custom pages by id, slug, or title
if( is_page( array( 42, 'about-me', 'Contact' ) ) ){
return true;
}
return false;
<?php
// Add text/html before button
add_action( 'wp_ulike_before_template', function(){
echo sprintf( '<span>%s</span>', __( 'Like me', 'wp-ulike' ) );
} );
// Add text/html after button
add_action( 'wp_ulike_after_template', function(){
@Alimir
Alimir / wp-ulike-pro.php
Last active March 4, 2021 20:20
How to add vote fields to WordPress comments API
<?php
add_action( 'rest_api_init', function () {
register_rest_field( 'comment', 'votes', array(
'get_callback' => function( $comment_arr ) {
return array(
'like_amount' => wp_ulike_get_comment_likes( $comment_arr['id'], 'like' ),
'dislike_amount' => wp_ulike_get_comment_likes( $comment_arr['id'], 'dislike' ),
'likers_list' => wp_ulike_get_likers_list_per_post( 'ulike_comments', 'comment_id', $comment_arr['id'], NULL )
);
@Alimir
Alimir / wp-ulike-pro.php
Created January 28, 2021 07:34
Add new inputs to wp ulike edit profile forms
<?php
/**
* Process submitted form args
*
* @param array $args
* @return void
*/
function wp_ulike_pro_custom_after_profile_process( $args ){
// Get current user id
@Alimir
Alimir / wp-ulike.php
Created December 30, 2020 14:20
Display like button on custom activity group
<?php
function wp_ulike_custom_bp_activity_entry_content() {
global $activities_template;
if( ! empty( $activities_template->activity->component ) && $activities_template->activity->component === 'groups' ){
if( ! empty( $activities_template->activity->item_id ) && in_array( $activities_template->activity->item_id, array( '1' ) ) ){
echo wp_ulike_buddypress('put');
}
}
@Alimir
Alimir / wp-ulike.php
Created December 20, 2020 15:20
Hide auto display on certain pages in WP ULike
<?php
function wp_ulike_custom_content_filter( $button, $content ){
if ( in_the_loop() && is_main_query() && is_page( array( 'terms-of-service', 'privacy-policy', 'contact', 'about' ) ) ){
return $content;
}
return $button;
}
add_filter( 'wp_ulike_the_content', 'wp_ulike_custom_content_filter', 2, 10 );