maithemewp / mai-engine

Other
17 stars 3 forks source link

Not allowed to access this page” on genesis-getting-started when switching from a Mai theme #355

Open JiveDig opened 4 years ago

JiveDig commented 4 years ago

Via Nick Cernis here.

  1. Activate Mai Success.
  2. Activate Genesis Sample from Appearance → Themes (or another theme that uses Genesis one-click theme setup).

You'll see “sorry you are not allowed to access this page” because Mai removes the Child Theme Setup page from the Genesis submenu.

It makes it look like the new theme is broken; it's not immediately clear that the cause is the previously active theme.

Once Mai Engine self-deactivates a visit to Genesis → Child Theme Setup works, but the user has to know to go there to complete set up their new theme.

nickcernis commented 4 years ago

Just to complete the loop from Slack, the issue is due to Genesis admin menus being effectively unhooked here:

https://github.com/maithemewp/mai-engine/blob/a4ac85cbcdaa44aca188e0c9faed1a2db7d8d9b6/lib/init.php#L191

They're only added back again for themes that declare mai-engine support:

https://github.com/maithemewp/mai-engine/blob/a4ac85cbcdaa44aca188e0c9faed1a2db7d8d9b6/lib/init.php#L235

So the Genesis Getting Started submenu page is not available to non mai-engine themes after a theme switch if Mai Engine is active. This results in the “Not allowed to access” message when the redirect occurs in Genesis on theme activation — WP shows that message if the submenu page hasn't been registered.

One fix is to return early from mai_modify_genesis_defaults and mai_load_genesis in init.php if the current theme is not a Mai Engine theme:

    if ( ! current_theme_supports( 'mai-engine' ) ) {
        return;
    }

That way menus are still available to non-Mai Genesis themes during a theme switch, as they're only removed for Mai Engine themes.