You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, if one tab is assigned a parent, then its parent is assigned a default/general sub tab. This is fine for a parent with children, however, this one child will automatically assign all other non-parent tabs their own default general tab:
Tab1
- General
Tab2
- General
- Sub1 <- assigning Sub1 to have Tab2 as parent causes all other tabs to prepare for parenthood
Tab3
-General
After digging around a bit, I found that there is a sweet wp_user_profiles_admin_show_subnav filter that controls the showing of subnavs (sub tabs).
This is the rather convoluted way I am using this to only show subnavs on tabs that are assigned as parent (and their children, of course):
var $sub_nav_screens = []; // Create an array to hold our family-friendly tabs
add_filter( 'wp_user_profiles_admin_show_subnav', 'sub_tab_o_matic'), 10);
function sub_tab_o_matic( $retval ){
global $sub_nav_screens;
// Once is enough, thank you very much
if(!empty($sub_nav_screens)){
// Make sure we have access to the wp_user_profiles_sections function before using it
if(!function_exists('wp_user_profiles_sections')){
// nope, bail
return $retval;
}
// Grab all the defined sections
$sections = wp_user_profiles_sections();
foreach($sections as $tab){
if(!empty($tab->parent)){
// Assign the children to our array
$sub_nav_screens[] = $tab->slug;
// Assign the parent to our array if not already present
if( !in_array( $tab->parent, $sub_nav_screens ) ){
$sub_nav_screens[] = $tab->parent;
}
}
}
}
// The current screen
$screen = get_current_screen();
// Loop each family member in our array
foreach( sub_nav_screens as $sub ){
if(str_contains( $screen->id, $sub)){
// We are fam-a-lee
return true;
}
}
// Get out of my yard, pesky kids
return false;
}
This is what I came up with. If anyone has a more efficient method of accomplishing this, please share.
Now for the discussion part:
Is the one-child-makes-everyone-a-parent behavior needed at all?
Seems like only tabs that have children and their children should enter into this subnav world in the first place.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Currently, if one tab is assigned a parent, then its parent is assigned a default/general sub tab. This is fine for a parent with children, however, this one child will automatically assign all other non-parent tabs their own default general tab:
After digging around a bit, I found that there is a sweet
wp_user_profiles_admin_show_subnav
filter that controls the showing of subnavs (sub tabs).This is the rather convoluted way I am using this to only show subnavs on tabs that are assigned as parent (and their children, of course):
This is what I came up with. If anyone has a more efficient method of accomplishing this, please share.
Now for the discussion part:
Is the one-child-makes-everyone-a-parent behavior needed at all?
Seems like only tabs that have children and their children should enter into this subnav world in the first place.
Beta Was this translation helpful? Give feedback.
All reactions