platypus2308
Member
Posted 5 months ago #
Hi ,
I'm using Restrict Category on post author and it's wroking just fine.
i would like to use it also on contributor ( my contributors don't publish post , they only comment them ) and let them comment post only if they have at least one corresponding categories with the post.
i found where to filter comment form but i'd like to know if there's an easy way to get categories from the current user to compare with the post categories ?
Any idea appreciated !
platypus2308
Member
Posted 5 months ago #
for those who minds, i found a solution :
here's the code i use just before the comment form display :
$allowed = false;
$rco = get_option( 'RestrictCats_user_options' );
$cu = wp_get_current_user();
$cats = get_the_category();
if(!is_null($rco[$cu->user_login.'_user_cats']))
{
foreach($rco[$cu->user_login.'_user_cats'] as $user_cat)
{
foreach( $cats as $cat)
{
if($cat->slug==$user_cat)$allowed = true;
}
}
}
else $allowed = true;
Regards,