Currently we can not pass user_ID or user_role to wp_list_category()
function, So it is not possible unless you use filter to do this, that is bit complicated so here I has a solution that does exact what you want without using filter.
<?php
if ( current_user_can( 'manage_options' ) ) {
/* A user with admin privileges */
wp_list_categories(); ?
} else {
/* A user without admin privileges */
wp_list_categories('exclude=4'); // 4 is id of category you'd like to hide
}
?>
Update –
I think using the get_category()
function will be good idea, First grab all the categories as array and then show them as required.
<?php
$categories = get_categories();
if(!current_user_can( 'manage_options' )) {
$exclude = 4; // category ID to hide from non admin
} else {
$exclude="";
}
foreach ( $categories as $cat ) {
if($cat->term_id != $exclude) {
echo '<li>'.$cat->name.'</li>';
}
}
?>