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

Use Rosetta header menu items instead of global #49

Closed
Tracked by #38
iandunn opened this issue Dec 27, 2021 · 4 comments
Closed
Tracked by #38

Use Rosetta header menu items instead of global #49

iandunn opened this issue Dec 27, 2021 · 4 comments
Assignees
Labels
[Type] Enhancement New feature or request
Milestone

Comments

@iandunn
Copy link
Member

iandunn commented Dec 27, 2021

The new header works on Rosetta sites, but it needs to have the local menu items (nav_menu_item posts).

Currently Rosetta sites use a homegrown API endpoint, e.g. https://de.wordpress.org/?fetch-custom-header=%2Fplugins%2F.

the Menu is generated on the "main localised site" and that menu (and therefor, all menu items) are then output on the sub-site. There's memcache involved in all that of course. The menu on Rosetta can't be built on a not-main/root-site as Nav Menu's (as used on Rosetta, rather than hard-coded links) can't be generated with a simple switch_to_site() correctly.
#38

If we want to take a different approach, then one workaround might be to have a cron job to generate the markup, and cache it in an option on each site. Then the global menu could switch_to_blog and retrieve it.

That may not even be necessary, though, since the Rosetta sites don't need to use the current homegrown REST API endpoint. It looks like they can just include the new block directly and it works fine. So, they could pull the menu items directly, without the need for a switch_to_blog, endpoint, etc.

@iandunn iandunn added the [Type] Enhancement New feature or request label Dec 27, 2021
@iandunn iandunn added this to the News launch milestone Dec 27, 2021
@iandunn iandunn self-assigned this Dec 27, 2021
@iandunn
Copy link
Member Author

iandunn commented Dec 28, 2021

The menu on Rosetta can't be built on a not-main/root-site as Nav Menu's (as used on Rosetta, rather than hard-coded links) can't be generated with a simple switch_to_site() correctly.

@dd32 , switch_to_blog() seems to work works fine on /team, /support, /plugins, etc in my experiments. Do you remember what specifically didn't work?

function render_global_header() {
	remove_inner_group_container();

	if ( isset( $GLOBALS['rosetta'] ) ) {
		switch_to_blog( 82 ); // nl.w.org root site

		$rendered = wp_nav_menu( array(
			'menu' => get_nav_menu_locations()['rosetta_main'],
			'echo' => false,
			'theme_location' => 'rosetta_main'
		) );
		var_dump($rendered);

		restore_current_blog();
		wp_die();

wp_get_nav_menu_items( get_nav_menu_locations()['rosetta_main'] ) also works. I'm guessing we'll want to use that, and have the new header loop through them and generate block markup, rather that using the Classic markup that wp_nav_menu generates. That way it'll be consistent w/ the global menu items that non-rosetta sites use.

@iandunn
Copy link
Member Author

iandunn commented Dec 29, 2021

FYI, i network-activated the Gutenberg plugin on Rosetta sites to support this.

cc @ocean90, @SergeyBiryukov, @dd32

iandunn added a commit that referenced this issue Dec 31, 2021
This lays the groundwork for swapping out the global items for Rosetta items, depending on the site.

See #49
@iandunn
Copy link
Member Author

iandunn commented Dec 31, 2021

9a7ed8d and 51399a8 are the core of the solution, but I'm still planning to add some caching, fix a few edge cases, etc.

Some of this relies on changes to rosetta-sites.php, but I don't want to deploy those on a Friday afternoon, so I'll do it next week.

@iandunn iandunn changed the title Use Rosetta menu items instead of global Use Rosetta header menu items instead of global Jan 1, 2022
This was referenced Jan 5, 2022
@iandunn
Copy link
Member Author

iandunn commented Jan 5, 2022

I think this is all done now, except for things that have separate issues opened.

@iandunn iandunn closed this as completed Jan 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant