Support » Plugin: Carbon Fields » carbon fields and menu edit screen

  • Resolved Dewy

    (@stardeuche)


    hi,

    I’m searching a solution for add metaboxe in the admin screen of menu wordpress

    With the carbon field plugin, i can create this metaboxes? In your documentation, i can add another metaboxe in the item of menu. but for my project, i want to put a custom metaboxe in the manage location of menu wordpress

    I want to use a custom taxonomy for my menu (each menu). With carbon field it’s possible ?

    Thanks so lot

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Atanas Angelov

    (@atanasangelovdev)

    Hi @stardeuche ,

    Currently you can add containers to menu items but not menus.

    As a work around, you can create a Theme Options page which lists all menus and dynamically creates a select field of all terms for every menu, e.g.:

    
    $fields = array();
    
    $menus = get_terms( 'nav_menu', array( 'hide_empty' => true ) );
    foreach ( $menus as $menu ) {
    	$fields[] = Field::make( 'select', 'menu_' . $menu->term_id . '_term', 'Category for "' + $menu->name + '"' )
    		->add_options( $your_menu_terms_array_here );
    }
    
    Container::make( 'theme_options', 'Menu Categories' )
    	->add_fields( $fields );
    

    NOTE: the above code is an example and has not been tested.

    Dewy

    (@stardeuche)

    Hi,

    thanks so lot for your response. With your idea, i can assign a menu with a category. But now, i want to restrict the administration wordpress by users logged. It’s my second difficuty in my works today !!

    Here my code :

    
    function spm_menu_list() {
        //retrouve les menus enregistrés dans wordpress
        //$t = get_registered_nav_menus();
        //var_dump($t);
    
        $arraySlugMenu = array('choisir un menu' => 'choisir un menu');
    
        $m = get_terms( 'nav_menu', array( 'hide_empty' => true ) );
        foreach ($m as $value) {
            $slugMenu = $value->slug;
            $arraySlugMenu[$slugMenu] = $slugMenu;
        }
        return $arraySlugMenu;
    }
    
    Container::make( 'theme_options', 'Theme Options' )
        ->add_fields(array(
            field::make('complex', 'menu')
            ->add_fields(array(
                Field::make('select', 'crb_select_menu', 'Menu')->add_options( spm_menu_list() ),
                Field::make('select', 'crb_select_menu_entite', 'Entité assignée au menu')->add_options( spm_list_entite() )
                  ))
        ));
    

    the function spm_list_entite is an array of services of the users

    it’s not in your scope, but if you have got a little idea, it will fabulous

    thanks so lot

    Plugin Contributor Atanas Angelov

    (@atanasangelovdev)

    I’m not really sure if this is what you need but you can restrict access to containers based on the current user ID, role or capabilities using this set of conditions:
    current_user_id
    current_user_role
    current_user_capability

    https://carbonfields.net/docs/containers-conditional-display/?crb_version=2-0-0
    https://carbonfields.net/docs/containers-condition-types/?crb_version=2-0-0

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘carbon fields and menu edit screen’ is closed to new replies.