"Aliases" tab missing in network site settings
villeveikkoilen opened this issue · comments
Problem
One day I noticed that the Aliases
settings tab was missing in network site settings. I traced the problem to The Events Calendar PRO
plugin. When that plugin was activated, the tab disappeared, and when I deactivated it, the tab re-appeared.
In my understanding, the problem is in the following lines of code:
Lines 64 to 66 in 9240e7c
For some reason, I don't know why, when TEC plugin is activated, $GLOBALS['submenu_file']
value is NULL
, when it should be sites.php
.
Versions
- WordPress: 5.9.3
- The Events Calendar PRO: 5.14.0.1
- Mercator: 1.0.3
Possible fix (POC)
There's a proper way of getting current admin screen instead of reading globals. My suggestion would be to replace these lines:
Lines 64 to 66 in 9240e7c
with:
$current_screen = get_current_screen();
if ( empty($current_screen->id) || ($current_screen->id !== 'site-info-network' && $current_screen->id !== 'admin-network' ) ) {
return;
}
Interesting find @villeveikkoilen. I have confirmed this behavior as I have a multisite using The Events Calendar and another one without it. The one that has TEC is missing the Aliases tab. I have discovered another issue as well.
Problem: When viewing a custom tab that has been added to a multisite using the network_edit_site_nav_links
filter, the Alias tab also disappears.
From what I can see, Mercator is adding the Aliases
tab using Javascript.
Lines 53 to 59 in 55e3f01
At the time this might have been the only way to do it however there is a hook that can be used to avoid using JavaScript. Perhaps something like this to replace maybe_output_site_tab()
...
add_filter( 'network_edit_site_nav_links', 'mercator_add_settings_tab' );
function mercator_add_settings_tab( $tabs ) {
// add a new tab to the Edit Site area for Sites
$tabs['mercator-aliases-nav-link'] = array(
'label' => 'Aliases',
'url' => 'admin.php?action=mercator-aliases',
'cap' => 'manage_sites'
);
return $tabs;
}