Skip to content

Commit

Permalink
Merge pull request #474 from newfold-labs/enhance/sitegen-header-nav
Browse files Browse the repository at this point in the history
Replace menu items in previews with those from the sitemap
  • Loading branch information
officiallygod authored Feb 21, 2024
2 parents f1d25f1 + 73e013f commit 39d9b75
Showing 1 changed file with 7 additions and 5 deletions.
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

0 comments on commit 39d9b75

Please sign in to comment.