Created
April 22, 2021 11:46
-
-
Save Alimir/a8523f94c8ade113ebec15ae0de90191 to your computer and use it in GitHub Desktop.
Limit user to vote per day by cookie method
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 | |
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