Last active
June 24, 2021 22:02
-
-
Save Alimir/4c0b299a721debfba38e87bb2ed5b0ed to your computer and use it in GitHub Desktop.
Restrict users to vote on one post per category
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_disable_same_category_actions( $status, $args , $settings ){ | |
if( $args['type'] === 'post' && get_post_type( $args['item_id'] ) == 'post' ){ | |
$user_info = wp_ulike_get_meta_data( $args['current_user'], 'user', 'post_status', true ); | |
if( ! empty( $user_info ) ){ | |
$category_list = array(); | |
foreach ($user_info as $item_id => $current_status) { | |
if( ! empty($current_status ) && strpos( $current_status, 'un') === false && get_post_type( $item_id ) == 'post' ){ | |
$categories = get_the_category( $item_id ); | |
if ( ! empty( $categories ) ) { | |
foreach( $categories as $term ) { | |
$category_list[] = $term->term_id; | |
} | |
} | |
} | |
} | |
if( ! empty( $category_list ) ){ | |
$current_category = get_the_category( $args['item_id'] ); | |
if ( ! empty( $current_category ) ) { | |
foreach( $current_category as $current_term ) { | |
if( in_array( $current_term->term_id, $category_list ) ){ | |
return false; | |
} | |
} | |
} | |
} | |
} | |
} | |
return $status; | |
} | |
add_filter( 'wp_ulike_permission_status', 'wp_ulike_disable_same_category_actions', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment