Skip to content

Instantly share code, notes, and snippets.

@Alimir
Created April 22, 2021 11:46
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/a8523f94c8ade113ebec15ae0de90191 to your computer and use it in GitHub Desktop.
Save Alimir/a8523f94c8ade113ebec15ae0de90191 to your computer and use it in GitHub Desktop.
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 {
$status = true;
}
if( ! $has_cookie && $args['method'] === 'process' ){
\setcookie( $cookie_key, "on", time()+86400, '/' );
}
return $status;
}
add_filter( 'wp_ulike_permission_status', 'wp_ulike_custom_permission_status', 20, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment