Skip to content

Instantly share code, notes, and snippets.

@Alimir
Created July 15, 2022 17:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Alimir/2f24b729be6232cc8b3c2269e46064ed to your computer and use it in GitHub Desktop.
Save Alimir/2f24b729be6232cc8b3c2269e46064ed to your computer and use it in GitHub Desktop.
wp ulike restrict user to vote x times at all
<?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