Skip to content

Commit

Permalink
Add a populate capabilities flag
Browse files Browse the repository at this point in the history
  • Loading branch information
arunshenoy99 committed Oct 28, 2024
1 parent 1c60007 commit 5d51262
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 17 deletions.
20 changes: 12 additions & 8 deletions includes/Brands.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,23 @@ public static function get_default_brand() {
),
);

return array_replace( self::get_brands()['bluehost'], $default_brand_data );
return array_replace( self::get_brands( false )['bluehost'], $default_brand_data );
}

/**
* Brand specific data - Bluehost, Bluehost India, Webcom
* Retrieve brand-specific data for various brands such as Bluehost, Bluehost India, Web.com, etc.
*
* @return array
* @param bool $populate_capabilities Optional. Determines whether capabilities such as `has_ai_sitegen`
* and `can_migrate_site` should be populated for each brand. Defaults to true.
*
* @return array Associative array containing configuration details for each brand, including links,
* contact information, and enabled features. Capabilities are set based on the
* $populate_capabilities argument.
*/
public static function get_brands() {

public static function get_brands( $populate_capabilities = true ) {
// Checks if customer has acess to AI Sitegen.
$has_ai_sitegen = Config::has_ai_sitegen();
$can_migrate_site = Config::can_migrate_site();
$has_ai_sitegen = $populate_capabilities ? Config::has_ai_sitegen() : false;
$can_migrate_site = $populate_capabilities ? Config::can_migrate_site() : false;

return array(
'bluehost' => array(
Expand Down Expand Up @@ -489,7 +493,7 @@ public static function set_current_brand( $container ) {
if ( ! defined( 'NFD_ONBOARDING_PLUGIN_BRAND' ) ) {
$brand = $container->plugin()->brand;
if ( empty( $brand ) ) {
$brand = 'wordpress';
$brand = 'WordPress';
}

if ( false !== stripos( $brand, 'hostgator' ) ) {
Expand Down
12 changes: 8 additions & 4 deletions includes/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,16 @@ public static function runtime() {
}

/**
* Establish brand to apply to Onboarding experience.
* Establish the brand to apply to the Onboarding experience.
*
* @return array
* @param bool $populate_capabilities Optional. Determines whether capabilities should be populated
* for the selected brand. Defaults to true.
*
* @return array The configuration array of the current brand. If the specified brand is not found,
* returns the default brand configuration.
*/
public static function current_brand() {
$brands = Brands::get_brands();
public static function current_brand( $populate_capabilities = true ) {
$brands = Brands::get_brands( $populate_capabilities );

return array_key_exists( NFD_ONBOARDING_PLUGIN_BRAND, $brands ) ?
$brands[ NFD_ONBOARDING_PLUGIN_BRAND ] :
Expand Down
15 changes: 10 additions & 5 deletions includes/Flows/Flows.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ final class Flows {
),

'continueWithoutAi' => false,
'sitegenThemeMode' => '',
'sitegenThemeMode' => '',
);

/**
Expand Down Expand Up @@ -220,11 +220,16 @@ public static function get_default_flow() {
/**
* 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.
* @param bool $populate_capabilities Optional. Determines whether capabilities should be populated
* for the current brand. Defaults to true.
*
* @return array Associative array of onboarding flows. A value of true for each key indicates that the
* flow has been approved. A value of null indicates the flow has not been approved or has
* been temporarily disabled. If no enabled flows are found, default flows are provided with
* a value of false.
*/
public static function get_flows() {
$current_brand = Data::current_brand();
public static function get_flows( $populate_capabilities = true ) {
$current_brand = Data::current_brand( $populate_capabilities );
return isset( $current_brand['config']['enabled_flows'] )
? $current_brand['config']['enabled_flows'] : array(
'wp-setup' => false,
Expand Down

0 comments on commit 5d51262

Please sign in to comment.