<?php dropdown_categories('arguments'); ?> (admin function) (7 posts)

  1. ezequielzc
    Posted 8 years ago #

    First, sorry. This text was translated of the Portuguese for English in the Google.
    My doubt is the following one:
    The function dropdown_categories() does not allow to add arguments as child_of.
    That is, dropdown_categories(“child_of=4”).
    Argument found in the function wp_list_categories.
    Has some form of I to obtain to modify this function dropdown_categories to use the attribute child_of? It would thank the aid very.

  2. MichaelH
    Posted 8 years ago #

  3. ezequielzc
    Posted 8 years ago #

    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.

  4. ezequielzc
    Posted 8 years ago #

    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?

  5. ezequielzc
    Posted 8 years ago #

    ?! :,|

  6. smalps
    Posted 8 years ago #

    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.

  7. raduma
    Posted 7 years ago #

    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 :D

Topic Closed

This topic has been closed to new replies.

About this Topic