Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…oarding into enhance/PRESS2-856-analytics
  • Loading branch information
arunshenoy99 committed May 26, 2023
2 parents d32de03 + afa7d29 commit 9666a96
Show file tree
Hide file tree
Showing 31 changed files with 545 additions and 202 deletions.
2 changes: 1 addition & 1 deletion includes/Data/Brands.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public static function get_brands() {
/**
* Sets the hosting brand for which Onboarding is active.
*
* @param array $container The brand plugin container.
* @param object $container The brand plugin container.
* @return void
*/
public static function set_current_brand( $container ) {
Expand Down
2 changes: 1 addition & 1 deletion includes/Data/Flows.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public static function get_default_flow() {
}

/**
* Retrive all the known onboarding flows.
* Retrieve all the known onboarding flows.
*
* @return array A value of true for each key indicates that the flow has been approved
* and a value of null indicates the flow has not been approved (or) has been temporarily disabled.
Expand Down
2 changes: 0 additions & 2 deletions includes/Data/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@ final class Options {
*
* @var string
*/

protected static $prefix = 'nfd_module_onboarding_';

/**
* List of all the options.
*
* @var array
*/

protected static $options = array(
'redirect' => 'redirect',
'redirect_param' => 'redirect_param',
Expand Down
142 changes: 97 additions & 45 deletions includes/Data/Patterns.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,19 @@ protected static function get_theme_step_patterns() {
);
}

/**
* Callback Functions for Theme Step.
*
* @return array
*/
protected static function get_theme_step_filters() {
return array(
'yith-wonder' => array(
'homepage-styles' => array( __CLASS__, 'filter_yith_wonder_homepage_patterns' ),
),
);
}

/**
* Get post metadata for a pattern. Ref: SitePagesController.php
*
Expand Down Expand Up @@ -191,7 +204,7 @@ public static function get_meta_from_pattern_slug( $pattern_slug ) {
/**
* Retrieve pattern from slug.
*
* @param array $pattern_slug Pattern Slug Data
* @param string $pattern_slug Pattern Slug Data
*
* @return array|boolean
*/
Expand All @@ -211,21 +224,23 @@ public static function get_pattern_from_slug( $pattern_slug ) {
}

/**
* Replace the header menu slug in the patterns array
* Retrieve the header menu slug from flow data.
*
* @param array $patterns Patterns for the specific step
* @param string $header_menu_slug header menu slug choosen by the user
*
* @return array
* @return string|boolean
*/
private static function replace_header_menu_slug( $patterns, $header_menu_slug ) {
foreach ( $patterns as $slug => $slug_details ) {
if ( isset( $slug_details['replace'] ) && true === $slug_details['replace'] ) {
unset( $patterns[ $slug ] );
$patterns = array_merge( array( $header_menu_slug => $slug_details ), $patterns );
}
private static function get_selected_header_from_flow_data() {
// fetch the selected header menu slug from DB
$flow_data = \get_option( Options::get_option_name( 'flow' ), false );
if ( ! $flow_data ) {
return false;
}
return $patterns;

if ( ! empty( $flow_data['data']['partHeader'] ) ) {
return explode( '/', $flow_data['data']['partHeader'] )[1];
}

return false;

}

/**
Expand Down Expand Up @@ -268,44 +283,81 @@ public static function get_theme_step_patterns_from_step( $step, $squash = 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 = '';

// 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'] ) {
continue;
}
if ( isset( $pattern_slugs[ $pattern_slug ]['replace'] ) && true === $pattern_slugs[ $pattern_slug ]['replace'] ) {
$pattern_slug_data = $pattern_slugs[ $pattern_slug ];
$header_menu_slug = self::get_selected_header_from_flow_data();
$pattern_slug = ( ! empty( $header_menu_slug ) ) ? $header_menu_slug : $pattern_slug;
$pattern_slugs[ $pattern_slug ] = $pattern_slug_data;
}
$pattern_name = $active_theme . '/' . $pattern_slug;
if ( ! $block_patterns_registry->is_registered( $pattern_name ) ) {
continue;
}
$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(
'slug' => $pattern_name,
'title' => $pattern['title'],
'content' => self::cleanup_wp_grammar( $pattern['content'] ),
'name' => $pattern['name'],
'categories' => $pattern['categories'],
),
$pattern_slugs[ $pattern_slug ]
);
continue;
}
$block_patterns .= self::cleanup_wp_grammar( $pattern['content'] );
}

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(
'slug' => $pattern_name,
'title' => $pattern['title'],
'content' => self::cleanup_wp_grammar( $pattern['content'] ),
'name' => $pattern['name'],
),
$pattern_slugs[ $pattern_slug ]
);
continue;
}
$block_patterns_squashed .= self::cleanup_wp_grammar( $pattern['content'] );
}
$step_filter = self::get_theme_step_filters()[ $active_theme ][ $step ];
$theme_step_callback = isset( $step_filter ) ? $step_filter : false;
if ( is_callable( $theme_step_callback ) ) {
return $theme_step_callback( $block_patterns );
}

return $block_patterns;
}

/**
* Retrieve Homepage Menu Step Patterns
*
* @param array $patterns Step Patterns Data
* @return array
*/
private static function filter_yith_wonder_homepage_patterns( $patterns ) {
$header_content = '';
$homepage_style_slugs = array();
$footer_content = '';

foreach ( $patterns as $index_key => $slug ) {
if ( in_array( 'yith-wonder-site-header', $slug['categories'] ) ) {
$header_content = $slug['content'];
continue;
}
if ( in_array( 'yith-wonder-pages', $slug['categories'] ) ) {
array_push( $homepage_style_slugs, $slug );
}
if ( in_array( 'yith-wonder-site-footer', $slug['categories'] ) ) {
$footer_content = $slug['content'];
continue;
}
}

return $squash ? $block_patterns_squashed : $block_patterns;
foreach ( $homepage_style_slugs as $key => $homepage_style ) {
$homepage_style_slugs[ $key ]['content'] = $header_content . $homepage_style['content'] . $footer_content;
}

return $homepage_style_slugs;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions includes/Data/Themes/Colors.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ final class Colors {
*/
protected static $theme_colors = array(
'yith-wonder' => array(
'tailored' => array(
'tailored' => array(
'calm' => array(
'header-background' => '#1A4733',
'header-foreground' => '#FFFFFF',
Expand Down Expand Up @@ -137,7 +137,7 @@ final class Colors {
'base' => '#FFFFFF',
),
),
'custom-picker-grouping' => array(
'custom-picker-grouping' => array(
'base' => array(
'header-foreground',
'header-titles',
Expand Down
3 changes: 3 additions & 0 deletions includes/Data/Themes/Fonts.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace NewfoldLabs\WP\Module\Onboarding\Data\Themes;

/**
* Contains custom font palettes for a given theme.
*/
final class Fonts {

/**
Expand Down
2 changes: 1 addition & 1 deletion includes/LoginRedirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static function sso( $original_redirect ) {
*/
public static function wplogin( $original_redirect, $requested_original_redirect, $user ) {
// wp-login.php runs this filter on load and login failures
// We should only do a redirect with a succesful user login
// We should only do a redirect with a successful user login
if ( ! ( $user instanceof \WP_User ) ) {
return $original_redirect;
}
Expand Down
5 changes: 2 additions & 3 deletions includes/Models/PriorityQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
class PriorityQueue extends \SplPriorityQueue {

/**
* @param mixed $priority1
* @param mixed $priority2
*
* Defines the logic to use when comparing two priorities.
*
* @param mixed $priority1 First Priority Queue
* @param mixed $priority2 Second Priority Queue
* @return int
*/
public function compare( $priority1, $priority2 ) {
Expand Down
46 changes: 38 additions & 8 deletions includes/Models/Theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,68 +7,98 @@
*/
class Theme implements \JsonSerializable {

/**
* Name of the Theme.
*
* @var string
*/
private $theme_name;

/**
* Theme image Path.
*
* @var string
*/
private $theme_image;

/**
* Status of a theme being a Newfold Theme.
*
* @var boolean
*/
private $is_newfold_theme;

/**
* @param string $theme_name
* Theme constructor.
*
* @param string $theme_name Theme Name.
*/
public function __construct( $theme_name ) {
$this->theme_name = $theme_name;
$this->is_newfold_theme = false;
}

/**
* @param string $theme_name
* Sets the Theme Name
*
* @param string $theme_name name of the theme.
* @return void
*/
public function set_theme_name( $theme_name ) {
$this->theme_name = $theme_name;
}

/**
* @return string $theme_name
* Retrieve the Theme Name
*
* @return string
*/
public function get_theme_name() {
return $this->theme_name;
}

/**
* @param string $theme_image Path to theme screenshot image.
* Sets the Theme image path
*
* @param string $theme_image Path to theme screenshot image.
* @return void
*/
public function set_theme_image( $theme_image ) {
$this->theme_image = $theme_image;
}

/**
* @return $theme_image Path to theme screenshot image.
* Retrieve the path to theme screenshot image
*
* @return string
*/
public function get_theme_image() {
return $this->theme_image;
}

/**
* @param boolean $is_newfold_theme
* Sets the status of a theme as a Newfold theme.
*
* @param boolean $is_newfold_theme Determines if there is a Newfold theme
* @return void
*/
public function set_is_newfold_theme( $is_newfold_theme ) {
$this->is_newfold_theme = $is_newfold_theme;
}

/**
* @return boolean $is_newfold_theme true if the theme author is Newfold Digital.
* Retrieve is_newfold_theme status - true if the theme author is Newfold Digital.
*
* @return boolean
*/
public function get_is_newfold_theme() {
return $this->is_newfold_theme;
}

/**
* @return array JSON Serialize the data
* To JSON Serialize the Theme data
*
* @return array
*/
public function jsonSerialize() {
return array(
Expand Down
2 changes: 1 addition & 1 deletion includes/ModuleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static function module_switcher() {

$enable_onboarding = self::verify_onboarding_criteria( $customer_data );

// Check if he is a Non-Ecom Cust and Disable Redirect and Module
// Check if he is a Non-Ecommerce Customer and Disable Redirect and Module
if ( ! $enable_onboarding ) {

// Check if the Module Does Exist
Expand Down
Loading

0 comments on commit 9666a96

Please sign in to comment.