Forum Replies Created

Viewing 1 replies (of 1 total)
  • 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.

Viewing 1 replies (of 1 total)