Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…oarding into add/PRESS2-682-support-crazydomains
  • Loading branch information
arunshenoy99 committed Apr 5, 2023
2 parents 902e47f + cab49b2 commit d8692c5
Show file tree
Hide file tree
Showing 13 changed files with 488 additions and 248 deletions.
9 changes: 8 additions & 1 deletion includes/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,17 @@
final class Application {

/**
* Newfold Labs Module Container
*
* @var Container
*/
protected $container;

/**
* Arguments for the container
*
* @var agrs
*/
protected $args;

/**
Expand Down Expand Up @@ -65,4 +72,4 @@ public function __construct( Container $container ) {
\do_action( 'nfd_module_onboarding_post_init' );
}
}
// END \NewfoldLabs\WP\Module\Onboarding\Application
// END /NewfoldLabs/WP/Module/Onboarding/Application
85 changes: 79 additions & 6 deletions includes/Data/Patterns.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,22 @@
*/
final class Patterns {

/**
* List of dummy menu page titles.
*
* @return array
*/
public static function get_dummy_menu_items() {
return 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' ),
);
}

/**
* Retrieve Patterns for Theme Step.
*
Expand All @@ -16,7 +32,8 @@ protected static function get_theme_step_patterns() {
'yith-wonder' => array(
'theme-styles' => array(
'site-header-left-logo-navigation-inline' => array(
'active' => true,
'active' => true,
'replace' => true,
),
'homepage-1' => array(
'active' => true,
Expand All @@ -29,7 +46,8 @@ protected static function get_theme_step_patterns() {
),
'homepage-styles' => array(
'site-header-left-logo-navigation-inline' => array(
'active' => true,
'active' => true,
'replace' => true,
),
'homepage-1' => array(
'active' => true,
Expand Down Expand Up @@ -148,6 +166,47 @@ public static function get_pattern_from_slug( $pattern_slug ) {
return false;
}

/**
* Replace the header menu slug in the patterns array
*
* @param array $patterns Patterns for the specific step
* @param string $header_menu_slug header menu slug choosen by the user
*
* @return array
*/
private static function replace_header_menu_slug( $patterns, $header_menu_slug ) {
foreach ( $patterns as $slug => $slug_details ) {
if ( true === $slug_details['replace'] ) {
unset( $patterns[ $slug ] );
$patterns = array_merge( array( $header_menu_slug => $slug_details ), $patterns );
}
}
return $patterns;
}

/**
* Replace the header menu slug in the patterns array
*
* @param array $pattern_content pattern grammar that is to be modified
*
* @return array
*/
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 ) {
$dummy_menu_grammar = '<!-- wp:navigation-link {
"isTopLevelLink":true,
"label":"' . strtolower( $item ) . '",
"title":"' . $item . '",
"url":"' . get_site_url() . '/' . strtolower( $item ) . '"
} /-->';
$pattern_content = preg_replace( $menu_navigation_grammar, $dummy_menu_grammar, $pattern_content, 1 );
}
return $pattern_content;
}

/**
* Retrieve Theme Step Patterns from chosen Theme in Previous Step
*
Expand All @@ -163,15 +222,29 @@ public static function get_theme_step_patterns_from_step( $step, $squash = false
return false;
}

$pattern_slugs = self::get_theme_step_patterns()[ $active_theme ][ $step ];
$block_patterns_registry = \WP_Block_Patterns_Registry::get_instance();
$block_patterns = array();
$block_patterns_squashed = '';
$styles_to_check_for_header_menu = self::get_theme_step_patterns()[ $active_theme ]['styles-for-header-menu-check'];
$pattern_slugs = self::get_theme_step_patterns()[ $active_theme ][ $step ];
$block_patterns_registry = \WP_Block_Patterns_Registry::get_instance();
$block_patterns = array();
$block_patterns_squashed = '';

// fetch the selected header menu slug from DB
$flow_data = \get_option( Options::get_option_name( 'flow' ) );
$header_menu_slug = explode( '/', $flow_data['data']['partHeader'] )[1];
if ( ! empty( $header_menu_slug ) ) {
$pattern_slugs = self::replace_header_menu_slug( $pattern_slugs, $header_menu_slug );
}

foreach ( array_keys( $pattern_slugs ) as $pattern_slug ) {
if ( true === $pattern_slugs[ $pattern_slug ]['active'] ) {
$pattern_name = $active_theme . '/' . $pattern_slug;
if ( $block_patterns_registry->is_registered( $pattern_name ) ) {
$pattern = $block_patterns_registry->get_registered( $pattern_name );
// if header menu slug contains "split" replace the menu links with dummy links
if ( false !== stripos( $pattern_slug, 'split' ) ) {
$pattern['content'] = self::replace_split_menu_items( $pattern['content'] );
}

if ( ! $squash ) {
$block_patterns[] = array_merge(
array(
Expand Down
13 changes: 12 additions & 1 deletion includes/Data/Plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,18 @@ final class Plugins {
'priority' => 20,
),
),
'wc_priority' => array(),
'wc_priority' => array(
array(
'slug' => 'nfd_slug_yith_shippo_shippings_for_woocommerce',
'activate' => true,
'priority' => 259,
),
array(
'slug' => 'nfd_slug_yith_paypal_payments_for_woocommerce',
'activate' => true,
'priority' => 258,
),
),
),
'bluehost-india' => array(
'wc_standard' => array(
Expand Down
19 changes: 17 additions & 2 deletions includes/RestApi/RestApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@

namespace NewfoldLabs\WP\Module\Onboarding\RestApi;

use NewfoldLabs\WP\Module\Onboarding\RestApi\RestApiFilter;

/**
* Instantiate controllers and register routes.
*/
final class RestApi {

/**
* List of custom REST API controllers
*
* @var array
*/
protected $controllers = array(
'NewfoldLabs\\WP\\Module\\Onboarding\\RestApi\\SiteImagesController',
'NewfoldLabs\\WP\\Module\\Onboarding\\RestApi\\Themes\\ThemeGeneratorController',
Expand All @@ -20,13 +27,21 @@ final class RestApi {
'NewfoldLabs\\WP\\Module\\Onboarding\\RestApi\\SitePagesController',
'NewfoldLabs\WP\\Module\\Onboarding\\RestApi\\Themes\\ThemeInstallerController',
'NewfoldLabs\WP\\Module\\Onboarding\\RestApi\\Themes\\ThemeFontsController',
'NewfoldLabs\WP\\Module\\Onboarding\\RestApi\\Themes\\ThemeColorsController'
'NewfoldLabs\WP\\Module\\Onboarding\\RestApi\\Themes\\ThemeColorsController',
);

/**
* Setup the custom REST API
*/
public function __construct() {
add_action( 'rest_api_init', array( $this, 'register_routes' ) );
// create an instance of the RestApiFilter to filter the responses for header menu navigation
new RestApiFilter();
}

/**
* Register the custom REST API routes
*/
public function register_routes() {
foreach ( $this->controllers as $controller ) {
/**
Expand All @@ -38,4 +53,4 @@ public function register_routes() {
$instance->register_routes();
}
}
} // END \NewfoldLabs\WP\Module\Onboarding\RestApi()
} // END /NewfoldLabs/WP/Module/Onboarding/RestApi()
Loading

0 comments on commit d8692c5

Please sign in to comment.