Skip to content

Commit

Permalink
Add Wonder Blocks Headers and Footers
Browse files Browse the repository at this point in the history
  • Loading branch information
arunshenoy99 committed Nov 1, 2023
1 parent 145119e commit d6cac82
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 32 deletions.
4 changes: 3 additions & 1 deletion includes/Flows/Flows.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final class Flows {
* @var array
*/
protected static $data = array(
'version' => '1.0.2',
'version' => '1.0.3',

// Each time step is viewed, insert GMT timestamp to array.
'isViewed' => array(),
Expand Down Expand Up @@ -94,6 +94,8 @@ final class Flows {
// This string will identify the Header Pattern
'partHeader' => '',

'partFooter' => '',

// for eg. Home, About, Contact, Blog|News, Resume, Portfolio, Staff and Link in Bio
'sitePages' => array(
'homepage' => '',
Expand Down
95 changes: 65 additions & 30 deletions includes/Patterns.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ protected static function get_theme_step_patterns() {
'yith-wonder' => array(
'theme-styles' => array(
'site-header-left-logo-navigation-inline' => array(
'active' => true,
'replace' => true,
'active' => true,
'replace' => true,
'wonder_blocks' => 'header-1',
),
'homepage-1' => array(
'active' => true,
Expand All @@ -44,13 +45,15 @@ protected static function get_theme_step_patterns() {
'wonder_blocks' => 'home-1',
),
'site-footer' => array(
'active' => true,
'active' => true,
'wonder_blocks' => 'footer-15',
),
),
'homepage-styles' => array(
'site-header-left-logo-navigation-inline' => array(
'active' => true,
'replace' => true,
'active' => true,
'replace' => true,
'wonder_blocks' => 'header-1',
),
'homepage-1' => array(
'active' => true,
Expand All @@ -68,7 +71,8 @@ protected static function get_theme_step_patterns() {
'wonder_blocks' => 'home-3',
),
'site-footer' => array(
'active' => true,
'active' => true,
'wonder_blocks' => 'footer-15',
),
),
'site-pages' => array(
Expand Down Expand Up @@ -106,27 +110,32 @@ protected static function get_theme_step_patterns() {
),
'header-menu' => array(
'site-header-left-logo-navigation-inline' => array(
'active' => true,
'shown' => true,
'active' => true,
'shown' => true,
'wonder_blocks' => 'header-1',
),
'homepage-1' => array(
'active' => true,
'wonder_blocks' => 'home-1',
),
'site-footer' => array(
'active' => true,
'active' => true,
'wonder_blocks' => 'footer-15',
),
'site-header-left-logo-navigation-below' => array(
'active' => true,
'shown' => true,
'active' => true,
'shown' => true,
'wonder_blocks' => 'header-10',
),
'site-header-centered' => array(
'active' => true,
'shown' => true,
'active' => true,
'shown' => true,
'wonder_blocks' => 'header-8',
),
'site-header-splitted-menu' => array(
'active' => true,
'shown' => true,
'active' => true,
'shown' => true,
'wonder_blocks' => 'header-3',
),
),
),
Expand Down Expand Up @@ -317,11 +326,24 @@ private static function get_selected_header_from_flow_data() {
return false;
}

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

return false;
$part_header = $flow_data['data']['partHeader'];
$slug = explode( '/', $flow_data['data']['partHeader'] )[1];

if ( WonderBlocksService::is_valid_slug( $part_header ) ) {
return array(
'slug' => $slug,
'type' => 'wonder_blocks',
);
}

return array(
'slug' => $slug,
'type' => 'wonder',
);

}

Expand Down Expand Up @@ -371,9 +393,16 @@ public static function get_theme_step_patterns_from_step( $step, $squash = false
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_slug_data = $pattern_slugs[ $pattern_slug ];
$header_menu_data = self::get_selected_header_from_flow_data();
if ( ! empty( $header_menu_data ) ) {
$slug = $header_menu_data['slug'];
if ( 'wonder_blocks' === $header_menu_data['type'] ) {
$pattern_slug_data['wonder_blocks'] = $slug;
} else {
$pattern_slug = $slug;
}
}
$pattern_slugs[ $pattern_slug ] = $pattern_slug_data;
}

Expand Down Expand Up @@ -425,17 +454,17 @@ private static function filter_yith_wonder_homepage_patterns( $patterns ) {
$footer_content = '';

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

foreach ( $homepage_style_slugs as $key => $homepage_style ) {
Expand All @@ -455,13 +484,19 @@ private static function filter_yith_wonder_headermenu_patterns( $patterns ) {
$body_content = '';
$header_menu_slugs = array();
foreach ( $patterns as $pattern_details ) {
if ( in_array( 'yith-wonder-site-header', $pattern_details['categories'], true ) ) {
if ( ( WonderBlocksService::is_valid_slug( $pattern_details['slug'] ) && in_array( 'header', $pattern_details['categories'], true ) ) || in_array( 'yith-wonder-site-header', $pattern_details['categories'], true ) ) {
$header_menu_slugs['pageHeaders'][] = $pattern_details;
} else {
$body_content .= $pattern_details['content'];
$header_menu_slugs['pageBody'] = $body_content;
continue;
}

if ( ( WonderBlocksService::is_valid_slug( $pattern_details['slug'] ) && in_array( 'footer', $pattern_details['categories'], true ) ) || in_array( 'yith-wonder-site-footer', $pattern_details['categories'], true ) ) {
$header_menu_slugs['pageFooter'] = $pattern_details;
}

$body_content .= $pattern_details['content'];
$header_menu_slugs['pageBody'] = $body_content;
}

return $header_menu_slugs;
}

Expand Down
8 changes: 7 additions & 1 deletion includes/Services/WonderBlocksService.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ class WonderBlocksService {
* @return boolean
*/
public static function is_pattern( $slug ) {
$patterns = array();
$patterns = array(
'header-1' => true,
'header-10' => true,
'header-8' => true,
'header-3' => true,
'footer-15' => true,
);

return isset( $patterns[ $slug ] );
}
Expand Down

0 comments on commit d6cac82

Please sign in to comment.