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

Replace menu items in previews with those from the sitemap #474

Merged
merged 3 commits into from
Feb 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions includes/RestApi/RestApiFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public static function wp_onboarding_nav_menu_filter( $response, $args ) {
public static function prepare_raw_html_menu( $data, $index ) {
// create dummy menu links
$menu_navigation_grammar = '';
foreach ( Patterns::get_dummy_menu_items() as $page_title ) {
foreach ( Patterns::get_dummy_navigation_menu_items() as $page_title ) {
$menu_navigation_grammar .= '<!-- wp:navigation-link {"isTopLevelLink":true, "label":"' . $page_title . '", "title":"' . $page_title . '"} /-->';
}
// need to reset ID else the data saved in the DB gets used
Expand Down Expand Up @@ -252,11 +252,12 @@ public static function modify_get_pages_response( $response ) {
}

// make sure we have the number of dummy pages required
$pages = $response->get_data();
if ( count( $pages ) < count( Patterns::get_dummy_menu_items() ) ) {
$pages = $response->get_data();
$dummy_items = Patterns::get_dummy_navigation_menu_items();
if ( count( $pages ) < count( $dummy_items ) ) {
$pages = array_pad(
$pages,
count( Patterns::get_dummy_menu_items() ),
count( $dummy_items ),
array_pop( $pages )
);
}
Expand All @@ -281,9 +282,10 @@ public static function rename_page( array $page, $index ) {
if ( isset( $page['title']['rendered'] ) ) {
// changed id so that while rendering the menu link and name are proper
$page['id'] = $page['id'] + $index;
$page['title']['rendered'] = Patterns::get_dummy_menu_items()[ $index ];
$page['title']['rendered'] = Patterns::get_dummy_navigation_menu_items()[ $index ];
$page['menu_order'] = $index;
}

return $page;
}

Expand Down
Loading