Skip to content

Commit

Permalink
Merge pull request #244 from newfold-labs/add/installer-module
Browse files Browse the repository at this point in the history
Refactor onboarding to use the installer module
  • Loading branch information
arunshenoy99 authored Jun 5, 2023
2 parents 2e1da29 + 2bf5da5 commit 3a23d72
Show file tree
Hide file tree
Showing 35 changed files with 235 additions and 2,555 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
],
"require": {
"mustache/mustache": "~2.5",
"wp-cli/wp-config-transformer": "~1.3.0"
"wp-cli/wp-config-transformer": "~1.3.0",
"newfold-labs/wp-module-installer": "^1.0.0"
},
"require-dev": {
"wp-phpunit/wp-phpunit": "^5.9",
Expand Down
44 changes: 43 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions includes/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use NewfoldLabs\WP\ModuleLoader\Container;
use NewfoldLabs\WP\Module\Onboarding\Data\Options;
use function NewfoldLabs\WP\ModuleLoader\container;
use NewfoldLabs\WP\Module\Onboarding\TaskManagers\TaskManager;

/**
* Primary instantiation of Onboarding Application.
Expand Down Expand Up @@ -64,8 +63,6 @@ public function __construct( Container $container ) {

new RestAPI();

new TaskManager();

if ( defined( '\\WP_CLI' ) && \WP_CLI ) {
new WP_CLI();
}
Expand Down
4 changes: 2 additions & 2 deletions includes/Data/Data.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
namespace NewfoldLabs\WP\Module\Onboarding\Data;

use NewfoldLabs\WP\Module\Onboarding\Permissions;
use NewfoldLabs\WP\Module\CustomerBluehost\CustomerBluehost;
use NewfoldLabs\WP\Module\Installer\Services\PluginInstaller;

/**
* CRUD methods for Onboarding config for use in API, CLI and runtime.
Expand All @@ -20,7 +20,7 @@ public static function runtime() {
'currentBrand' => self::current_brand(),
'currentPlan' => self::current_plan(),
'currentFlow' => self::current_flow(),
'pluginInstallHash' => Permissions::rest_get_plugin_install_hash(),
'pluginInstallHash' => PluginInstaller::rest_get_plugin_install_hash(),
'previewSettings' => array(
'settings' => Preview::get_settings(),
'stepPreviewData' => Themes::step_preview_data(),
Expand Down
2 changes: 1 addition & 1 deletion includes/Data/Flows.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
namespace NewfoldLabs\WP\Module\Onboarding\Data;

use NewfoldLabs\WP\Module\Onboarding\Services\FlowService;
use NewfoldLabs\WP\Module\Onboarding\Services\PluginInstaller;
use NewfoldLabs\WP\Module\Installer\Services\PluginInstaller;

/**
* Contains Onboarding Flow information.
Expand Down
5 changes: 0 additions & 5 deletions includes/Data/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,7 @@ final class Options {
'auto_update_theme' => 'auto_update_theme',
'permalink_structure' => 'permalink_structure',
'settings_initialized' => 'settings_initialized',
'plugins_init_status' => 'plugins_init_status',
'plugin_install_queue' => 'plugin_install_queue',
'plugin_uninstall_queue' => 'plugin_uninstall_queue',
'flow' => 'flow',
'theme_init_status' => 'theme_init_status',
'theme_install_queue' => 'theme_install_queue',
'blog_name' => 'blogname',
'blog_description' => 'blogdescription',
'site_icon' => 'site_icon',
Expand Down
197 changes: 0 additions & 197 deletions includes/Data/Plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,107 +5,6 @@
* List of Plugin Slugs/URLs/Domains
*/
final class Plugins {
/**
* A value of true indicates that the slug/url/domain has been approved.
* A value of null indicates that the slug/url/domain has not been approved
* (or) has been temporarily deactivated.
*
* @var array
*/
protected static $wp_slugs = array(
'jetpack' => array(
'approved' => true,
'path' => 'jetpack/jetpack.php',
),
'woocommerce' => array(
'approved' => true,
'path' => 'woocommerce/woocommerce.php',
'post_install_callback' => array( __CLASS__, 'wc_prevent_redirect_on_activation' ),
),
'wordpress-seo' => array(
'approved' => true,
'path' => 'wordpress-seo/wp-seo.php',
),
'wpforms-lite' => array(
'approved' => true,
'path' => 'wpforms-lite/wpforms.php',
),
'google-analytics-for-wordpress' => array(
'approved' => true,
'path' => 'google-analytics-for-wordpress/googleanalytics.php',
),
'optinmonster' => array(
'approved' => true,
'path' => 'optinmonster/optin-monster-wp-api.php',
),
'yith-woocommerce-ajax-search' => array(
'approved' => true,
'path' => 'yith-woocommerce-ajax-search/init.php',
),
'creative-mail-by-constant-contact' => array(
'approved' => true,
'path' => 'creative-mail-by-constant-contact/creative-mail-plugin.php',
),
);

/**
* Contains a list of zip url's with a unique "nfd_slug" for each.
*
* @var array
*/
protected static $nfd_slugs = array(
'nfd_slug_endurance_page_cache' => array(
'approved' => true,
'url' => 'https://raw.githubusercontent.com/bluehost/endurance-page-cache/production/endurance-page-cache.php',
'path' => WP_CONTENT_DIR . '/mu-plugins/endurance-page-cache.php',
),
'nfd_slug_yith_woocommerce_customize_myaccount_page' => array(
'approved' => true,
'url' => 'https://hiive.cloud/workers/plugin-downloads/yith-woocommerce-customize-myaccount-page',
'path' => 'yith-woocommerce-customize-myaccount-page-extended/init.php',
),
'nfd_slug_yith_woocommerce_gift_cards' => array(
'approved' => true,
'url' => 'https://hiive.cloud/workers/plugin-downloads/yith-woocommerce-gift-cards',
'path' => 'yith-woocommerce-gift-cards-extended/init.php',
),
'nfd_slug_ecomdash_wordpress_plugin' => array(
'approved' => true,
'url' => 'https://hiive.cloud/workers/plugin-downloads/ecomdash-wordpress-plugin',
'path' => 'ecomdash-wordpress-plugin/ecomdash-plugin.php',
),
'nfd_slug_yith_paypal_payments_for_woocommerce' => array(
'approved' => true,
'url' => 'https://hiive.cloud/workers/plugin-downloads/yith-paypal-payments-for-woocommerce',
'path' => 'yith-paypal-payments-for-woocommerce-extended/init.php',
),
'nfd_slug_yith_shippo_shippings_for_woocommerce' => array(
'approved' => true,
'url' => 'https://hiive.cloud/workers/plugin-downloads/yith-shippo-shippings-for-woocommerce',
'path' => 'yith-shippo-shippings-for-woocommerce-extended/init.php',
),
'nfd_slug_yith_woocommerce_ajax_product_filter' => array(
'approved' => true,
'url' => 'https://hiive.cloud/workers/plugin-downloads/yith-woocommerce-ajax-product-filter',
'path' => 'yith-woocommerce-ajax-product-filter-extended/init.php',
),
'nfd_slug_yith_woocommerce_booking' => array(
'approved' => true,
'url' => 'https://hiive.cloud/workers/plugin-downloads/yith-woocommerce-booking',
'path' => 'yith-woocommerce-booking-extended/init.php',
),
'nfd_slug_yith_woocommerce_wishlist' => array(
'approved' => true,
'url' => 'https://hiive.cloud/workers/plugin-downloads/yith-woocommerce-wishlist',
'path' => 'yith-woocommerce-wishlist-extended/init.php',
),
'nfd_slug_woo_razorpay' => array(
'approved' => true,
'url' => 'https://hiive.cloud/workers/plugin-downloads/razorpay',
'path' => 'woo-razorpay/woo-razorpay.php',
),
);

/**
* Initial plugins to be installed classified based on the hosting plan.
* Key 'default' contains a list of default plugins to be installed irrespective of the plan.
Expand Down Expand Up @@ -302,102 +201,6 @@ final class Plugins {
),
);

// [TODO] Think about deprecating this approach and move to nfd_slugs for url based installs.
/**
* Contains a whitelist of zip url's.
*
* @var array
*/
protected static $urls = array(
'https://downloads.wordpress.org/plugin/google-analytics-for-wordpress.8.5.3.zip' => true,
);
/**
* Contains a list of approved domains for zip based installs.
*
* @var array
*/
protected static $domains = array(
'downloads.wordpress.org' => true,
'nonapproveddomain.com' => null,
);

/**
* Returns a list of whitelisted WordPress Plugin slugs.
*
* @return array
*/
public static function get_wp_slugs() {
return self::$wp_slugs;
}

/**
* Returns a list of whitelisted Plugin URL's.
*
* @return array
*/
public static function get_urls() {
return self::$urls;
}

/**
* Returns a list of whitelisted Plugin URL domains.
*
* @return array
*/
public static function get_domains() {
return self::$domains;
}

/**
* Use this return value for a faster search of slug/url/domain.
*
* @return array
*/
public static function get() {
return array(
'wp_slugs' => self::$wp_slugs,
'nfd_slugs' => self::$nfd_slugs,
'urls' => self::$urls,
'domains' => self::$domains,
);
}

/**
* Use this for finding the path for installed plugins.
*
* @return array
*/
public static function get_squashed() {
return array_merge(
array_filter( self::$wp_slugs, array( __CLASS__, 'check_approved' ) ),
array_filter( self::$nfd_slugs, array( __CLASS__, 'check_approved' ) )
);
}

/**
* Get approved slugs/urls/domains
*
* @return array
*/
public static function get_approved() {
return array(
'wp_slugs' => array_keys( array_filter( self::$wp_slugs, array( __CLASS__, 'check_approved' ) ) ),
'nfd_slugs' => array_keys( array_filter( self::$nfd_slugs, array( __CLASS__, 'check_approved' ) ) ),
'urls' => array_keys( self::$urls, true, true ),
'domains' => array_keys( self::$domains, true, true ),
);
}

/**
* Checks if a Plugin slug has been approved.
*
* @param array $value The Plugin slug that will be checked.
* @return boolean
*/
private static function check_approved( $value ) {
return true === $value['approved'];
}

/**
* Get the list of initial plugins to be installed for a particular hosting plan.
*
Expand Down
5 changes: 3 additions & 2 deletions includes/Data/Preview.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php
namespace NewfoldLabs\WP\Module\Onboarding\Data;

use NewfoldLabs\WP\Module\Onboarding\Services\PluginInstaller;
use NewfoldLabs\WP\Module\Onboarding\Services\ThemeInstaller;
use NewfoldLabs\WP\Module\Installer\Data\Themes;
use NewfoldLabs\WP\Module\Installer\Services\PluginInstaller;
use NewfoldLabs\WP\Module\Installer\Services\ThemeInstaller;

/**
* Class Preview
Expand Down
Loading

0 comments on commit 3a23d72

Please sign in to comment.