Skip to content

Instantly share code, notes, and snippets.

@Alimir
Last active August 8, 2022 16:52
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/95cb33c6eb876c6fecf9905db55e5790 to your computer and use it in GitHub Desktop.
Save Alimir/95cb33c6eb876c6fecf9905db55e5790 to your computer and use it in GitHub Desktop.
wp ulike vote only 1 post per day
<?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