Skip to content

Instantly share code, notes, and snippets.

@imjjss
Created May 13, 2012 01:58
Show Gist options
  • Save imjjss/2670240 to your computer and use it in GitHub Desktop.
Save imjjss/2670240 to your computer and use it in GitHub Desktop.
only want the Admin to be able to post to.Authors not even be able to see it in the category checklist when composing a new post
<?php
// add_filter('get_terms', 'restrict_categories');
function restrict_categories($categories) {
// If we are in the new/edit post page and not an admin, then restrict the categories
$onPostPage = (strpos($_SERVER['PHP_SELF'], 'post.php') || strpos($_SERVER['PHP_SELF'], 'post-new.php'));
if (is_admin() && $onPostPage && !current_user_can('level_10')) {
$size = count($categories);
for ($i = 0; $i < $size; $i++) {
if ($categories[$i]->slug != 'site_news')
unset($categories[$i]);
}
}
return $categories;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment