Created
July 15, 2022 17:14
-
-
Save Alimir/2f24b729be6232cc8b3c2269e46064ed to your computer and use it in GitHub Desktop.
wp ulike restrict user to vote x times at all
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'wp_ulike_permission_status', function( $status, $args , $settings ){ | |
$limit = 3; | |
if( $args['type'] == 'post' && ! empty( $args['current_status'] ) && strpos( $args['current_status'], 'un') === false ){ | |
global $wpdb; | |
$query = sprintf( " | |
SELECT COUNT(*) | |
FROM %s | |
WHERE user_id = %d AND status NOT LIKE '%s'", | |
esc_sql( $wpdb->prefix . 'ulike' ), | |
esc_sql( $args['current_user'] ), | |
'un%' | |
); | |
if( $wpdb->get_var( $query ) >= $limit ){ | |
return false; | |
} | |
} | |
return $status; | |
}, 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment