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.php
Created June 22, 2021 07:45
Get number of likes received by post author
<?php
function wp_ulike_custom_author_counter( $user_id, $status = 'like' ){
global $wpdb;
$meta_key = wp_ulike_setting_repo::isDistinct( 'post' ) ? 'count_distinct_' . $status : 'count_total_' . $status;
return $wpdb->get_var(
$wpdb->prepare(
"SELECT SUM(m.meta_value) FROM {$wpdb->prefix}ulike_meta m INNER JOIN $wpdb->posts p ON m.item_id = p.ID AND p.post_author = %s WHERE m.meta_group = 'post' AND m.meta_key = %s",
@Alimir
Alimir / wp-ulike-pro.php
Last active June 5, 2022 06:36
A sample shortcode to display current user pinned posts
<?php
function wp_ulike_pro_get_current_user_pinned_posts($atts){
global $post;
$attributes = shortcode_atts( array(
'post_type' => 'post',
'past_days' => '',
'per_page' => 10
), $atts );
@Alimir
Alimir / wp-ulike.php
Created June 12, 2021 15:33
How to add custom template in wp ulike
<?php
/**
* Register custom template
*
* @param array $templates
* @return array
*/
function wp_ulike_voting_register_templates( $templates ){
$templates['wpulike-custom-template'] = array(
@Alimir
Alimir / wp-ulike.php
Last active June 24, 2021 22:02
Restrict users to vote on one post per category
<?php
function wp_ulike_disable_same_category_actions( $status, $args , $settings ){
if( $args['type'] === 'post' && get_post_type( $args['item_id'] ) == 'post' ){
$user_info = wp_ulike_get_meta_data( $args['current_user'], 'user', 'post_status', true );
if( ! empty( $user_info ) ){
$category_list = array();
foreach ($user_info as $item_id => $current_status) {
if( ! empty($current_status ) && strpos( $current_status, 'un') === false && get_post_type( $item_id ) == 'post' ){
@Alimir
Alimir / wp-ulike.php
Created April 30, 2021 10:45
Restrict like/dislike based on period time for 10 days after post publish
<?php
/**
* Restrict period time for 10 days after post publish
*
* @param integer $id
* @param string $type
* @return void
*/
function wp_ulike_pro_custom_restrict_period_time( $id, $type ){
@Alimir
Alimir / wp-ulike.php
Last active April 28, 2021 19:25
Migrate counter values from LikeBtn to WP ULike
<?php
add_action( 'admin_action_migrate_likebtn_to_wp_ulike', 'migrate_likebtn_to_wp_ulike_admin_action' );
function migrate_likebtn_to_wp_ulike_admin_action(){
global $wpdb;
// Do your stuff here
if( empty( $_POST['posts'] ) && empty( $_POST['comments'] ) ){
wp_die( 'Please select an option!' );
}
@Alimir
Alimir / wp-ulike-pro.php
Last active June 27, 2022 09:07
Filter posts by like amount in elementor post widget
<?php
add_action( 'elementor/query/order_by_like_amount', function( $query ) {
// Get current meta Query
$meta_query = $query->get( 'meta_query' );
// If there is no meta query when this filter runs, it should be initialized as an empty array.
if ( ! $meta_query ) {
$meta_query = [];
}
@Alimir
Alimir / wp-ulike.php
Created April 22, 2021 11:46
Limit user to vote per day by cookie method
<?php
function wp_ulike_custom_permission_status( $status, $args, $settings ){
$cookie_key = sanitize_key( 'wp_ulike_manual_' . $args['type'] . $args['item_id'] );
$has_cookie = false;
if( isset( $_COOKIE[ $cookie_key ] ) ) {
$status = false;
$has_cookie = true;
} else {
@Alimir
Alimir / wp-ulike-pro.php
Last active April 22, 2021 11:28
Ultimate member user acitivity counter
<?php
/**
* Create shortcode: [wp_ulike_pro_um_counter]
*
* @param array $atts
*
* @return integer|string
*/
function wp_ulike_pro_get_um_counter( $atts ){
@Alimir
Alimir / wp-ulike-pro.php
Last active March 10, 2023 12:24
Add new password field inside wp ulike edit account & signup forms
<?php
/**
* Add new fields to account form
*
* @param string $type
* @param array $args
* @return void
*/
function wp_ulike_pro_customize_account_form( $type, $args ){