Last active
August 8, 2022 16:52
-
-
Save Alimir/95cb33c6eb876c6fecf9905db55e5790 to your computer and use it in GitHub Desktop.
wp ulike vote only 1 post per day
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 | |
/** | |
* vote only for 1 post per day | |
*/ | |
add_filter( 'wp_ulike_permission_status', function( $status, $args , $settings ){ | |
if( $args['type'] == 'post' && ! empty( $args['current_status'] ) && strpos( $args['current_status'], 'un') === false ){ | |
// if cookie has been set | |
if( isset( $_COOKIE['wphs'] ) && $args['item_id'] != $_COOKIE['wphs'] ){ | |
return false; | |
} else { | |
setcookie('wphs', $args['item_id'], time() + 86400, '/', COOKIE_DOMAIN, is_ssl(), true ); | |
} | |
} | |
return $status; | |
}, 10, 3 ); | |
add_filter( 'wp_ulike_user_prev_status', function( $status, $args ){ | |
if( $args['item_type'] == 'post' ){ | |
// if cookie has been set | |
if( isset( $_COOKIE['wphs'] ) && $args['item_id'] == $_COOKIE['wphs'] ){ | |
return $status; | |
} | |
} | |
return false; | |
}, 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment