Skip to content

Commit

Permalink
Merge pull request #176 from newfold-labs/fix/PRESS2-654-site-feature…
Browse files Browse the repository at this point in the history
…s-skeleton

Improve site features code, fix site features skeleton
  • Loading branch information
arunshenoy99 authored Feb 21, 2023
2 parents 667e5c1 + 49697f8 commit 0002a1f
Show file tree
Hide file tree
Showing 4 changed files with 250 additions and 218 deletions.
14 changes: 5 additions & 9 deletions includes/Data/Patterns.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<?php

namespace NewfoldLabs\WP\Module\Onboarding\Data;

use NewfoldLabs\WP\Module\Onboarding\Data\Options;

/**
* Class Patterns
*/
Expand Down Expand Up @@ -104,7 +101,6 @@ protected static function get_theme_step_patterns() {
'shown' => true,
),
),
'site-features' => SiteFeatures::get_site_features()[ Data::current_flow() ],
),
);
}
Expand Down Expand Up @@ -142,11 +138,11 @@ public static function get_pattern_from_slug( $pattern_slug ) {
$block_patterns_registry = \WP_Block_Patterns_Registry::get_instance();
if ( $block_patterns_registry->is_registered( $pattern_slug ) ) {
$pattern = $block_patterns_registry->get_registered( $pattern_slug );
return array(
'title' => $pattern['title'],
'content' => self::cleanup_wp_grammar( $pattern['content'] ),
'name' => $pattern['name'],
);
return array(
'title' => $pattern['title'],
'content' => self::cleanup_wp_grammar( $pattern['content'] ),
'name' => $pattern['name'],
);
}

return false;
Expand Down
328 changes: 163 additions & 165 deletions includes/Data/SiteFeatures.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,194 +6,192 @@
* Class SiteFeatures
*/
final class SiteFeatures {

/**
* Retrieve Site Features.
* Contains the map of site features for a particular flow and plan.
*
* @return array
* @var array
*/
public static function get_site_features() {
return array(
'wp-setup' => array(),
'ecommerce' => array(
'default' => array(
'jetpack' => array(
'slug' => 'jetpack',
'icon' => '--site-features-security',
'title' => 'Security, Speed & Growth',
'subtitle' => 'Powered by Jetpack',
'desc' => 'Jetpack includes dozens of powerful, unique capabilities for your WordPress sites from Automattic.',
'selected' => false,
'shown' => true,
),
'wpforms-lite' => array(
'slug' => 'wpforms-lite',
'icon' => '--site-features-form',
'title' => 'Forms',
'subtitle' => 'Powered by WP Forms',
'desc' => 'Five million people build smarter forms and surveys with WPForms from Awesome Motive.',
'selected' => false,
'shown' => true,
),
'google-analytics-for-wordpress' => array(
'slug' => 'google-analytics-for-wordpress',
'icon' => '--site-features-analytics',
'title' => 'Site Traffic',
'subtitle' => 'Powered by MonsterInsights',
'desc' => 'See the opportunities in your website analytics traffic data using MonsterInsights from Awesome Motive.',
'selected' => false,
'shown' => true,
),
'wordpress-seo' => array(
'slug' => 'wordpress-seo',
'icon' => '--site-features-share',
'title' => 'Search Engine Optimization',
'subtitle' => 'Powered by Yoast',
'desc' => 'Get more traffic to your WordPress site with powerful analysis and tools from our colleagues at Yoast.',
'selected' => false,
'shown' => true,
),
'creative-mail-by-constant-contact' => array(
'slug' => 'creative-mail-by-constant-contact',
'icon' => '--site-features-email',
'title' => 'Email Newsletters',
'subtitle' => 'Powered by Creative Email',
'desc' => 'A professional logo builder, marketing automations with WooCommerce and social management -- CreativeMail is a whole lot more than mail from Constant Contact.',
'selected' => false,
'shown' => true,
),
'optinmonster' => array(
'slug' => 'optinmonster',
'icon' => '--site-features-lead',
'title' => 'Lead Generation',
'subtitle' => 'Powered by Optin Monster',
'desc' => 'Connect with website visitors using a proven kit of tools for growth using this offering from Awesome Motive.',
'selected' => false,
'shown' => true,
),
protected static $site_features_flow_plan_map = array(
'wp-setup' => array(),
'ecommerce' => array(
'default' => array(
'jetpack' => array(
'slug' => 'jetpack',
'icon' => '--site-features-security',
'title' => 'Security, Speed & Growth',
'subtitle' => 'Powered by Jetpack',
'desc' => 'Jetpack includes dozens of powerful, unique capabilities for your WordPress sites from Automattic.',
'selected' => false,
'shown' => true,
),
'wpforms-lite' => array(
'slug' => 'wpforms-lite',
'icon' => '--site-features-form',
'title' => 'Forms',
'subtitle' => 'Powered by WP Forms',
'desc' => 'Five million people build smarter forms and surveys with WPForms from Awesome Motive.',
'selected' => false,
'shown' => true,
),
'google-analytics-for-wordpress' => array(
'slug' => 'google-analytics-for-wordpress',
'icon' => '--site-features-analytics',
'title' => 'Site Traffic',
'subtitle' => 'Powered by MonsterInsights',
'desc' => 'See the opportunities in your website analytics traffic data using MonsterInsights from Awesome Motive.',
'selected' => false,
'shown' => true,
),
'wc_standard' => array(
'yith-woocommerce-ajax-search' => array(
'slug' => 'yith-woocommerce-ajax-search',
'icon' => '--site-features-search',
'title' => 'Enhanced Product Search',
'subtitle' => 'Powered by YITH',
'desc' => 'Give your visitors great search experiences with this exclusive offering from our colleagues at YITH.',
'selected' => false,
'shown' => true,
),
'nfd_slug_yith_woocommerce_ajax_product_filter' => array(
'slug' => 'nfd_slug_yith_woocommerce_ajax_product_filter',
'icon' => '--site-features-filter',
'title' => 'Enhanced Product Filters',
'subtitle' => 'Powered by YITH',
'desc' => 'Give your visitors powerful tools to discover your great products with this exclusive offering from our colleagues at YITH.',
'selected' => false,
'shown' => true,
),
'nfd_slug_yith_woocommerce_booking' => array(
'slug' => 'nfd_slug_yith_woocommerce_booking',
'icon' => '--site-features-bookingcalendar',
'title' => 'Bookings & Appointments',
'subtitle' => 'Powered by YITH',
'desc' => 'Have visitors book meetings and services with you, accepting payment and more using this exclusive offering from our colleagues at YITH.',
'selected' => false,
'shown' => true,
),
'nfd_slug_yith_woocommerce_wishlist' => array(
'slug' => 'nfd_slug_yith_woocommerce_wishlist',
'icon' => '--site-features-wishlist',
'title' => 'Product Wishlists',
'subtitle' => 'Powered by YITH',
'desc' => 'Let discerning shoppers curate their selections with a system of favorites using this exclusive offering from our colleagues at YITH.',
'selected' => false,
'shown' => true,
),
'wordpress-seo' => array(
'slug' => 'wordpress-seo',
'icon' => '--site-features-share',
'title' => 'Search Engine Optimization',
'subtitle' => 'Powered by Yoast',
'desc' => 'Get more traffic to your WordPress site with powerful analysis and tools from our colleagues at Yoast.',
'selected' => false,
'shown' => true,
),
'wc_premium' => array(
'yith-woocommerce-ajax-search' => array(
'slug' => 'yith-woocommerce-ajax-search',
'icon' => '--site-features-search',
'title' => 'Enhanced Product Search',
'subtitle' => 'Powered by YITH',
'desc' => 'Give your visitors great search experiences with this exclusive offering from our colleagues at YITH.',
'selected' => false,
'shown' => true,
),
'nfd_slug_yith_woocommerce_ajax_product_filter' => array(
'slug' => 'nfd_slug_yith_woocommerce_ajax_product_filter',
'icon' => '--site-features-filter',
'title' => 'Enhanced Product Filters',
'subtitle' => 'Powered by YITH',
'desc' => 'Give your visitors powerful tools to discover your great products with this exclusive offering from our colleagues at YITH.',
'selected' => false,
'shown' => true,
),
'nfd_slug_yith_woocommerce_booking' => array(
'slug' => 'nfd_slug_yith_woocommerce_booking',
'icon' => '--site-features-bookingcalendar',
'title' => 'Bookings & Appointments',
'subtitle' => 'Powered by YITH',
'desc' => 'Have visitors book meetings and services with you, accepting payment and more using this exclusive offering from our colleagues at YITH.',
'selected' => false,
'shown' => true,
),
'nfd_slug_yith_woocommerce_wishlist' => array(
'slug' => 'nfd_slug_yith_woocommerce_wishlist',
'icon' => '--site-features-wishlist',
'title' => 'Product Wishlists',
'subtitle' => 'Powered by YITH',
'desc' => 'Let discerning shoppers curate their selections with a system of favorites using this exclusive offering from our colleagues at YITH.',
'selected' => false,
'shown' => true,
),
'creative-mail-by-constant-contact' => array(
'slug' => 'creative-mail-by-constant-contact',
'icon' => '--site-features-email',
'title' => 'Email Newsletters',
'subtitle' => 'Powered by Creative Email',
'desc' => 'A professional logo builder, marketing automations with WooCommerce and social management -- CreativeMail is a whole lot more than mail from Constant Contact.',
'selected' => false,
'shown' => true,
),
'optinmonster' => array(
'slug' => 'optinmonster',
'icon' => '--site-features-lead',
'title' => 'Lead Generation',
'subtitle' => 'Powered by Optin Monster',
'desc' => 'Connect with website visitors using a proven kit of tools for growth using this offering from Awesome Motive.',
'selected' => false,
'shown' => true,
),
'wc_priority' => array(),
),
);
}
'wc_standard' => array(
'yith-woocommerce-ajax-search' => array(
'slug' => 'yith-woocommerce-ajax-search',
'icon' => '--site-features-search',
'title' => 'Enhanced Product Search',
'subtitle' => 'Powered by YITH',
'desc' => 'Give your visitors great search experiences with this exclusive offering from our colleagues at YITH.',
'selected' => false,
'shown' => true,
),
'nfd_slug_yith_woocommerce_ajax_product_filter' => array(
'slug' => 'nfd_slug_yith_woocommerce_ajax_product_filter',
'icon' => '--site-features-filter',
'title' => 'Enhanced Product Filters',
'subtitle' => 'Powered by YITH',
'desc' => 'Give your visitors powerful tools to discover your great products with this exclusive offering from our colleagues at YITH.',
'selected' => false,
'shown' => true,
),
'nfd_slug_yith_woocommerce_booking' => array(
'slug' => 'nfd_slug_yith_woocommerce_booking',
'icon' => '--site-features-bookingcalendar',
'title' => 'Bookings & Appointments',
'subtitle' => 'Powered by YITH',
'desc' => 'Have visitors book meetings and services with you, accepting payment and more using this exclusive offering from our colleagues at YITH.',
'selected' => false,
'shown' => true,
),
'nfd_slug_yith_woocommerce_wishlist' => array(
'slug' => 'nfd_slug_yith_woocommerce_wishlist',
'icon' => '--site-features-wishlist',
'title' => 'Product Wishlists',
'subtitle' => 'Powered by YITH',
'desc' => 'Let discerning shoppers curate their selections with a system of favorites using this exclusive offering from our colleagues at YITH.',
'selected' => false,
'shown' => true,
),
),
'wc_premium' => array(
'yith-woocommerce-ajax-search' => array(
'slug' => 'yith-woocommerce-ajax-search',
'icon' => '--site-features-search',
'title' => 'Enhanced Product Search',
'subtitle' => 'Powered by YITH',
'desc' => 'Give your visitors great search experiences with this exclusive offering from our colleagues at YITH.',
'selected' => false,
'shown' => true,
),
'nfd_slug_yith_woocommerce_ajax_product_filter' => array(
'slug' => 'nfd_slug_yith_woocommerce_ajax_product_filter',
'icon' => '--site-features-filter',
'title' => 'Enhanced Product Filters',
'subtitle' => 'Powered by YITH',
'desc' => 'Give your visitors powerful tools to discover your great products with this exclusive offering from our colleagues at YITH.',
'selected' => false,
'shown' => true,
),
'nfd_slug_yith_woocommerce_booking' => array(
'slug' => 'nfd_slug_yith_woocommerce_booking',
'icon' => '--site-features-bookingcalendar',
'title' => 'Bookings & Appointments',
'subtitle' => 'Powered by YITH',
'desc' => 'Have visitors book meetings and services with you, accepting payment and more using this exclusive offering from our colleagues at YITH.',
'selected' => false,
'shown' => true,
),
'nfd_slug_yith_woocommerce_wishlist' => array(
'slug' => 'nfd_slug_yith_woocommerce_wishlist',
'icon' => '--site-features-wishlist',
'title' => 'Product Wishlists',
'subtitle' => 'Powered by YITH',
'desc' => 'Let discerning shoppers curate their selections with a system of favorites using this exclusive offering from our colleagues at YITH.',
'selected' => false,
'shown' => true,
),
),
'wc_priority' => array(),
),
);

/**
* Based on the flow type initial site features are marked.
* Retrieves all the site features for a particular flow and plan.
*
* @return array
*/
private static function mark_initial_plugins() {
$plan_data = Data::current_plan();
$plan_flow = $plan_data['flow'];
$plan_subtype = $plan_data['subtype'];
$installed_plugins = Plugins::get_init();
public static function get() {
$plan_data = Data::current_plan();
$plan_flow = $plan_data['flow'];
$plan_subtype = $plan_data['subtype'];

$site_features_marked = array();
if ( $plan_flow && isset( self::get_site_features()[ $plan_flow ] ) ) {
if ( isset( self::get_site_features()[ $plan_flow ]['default'] ) ) {
$site_features_marked = array_merge( $site_features_marked, self::get_site_features()[ $plan_flow ]['default'] );
$site_features = array();
if ( $plan_flow && isset( self::$site_features_flow_plan_map[ $plan_flow ] ) ) {
if ( isset( self::$site_features_flow_plan_map[ $plan_flow ]['default'] ) ) {
$site_features = array_merge( $site_features, self::$site_features_flow_plan_map[ $plan_flow ]['default'] );
}
if ( 'default' !== $plan_subtype && isset( self::get_site_features()[ $plan_flow ][ $plan_subtype ] ) ) {
$site_features_marked = array_merge( $site_features_marked, self::get_site_features()[ $plan_flow ][ $plan_subtype ] );
if ( 'default' !== $plan_subtype && isset( self::$site_features_flow_plan_map[ $plan_flow ][ $plan_subtype ] ) ) {
$site_features = array_merge( $site_features, self::$site_features_flow_plan_map[ $plan_flow ][ $plan_subtype ] );
}
}
return $site_features;
}

if ( empty( $site_features_marked ) ) {
/**
* Retrieves all the site features for a particular flow and plan, marks
* each one as selected based on whether it has already been installed
* or is in the install queue.
*
* @return array
*/
public static function get_with_selections() {
$site_features = self::get();
if ( empty( $site_features ) ) {
return array();
}

$installed_plugins = Plugins::get_init();
foreach ( $installed_plugins as $installed_plugin ) {
if ( isset( $site_features_marked[ $installed_plugin['slug'] ] ) ) {
$site_features_marked[ $installed_plugin['slug'] ]['selected'] = true;
if ( isset( $site_features[ $installed_plugin['slug'] ] ) ) {
$site_features[ $installed_plugin['slug'] ]['selected'] = true;
}
}

return $site_features_marked;
return $site_features;
}

/**
* Retrieve marked site features
*
* @return array
*/
public static function get() {
return self::mark_initial_plugins();
}

}
Loading

0 comments on commit 0002a1f

Please sign in to comment.