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

Enhance General Onboarding #212

Merged
merged 16 commits into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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
28 changes: 22 additions & 6 deletions includes/Data/Brands.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ final class Brands {
*/
public static function get_default_brand() {
$default_brand_data = array(
'brand' => 'wordpress',
'name' => __( 'your web host', 'wp-module-onboarding' ),
'pluginDashboardPage' => \admin_url(),
'hireExpertsInfo' => array(
'brand' => 'wordpress',
'name' => __( 'your web host', 'wp-module-onboarding' ),
'pluginDashboardPage' => \admin_url(),
'hireExpertsInfo' => array(
'defaultLink' => 'https://www.bluehost.com/wp-live',
'queryParameters' => array(
'page' => 'bluehost',
Expand Down Expand Up @@ -92,7 +92,11 @@ public static function get_brands() {
),
),
'config' => array(
'net_new_signup_date_threshold' => '2022-08-18T15:30:00.000Z',
'net_new_signup_date_threshold' => '2023-05-04T00:00:00.000Z',
'enabled_flows' => array(
'ecommerce' => true,
'wp-setup' => true,
),
),
),
'bluehost-india' => array(
Expand Down Expand Up @@ -146,6 +150,10 @@ public static function get_brands() {
),
'config' => array(
'net_new_signup_date_threshold' => '2022-08-18T15:30:00.000Z',
'enabled_flows' => array(
'ecommerce' => true,
'wp-setup' => false,
),
),
),
'webcom' => array(
Expand Down Expand Up @@ -200,6 +208,10 @@ public static function get_brands() {
),
'config' => array(
'net_new_signup_date_threshold' => '2022-08-18T15:30:00.000Z',
'enabled_flows' => array(
'ecommerce' => false,
'wp-setup' => false,
),
),
),
'crazy-domains' => array(
Expand Down Expand Up @@ -253,7 +265,11 @@ public static function get_brands() {
),
),
'config' => array(
'net_new_signup_date_threshold' => '2022-08-18T15:30:00.000Z',
'net_new_signup_date_threshold' => '2023-05-04T00:00:00.000Z',
'enabled_flows' => array(
'ecommerce' => true,
'wp-setup' => true,
),
'views' => array(
'sidebar' => array(
'illustration' => array(
Expand Down
29 changes: 11 additions & 18 deletions includes/Data/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ public static function current_plan() {
}
}

$current_flow = Flows::get_flow_from_top_priority();
if ( false !== $current_flow ) {
return array(
'flow' => 'ecommerce',
'subtype' => 'wc_priority',
'type' => null,
);
}

return array(
'flow' => Flows::get_default_flow(),
'subtype' => null,
Expand All @@ -93,24 +102,8 @@ public static function current_plan() {
* @return string
*/
public static function current_flow() {

$current_flow = Flows::get_flow_from_params();
if ( false !== $current_flow ) {
return $current_flow;
}

$current_flow = Flows::get_flow_from_plugins();
if ( false !== $current_flow ) {
return $current_flow;
}

$customer_data = self::customer_data();
$current_flow = Flows::get_flow_from_customer_data( $customer_data );
if ( false !== $current_flow ) {
return $current_flow;
}

return Flows::get_default_flow();
$current_plan = self::current_plan();
return $current_plan['flow'];
}

/**
Expand Down
45 changes: 30 additions & 15 deletions includes/Data/Flows.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\Services\FlowService;
use NewfoldLabs\WP\Module\Onboarding\Services\PluginInstaller;

/**
Expand Down Expand Up @@ -147,11 +148,11 @@ final class Flows {
),
);

/**
* Get Onboarding Flow information.
*
* @return array
*/
/**
* Get Onboarding Flow information.
*
* @return array
*/
public static function get_data() {
return self::$data;
}
Expand All @@ -162,7 +163,7 @@ public static function get_data() {
* @return string
*/
public static function get_default_flow() {
return 'wp-setup';
return 'wp-setup';
}

/**
Expand All @@ -172,9 +173,11 @@ public static function get_default_flow() {
* and a value of null indicates the flow has not been approved (or) has been temporarily disabled.
*/
public static function get_flows() {
return array(
'wp-setup' => true,
'ecommerce' => true,
$current_brand = Data::current_brand();
return isset( $current_brand['config']['enabled_flows'] )
? $current_brand['config']['enabled_flows'] : array(
'wp-setup' => false,
'ecommerce' => false,
);
}

Expand Down Expand Up @@ -212,15 +215,15 @@ public static function get_flow_from_params() {
$flows = self::get_flows();

if ( isset( $_GET['flow'] ) ) {
$current_flow_type = \sanitize_text_field( $_GET['flow'] );
$current_flow_type = \sanitize_text_field( $_GET['flow'] );
}

if ( ! empty( $current_flow_type ) && isset( $flows[ $current_flow_type ] ) ) {
if ( ! empty( $current_flow_type ) && true === $flows[ $current_flow_type ] ) {
return $current_flow_type;
}

$current_flow_type = \get_option( Options::get_option_name( 'flow_preset' ), false );
if ( $current_flow_type && isset( $flows[ $current_flow_type ] ) ) {
if ( $current_flow_type && true === $flows[ $current_flow_type ] ) {
return $current_flow_type;
}

Expand All @@ -234,7 +237,7 @@ public static function get_flow_from_params() {
*/
public static function get_flow_from_plugins() {
if ( PluginInstaller::exists( 'woocommerce', true ) ) {
return 'ecommerce';
return true === self::get_flows()['ecommerce'] ? 'ecommerce' : false;
}
return false;
}
Expand All @@ -260,8 +263,20 @@ public static function get_flow_from_customer_data( $customer_data = array() ) {
*/
public static function get_flow_from_plan_subtype( $plan_subtype ) {
if ( self::is_ecommerce_plan( $plan_subtype ) ) {
return isset( self::get_flows()['ecommerce'] ) ? 'ecommerce' : false;
return true === self::get_flows()['ecommerce'] ? 'ecommerce' : false;
}
return false;
return false;
}
/**
* Get the corresponding flow from the top priority in flow data.
*
* @return string|boolean
*/
public static function get_flow_from_top_priority() {
$flow_data = FlowService::read_data_from_wp_option();
if ( $flow_data && isset( $flow_data['data']['topPriority']['priority1'] ) && 'selling' === $flow_data['data']['topPriority']['priority1'] ) {
return true === self::get_flows()['ecommerce'] ? 'ecommerce' : false;
}
return false;
}
}
14 changes: 12 additions & 2 deletions includes/Data/Plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ final class Plugins {
'path' => 'jetpack/jetpack.php',
),
'woocommerce' => array(
'approved' => true,
'path' => 'woocommerce/woocommerce.php',
'approved' => true,
'path' => 'woocommerce/woocommerce.php',
'post_install_callback' => array( __CLASS__, 'wc_prevent_redirect_on_activation' ),
),
'wordpress-seo' => array(
'approved' => true,
Expand Down Expand Up @@ -420,4 +421,13 @@ public static function get_init() {
return $init_list;
}

/**
* Prevent redirect to woo wizard after activation of woocommerce.
*
* @return void
*/
public static function wc_prevent_redirect_on_activation() {
\delete_transient( '_wc_activation_redirect' );
}

}
55 changes: 41 additions & 14 deletions includes/Data/Preview.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,25 @@
use NewfoldLabs\WP\Module\Onboarding\Services\PluginInstaller;
use NewfoldLabs\WP\Module\Onboarding\Services\ThemeInstaller;

/**
* Class Preview
*/
final class Preview {

/**
* Convert boolean to plugin/theme status.
*
* @param boolean $boolean The boolean value.
* @return string
*/
private static function boolean_to_status( $boolean ) {
return $boolean ? 'activated' : 'init';
return $boolean ? 'activated' : 'init';
}

/**
* Map of pre requisites to show the live preview successfully for a flow.
*
* @return array
*/
private static function pre_requisites() {
$theme_map = Themes::get();
return array(
Expand All @@ -30,21 +43,35 @@ private static function pre_requisites() {
);
}

public static function get_pre_requisites() {
$pre_requisites = self::pre_requisites();
return isset( $pre_requisites[ Data::current_flow() ] ) ? $pre_requisites[ Data::current_flow() ] : array();
/**
* Get the pre requisites for a given flow.
*
* @param string $flow A valid Onboarding flow.
* @return array
*/
public static function get_pre_requisites( $flow = null ) {
$pre_requisites = self::pre_requisites();
if ( ! isset( $flow ) ) {
$flow = Data::current_flow();
}
return isset( $pre_requisites[ $flow ] ) ? $pre_requisites[ $flow ] : array();
}

/**
* Get all the settings necessary to load the live preview
*
* @return array
*/
public static function get_settings() {
$block_editor_context = new \WP_Block_Editor_Context( array( 'name' => 'core/edit-site' ) );
$custom_settings = array(
'siteUrl' => \site_url(),
);
$block_editor_context = new \WP_Block_Editor_Context( array( 'name' => 'core/edit-site' ) );
$custom_settings = array(
'siteUrl' => \site_url(),
);

return array(
'settings' => \get_block_editor_settings( $custom_settings, $block_editor_context ),
'globalStyles' => \wp_get_global_styles(),
'preRequisites' => self::get_pre_requisites(),
);
return array(
'settings' => \get_block_editor_settings( $custom_settings, $block_editor_context ),
'globalStyles' => \wp_get_global_styles(),
'preRequisites' => self::get_pre_requisites(),
);
}
}
Loading