Skip to content

Instantly share code, notes, and snippets.

@Clorith
Created January 8, 2014 12:20
Show Gist options
  • Save Clorith/8316016 to your computer and use it in GitHub Desktop.
Save Clorith/8316016 to your computer and use it in GitHub Desktop.
<?php
function exclude_cats() {
if( ! current_user_can( 'manage_options' ) ) {
add_filter( 'list_terms_exclusions', 'exclude_args', 10, 2 );
}
}
function exclude_args( $exclusions, $args ) {
$current_user = wp_get_current_user();
if ( strpos( $current_user->adi_title, 'Support' ) !== false ) {
$parentcat = 26;
} elseif ( strpos( $current_user->adi_title, 'Sales' ) !== false ) {
$parentcat = 27;
}
if ( ! isset( $parentcat ) )
return true;
$included[] = $parentcat;
$children = get_categories( array( 'child_if' => $parentcat ) );
foreach( $children AS $singlechild ) {
$included[] = $singlechild->cat_ID;
}
return $exclusions . " AND ( t.term_id IN ( " . implode( ",", $included ) . " ) )";
}
add_action( 'admin_init', 'exclude_cats' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment