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.
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
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