此插件提供过滤器,以按元值管理菜单项:
function custom_menu_item_visibility( $visible, $item ){
if( isset( $item->roles ) ){
$user_id = get_current_user_id();
$user_meta = get_user_meta( $user_id, \'your-meta-key\', true );
if ( /* your condition */ ){
$visible = true;
} else {
$visible = false;
}
}
return $visible;
}
add_filter( \'nav_menu_roles_item_visibility\', \'custom_menu_item_visibility\', 10, 2 );