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 #47

Merged
merged 2 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
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
16 changes: 13 additions & 3 deletions includes/Patterns.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace NewfoldLabs\WP\Module\Onboarding\Data;

use NewfoldLabs\WP\Module\Onboarding\Data\Services\SiteGenService;
use NewfoldLabs\WP\Module\Onboarding\Data\Services\WonderBlocksService;

/**
Expand All @@ -13,15 +14,24 @@ final class Patterns {
*
* @return array
*/
public static function get_dummy_menu_items() {
return array(
public static function get_dummy_navigation_menu_items() {
$default_items = array(
__( 'Home', 'wp-module-onboarding' ),
__( 'About', 'wp-module-onboarding' ),
__( 'Contact', 'wp-module-onboarding' ),
__( 'News', 'wp-module-onboarding' ),
__( 'Privacy', 'wp-module-onboarding' ),
__( 'Careers', 'wp-module-onboarding' ),
);

$flow_to_dummy_items = array(
'sitegen' => SiteGenService::get_dummy_navigation_menu_items(),
'wp-setup' => $default_items,
'ecommerce' => $default_items,
);

$current_flow = Data::current_flow();
return ! empty( $flow_to_dummy_items[ $current_flow ] ) ? $flow_to_dummy_items[ $current_flow ] : $default_items;
}

/**
Expand Down Expand Up @@ -357,7 +367,7 @@ private static function replace_split_menu_items( $pattern_content ) {
$dummy_menu_grammar = '';
$menu_navigation_grammar = '<!-- wp:navigation-link {"isTopLevelLink":true} /-->';

foreach ( self::get_dummy_menu_items() as $item ) {
foreach ( self::get_dummy_navigation_menu_items() as $item ) {
$dummy_menu_grammar = '<!-- wp:navigation-link {
"isTopLevelLink":true,
"label":"' . strtolower( $item ) . '",
Expand Down
26 changes: 26 additions & 0 deletions includes/Services/SiteGenService.php
Original file line number Diff line number Diff line change
Expand Up @@ -819,4 +819,30 @@ public static function publish_sitemap_pages( $site_description, $content_style,

return true;
}

/**
* Get the dummy navigation menu items for the Sitegen previews.
*
* @return array
*/
public static function get_dummy_navigation_menu_items() {
$prompt = self::get_prompt();
$site_info = array( 'site_description' => $prompt );
$sitemap = self::instantiate_site_meta( $site_info, 'sitemap' );
if ( is_wp_error( $sitemap ) ) {
return array();
}

$dummy_items = array();
foreach ( $sitemap as $page ) {
if ( ! isset( $page['title'] ) ) {
continue;
}

array_push( $dummy_items, $page['title'] );

}

return $dummy_items;
}
}
Loading