This tag is a “Template Tag” and not one “admin function”. Until I tried uses it, but it does not function. One presents in <“ul”> and to another one in dropdown. E still thus the parameters are different.
I am creating new pages as post-new.php/edit-form-advanced.php.
What I want is to restrict categories, showing the children of the category mother “X”. To post.
Get it?
Hey ezeuielzc:
I had a similar goal; I wanted to restrict access to categories based on the user’s role. This is how I did it:
1. In /wp-admin/includes/template.php –
I replaced this line:
$cats = get_categories("parent=$parent&hide_empty=0&fields=ids");
With this:
if (!$parent) {
$cats = get_categories("parent=$parent&hide_empty=0&fields=ids");
} else {
$cats = get_categories("child_of=$parent&hide_empty=0&fields=ids");
}
2. /wp-admin/includes/template.php –
I replaced this function:
function dropdown_categories( $default = 0 ) {
write_nested_categories( get_nested_categories( $default) );
}
With this function:
function dropdown_categories( $default = 0, $parent = 0 ) {
write_nested_categories( get_nested_categories( $default, $parent) );
}
3. /wp-admin/edit-form-advanced.php –
I replaced this line:
<ul id="categorychecklist"><?php dropdown_categories(); ?></ul></div>
With this line:
<ul id="categorychecklist"><?php if ( !current_user_can('manage_categories') ) { dropdown_categories(0,5); } else { dropdown_categories();} ?></ul></div>
5 – being my category ID which I wanted only the child of.
I used !current_user_can to control when this would be called. Currently child_of 5 is only called when the user is no admin or editor.
* – If there is a new update this will most likely be overwritten.
smalps, looks easy, one small problem thou.. can’t find that /wp-admin/includes/template.php you’re talking about.
in my wp-admin i only have the images and import directories and the rest of css, js and phps… no includes nor template.php.
i desperately want to restrict access to categories based on the user’s role, so plizzzzz help me find the .php i’m looking for 😀