Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Aliases" tab missing in network site settings #126

Open
villeveikkoilen opened this issue Jun 3, 2022 · 1 comment
Open

"Aliases" tab missing in network site settings #126

villeveikkoilen opened this issue Jun 3, 2022 · 1 comment

Comments

@villeveikkoilen
Copy link

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:

Mercator/admin.php

Lines 64 to 66 in 9240e7c

if ( $GLOBALS['parent_file'] !== 'sites.php' || $GLOBALS['submenu_file'] !== 'sites.php' ) {
return;
}

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:

Mercator/admin.php

Lines 64 to 66 in 9240e7c

if ( $GLOBALS['parent_file'] !== 'sites.php' || $GLOBALS['submenu_file'] !== 'sites.php' ) {
return;
}

with:

$current_screen = get_current_screen();

if ( empty($current_screen->id) || ($current_screen->id !== 'site-info-network' && $current_screen->id !== 'admin-network' ) ) {
	return;
}
@rumspeed
Copy link

rumspeed commented Jun 3, 2022

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.

Mercator/admin.php

Lines 53 to 59 in 55e3f01

/**
* Output the site tab if we're on the right page
*
* Outputs the link, then moves it into place using JS, as there are no hooks to
* speak of.
*/
function maybe_output_site_tab() {

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;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant