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

Solutions #32

Merged
merged 78 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
7093f12
Making it work
officiallygod Oct 10, 2024
f5a783c
More
officiallygod Oct 10, 2024
5da675a
Code
officiallygod Oct 10, 2024
76da00c
Update index.jsx
officiallygod Oct 10, 2024
56bbf03
Code Dump
officiallygod Oct 10, 2024
5dc96ac
Update index.jsx
officiallygod Oct 10, 2024
3ce7001
Update stylesheet.scss
officiallygod Oct 10, 2024
1ca2b09
Something
officiallygod Oct 10, 2024
e9f1d6c
Update installer.js
officiallygod Oct 10, 2024
1b2b339
tweak error state
circlecube Oct 10, 2024
2f855de
version bump to beta.2 and update build files
circlecube Oct 10, 2024
b19c54d
remove html from error state (for now)
circlecube Oct 10, 2024
bf5b754
Update dataAttrListener.js
officiallygod Oct 14, 2024
cffa06c
Add Support for Premium Plugin Activations
arunshenoy99 Oct 14, 2024
10e2a25
Updates
arunshenoy99 Oct 14, 2024
f0e519a
Use activated_plugin
arunshenoy99 Oct 14, 2024
fd38ffc
Hooks
officiallygod Oct 14, 2024
9de51c8
Build
officiallygod Oct 14, 2024
b114923
Update InstallerListener.php
officiallygod Oct 14, 2024
443b90a
Remove unncessary check
arunshenoy99 Oct 14, 2024
1496c5e
Add Contact Support Button
officiallygod Oct 15, 2024
d324f9f
Better Icon
officiallygod Oct 15, 2024
14f86d4
Minor changes to support PLS, add provider, lint fixes
arunshenoy99 Oct 15, 2024
609adbd
Remove whitespace
arunshenoy99 Oct 15, 2024
cd1f05b
Update WP CLI command
arunshenoy99 Oct 15, 2024
5e2c0d9
Merge branch 'enhance/activate-premium-plugin' into integration
wpscholar Oct 15, 2024
e50544c
Add .nvmrc
wpscholar Oct 15, 2024
9e95820
Update NPM deps
wpscholar Oct 15, 2024
75bafe9
Restore data attribute listener
wpscholar Oct 15, 2024
b4f3c71
Run build
wpscholar Oct 15, 2024
e2f7b4f
Code formatting and use createInterpolateElement to handle translatio…
wpscholar Oct 15, 2024
70d6fee
Prevent the icon from shrinking
wpscholar Oct 15, 2024
cdcceed
Update build
wpscholar Oct 16, 2024
235d62f
Update code formatting
wpscholar Oct 16, 2024
5829925
Simplify logic
wpscholar Oct 16, 2024
d9aad9a
Remove blank line
wpscholar Oct 16, 2024
edf027c
Clean up code
wpscholar Oct 16, 2024
21d02a7
Ran build
wpscholar Oct 16, 2024
ac07e70
Bump version
wpscholar Oct 16, 2024
23a14c1
Update PLS data attributes
arunshenoy99 Oct 16, 2024
c1bc771
Fix lint
arunshenoy99 Oct 16, 2024
7eb5301
Fix version numbers
wpscholar Oct 16, 2024
d8a9950
Merge pull request #27 from newfold-labs/rename/data-attributes
wpscholar Oct 16, 2024
8951a26
Production build
wpscholar Oct 16, 2024
50cfa0b
Add free plugin installation
arunshenoy99 Oct 17, 2024
d66d19b
Merge pull request #29 from newfold-labs/add/free-plugin-installation
arunshenoy99 Oct 17, 2024
889a796
Update build
arunshenoy99 Oct 17, 2024
8dcfc79
Missed Changes
officiallygod Oct 17, 2024
e2ac73d
Revert "Missed Changes"
officiallygod Oct 17, 2024
ebe2643
Update DataAttrListener.php
officiallygod Oct 17, 2024
a8d7b44
Fix free plugin checks
arunshenoy99 Oct 17, 2024
9e63255
Merge pull request #30 from newfold-labs/fix/minor-changes
arunshenoy99 Oct 17, 2024
c030396
Merge pull request #31 from newfold-labs/fix/free-plugin-checks
arunshenoy99 Oct 17, 2024
8d513d6
Update build
arunshenoy99 Oct 17, 2024
e3dd0b6
Update slugs based on staging Hiive data
arunshenoy99 Oct 18, 2024
f6f68f4
Update usage of PLSUtility
arunshenoy99 Oct 18, 2024
bdedba9
Exclude build from lint checks
arunshenoy99 Oct 18, 2024
0de9578
Close modal on Contact Support
officiallygod Oct 21, 2024
7febf2a
Fix Redirect Issue
officiallygod Oct 21, 2024
ac5c53b
Efficient
officiallygod Oct 21, 2024
8a0f103
Merge pull request #33 from newfold-labs/enhance/fix-modal-bugs
circlecube Oct 21, 2024
9a5bfee
Conditional logic based on plugin status
arunshenoy99 Oct 22, 2024
d6e8156
remove duplicate functions
arunshenoy99 Oct 22, 2024
0e7e57b
fix lint
arunshenoy99 Oct 22, 2024
6de9917
Reorder check
arunshenoy99 Oct 22, 2024
d4df2e0
hide modal once installation is completed
arunshenoy99 Oct 22, 2024
d9ef7e3
Merge pull request #35 from newfold-labs/add/activation-checks
arunshenoy99 Oct 22, 2024
569bcdf
Update to beta 4
arunshenoy99 Oct 22, 2024
38b3342
Update to beta 6
arunshenoy99 Oct 22, 2024
079a320
Whitelist hiive domain
arunshenoy99 Oct 22, 2024
8cad4a3
Install dependent entitlements first
arunshenoy99 Oct 22, 2024
e600fef
Merge pull request #36 from newfold-labs/add/dependant-entitlements
arunshenoy99 Oct 22, 2024
538155e
Update build and PLS
arunshenoy99 Oct 22, 2024
65878f2
Update constant
arunshenoy99 Oct 22, 2024
b0cded2
Update YITH upgrade commands
arunshenoy99 Oct 23, 2024
d9fad7a
reorder slugs
arunshenoy99 Oct 23, 2024
0e228cc
Merge pull request #37 from newfold-labs/update/wp-cli-command
arunshenoy99 Oct 23, 2024
e92e6bb
Update
arunshenoy99 Oct 23, 2024
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
2 changes: 2 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ on:
push:
paths:
- '**.php'
- '!build/**/*.php'
pull_request:
types: [opened, edited, reopened, ready_for_review]
paths:
- '**.php'
- '!build/**/*.php'
workflow_dispatch:

concurrency:
Expand Down
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v20
1 change: 0 additions & 1 deletion build/1.2.0-beta/dataAttrListener.asset.php

This file was deleted.

1 change: 0 additions & 1 deletion build/1.2.0-beta/dataAttrListener.js

This file was deleted.

1 change: 1 addition & 0 deletions build/1.2.0/dataAttrListener.asset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php return array('dependencies' => array('wp-dom-ready'), 'version' => 'b208b9a3938b304abbde');
1 change: 1 addition & 0 deletions build/1.2.0/dataAttrListener.js

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

1 change: 1 addition & 0 deletions build/1.2.0/installer.asset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php return array('dependencies' => array('react', 'wp-api-fetch', 'wp-dom-ready', 'wp-element', 'wp-i18n'), 'version' => '0374e667fa1f111980fb');
1 change: 1 addition & 0 deletions build/1.2.0/installer.css

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

2 changes: 2 additions & 0 deletions build/1.2.0/installer.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
}
},
"require": {
"newfold-labs/wp-module-pls": "^0.1.0"
"newfold-labs/wp-module-pls": "^0.2.0"
},
"require-dev": {
"wp-cli/wp-cli": "^2.11",
Expand Down
14 changes: 7 additions & 7 deletions composer.lock

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

2 changes: 1 addition & 1 deletion includes/Data/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Constants {
*/
public function __construct( $container ) {
if ( ! defined( 'NFD_INSTALLER_VERSION' ) ) {
define( 'NFD_INSTALLER_VERSION', '1.2.0-beta' );
define( 'NFD_INSTALLER_VERSION', '1.2.0-beta.7' );
}
if ( ! defined( 'NFD_INSTALLER_BUILD_DIR' ) && defined( 'NFD_INSTALLER_VERSION' ) ) {
define( 'NFD_INSTALLER_BUILD_DIR', dirname( __DIR__, 2 ) . '/build/' . NFD_INSTALLER_VERSION );
Expand Down
1 change: 1 addition & 0 deletions includes/Data/Plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ final class Plugins {
protected static $domains = array(
'downloads.wordpress.org' => true,
'nonapproveddomain.com' => null,
'hiive.cloud' => true,
);
/**
* Holds the possible status codes for a plugin.
Expand Down
17 changes: 11 additions & 6 deletions includes/RestApi/PluginsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,18 @@ public function get_install_plugin_args() {
'type' => 'boolean',
'default' => false,
),
'provider' => array(
'type' => 'string',
'default' => '',
),
);
}

/**
* Get args for the uninstall route.
*
* @return array
*/
/**
* Get args for the uninstall route.
*
* @return array
*/
public function get_uninstall_plugin_args() {
return array(
'plugin' => array(
Expand Down Expand Up @@ -183,10 +187,11 @@ public function install( \WP_REST_Request $request ) {
$queue = $request->get_param( 'queue' );
$priority = $request->get_param( 'priority' );
$premium = $request->get_param( 'premium' );
$provider = $request->get_param( 'provider' );

// Checks if the plugin is premium and uses the corresponding function for it.
if ( true === $premium ) {
return PluginInstaller::install_premium_plugin( $plugin, $activate );
return PluginInstaller::install_premium_plugin( $plugin, $provider, $activate );
}

// Checks if a plugin with the given slug and activation criteria already exists.
Expand Down
69 changes: 56 additions & 13 deletions includes/Services/PluginInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,42 +156,85 @@ public static function install_from_wordpress( $plugin, $activate ) {
* Provisions a license and installs or activates a premium plugin.
*
* @param string $plugin The slug of the premium plugin.
* @param string $provider The provider name for the premium plugin.
* @param boolean $activate Whether to activate the plugin after installation.
*
* @return \WP_Error|\WP_REST_Response
*/
public static function install_premium_plugin( $plugin, $activate ) {
$status_codes = Plugins::get_status_codes();
public static function install_premium_plugin( $plugin, $provider, $activate ) {
// Ensure plugin and provider are not empty
if ( empty( $plugin ) || empty( $provider ) ) {
return new \WP_Error(
'nfd_installer_error',
__( 'Plugin slug and provider name cannot be empty.', 'wp-module-installer' )
);
}

$pls_utility = new PLSUtility();

// Provision a license for the premium plugin, this returns basename and download URL
$license_response = $pls_utility->provision_license( $plugin, $provider );
if ( is_wp_error( $license_response ) ) {
return $license_response;
}

$premium_status = self::get_plugin_status( $plugin );
// Get the plugin basename from the license response
$plugin_basename = ! empty( $license_response['basename'] ) ? $license_response['basename'] : false;

// Check if the plugin is already installed
if ( $plugin_basename && self::is_plugin_installed( $plugin_basename ) ) {
// Check if the plugin is active
if ( is_plugin_active( $plugin_basename ) ) {
// If plugin is already installed and active, return success
return new \WP_REST_Response(
array(
'message' => __( 'Plugin is already installed and active: ', 'wp-module-installer' ) . $plugin,
),
200
);
}

// Check if the premium plugin is already installed or active
if ( $status_codes['active'] === $premium_status || $status_codes['installed'] === $premium_status ) {
// Activate the plugin if it's installed but not active
$activate_plugin_response = activate_plugin( $plugin_basename );
if ( is_wp_error( $activate_plugin_response ) ) {
return new \WP_Error( 'nfd_installer_error', __( 'Failed to activate the plugin: ', 'wp-module-installer' ) . $plugin );
}

// Activate the license
$activation_response = $pls_utility->activate_license( $plugin );
if ( is_wp_error( $activation_response ) ) {
return new \WP_Error( 'nfd_installer_error', __( 'Failed to activate the license for the premium plugin: ', 'wp-module-installer' ) . $plugin );
}

// Return success response
return new \WP_REST_Response(
array(
'message' => __( 'Premium plugin already installed or active: ', 'wp-module-installer' ) . $plugin,
'message' => __( 'Successfully provisioned and installed: ', 'wp-module-installer' ) . $plugin,
),
200
);
}

// Provision a license for the premium plugin
$license_response = PLSUtility::provision_license( $plugin );
if ( is_wp_error( $license_response ) ) {
return $license_response;
}

// Check if the download URL is present in the license response
if ( empty( $license_response['downloadUrl'] ) ) {
return new \WP_Error( 'nfd_installer_error', __( 'Download URL is missing for premium plugin: ', 'wp-module-installer' ) . $plugin );
}

// Attempt to install and/or activate the premium plugin using the provided download URL
// Plugin is not installed, proceed with installation
$install_status = self::install_from_zip( $license_response['downloadUrl'], $activate );
if ( is_wp_error( $install_status ) ) {
return new \WP_Error( 'nfd_installer_error', __( 'Failed to install or activate the premium plugin: ', 'wp-module-installer' ) . $plugin );
}

// If activation is requested, activate the license
if ( $activate ) {
$activation_response = $pls_utility->activate_license( $plugin );
if ( is_wp_error( $activation_response ) ) {
return new \WP_Error( 'nfd_installer_error', __( 'Failed to activate the license for the premium plugin: ', 'wp-module-installer' ) . $plugin );
}
}

// Return success response
return new \WP_REST_Response(
array(
'message' => __( 'Successfully provisioned and installed: ', 'wp-module-installer' ) . $plugin,
Expand Down
57 changes: 22 additions & 35 deletions includes/Services/PluginUpgrader.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ class PluginUpgrader {
public static function upgrade_extended_yith_plugins() {
// Define the list of extended YITH plugins to upgrade.
$yith_plugins_to_upgrade = array(
'yith-woocommerce-ajax-search',
'nfd_slug_yith_woocommerce_ajax_product_filter',
'nfd_slug_yith_woocommerce_wishlist',
'nfd_slug_yith_woocommerce_booking',
'nfd_slug_yith_woocommerce_gift_cards',
'nfd_slug_yith_woocommerce_customize_myaccount_page',
'yith-woocommerce-ajax-search',
);

// Array to store the status of each plugin's upgrade process
Expand All @@ -47,14 +47,13 @@ public static function upgrade_extended_yith_plugins() {
*/
public static function upgrade_extended_yith_plugin( $extended_slug ) {
// Define the list of extended YITH plugins and their corresponding premium versions.
// TODO: Replace the dummy entitlement slug 'nfd_slug_yith_paypal_payments_for_woocommerce' with actual entitlement slugs.
$yith_plugins_to_upgrade = array(
'yith-woocommerce-ajax-search' => 'nfd_slug_yith_paypal_payments_for_woocommerce',
'nfd_slug_yith_woocommerce_ajax_product_filter' => 'yith-woocommerce-ajax-product-filter-premium',
'nfd_slug_yith_woocommerce_wishlist' => 'yith-woocommerce-wishlist-premium',
'nfd_slug_yith_woocommerce_booking' => 'yith-woocommerce-booking-premium',
'nfd_slug_yith_woocommerce_gift_cards' => 'nfd_slug_yith_paypal_payments_for_woocommerce',
'nfd_slug_yith_woocommerce_ajax_product_filter' => 'yith-woocommerce-ajax-navigation',
'nfd_slug_yith_woocommerce_wishlist' => 'yith-woocommerce-wishlist',
'nfd_slug_yith_woocommerce_booking' => 'yith-woocommerce-booking',
'nfd_slug_yith_woocommerce_gift_cards' => 'yith-woocommerce-gift-cards',
'nfd_slug_yith_woocommerce_customize_myaccount_page' => 'yith-woocommerce-customize-myaccount-page',
'yith-woocommerce-ajax-search' => 'yith-woocommerce-ajax-search',
);

// Initialize status array for the plugin upgrade process
Expand Down Expand Up @@ -89,43 +88,31 @@ public static function upgrade_extended_yith_plugin( $extended_slug ) {
return $upgrade_status;
}

// Get the status of the premium version of the plugin
$premium_status = PluginInstaller::get_plugin_status( $premium_slug );

// Skip if the premium plugin is already active or installed
if ( $status_codes['active'] === $premium_status || $status_codes['installed'] === $premium_status ) {
$upgrade_status['message'] = __( 'Premium plugin already installed or active: ', 'wp-module-installer' ) . $premium_slug;
return $upgrade_status;
}

// Provision a license for the premium version of the plugin
$license_response = PLSUtility::provision_license( $premium_slug );
if ( is_wp_error( $license_response ) ) {
$upgrade_status['message'] = __( 'Failed to provision license for: ', 'wp-module-installer' ) . $premium_slug;
return $upgrade_status;
}

// Check if the download URL is present in the license response
if ( empty( $license_response['downloadUrl'] ) ) {
$upgrade_status['message'] = __( 'Download URL is missing for premium plugin: ', 'wp-module-installer' ) . $premium_slug;
return $upgrade_status;
}

// Check if the premium plugin should be activated after installation
$should_activate = ( $status_codes['active'] === $extended_status );

// Deactivate the extended version of the plugin if the premium plugin needs to be activated
if ( $should_activate ) {
PluginInstaller::deactivate( $extended_slug );
$deactivation_response = PluginInstaller::deactivate( $extended_slug );
if ( is_wp_error( $deactivation_response ) ) {
$upgrade_status['message'] = __( 'Failed to deactivate the extended plugin: ', 'wp-module-installer' ) . $extended_slug;
return $upgrade_status;
}
}

// Attempt to install the premium plugin using the provided download URL, and activate it if needed
$premium_install_status = PluginInstaller::install_from_zip( $license_response['downloadUrl'], $should_activate );
if ( is_wp_error( $premium_install_status ) ) {
$upgrade_status['message'] = __( 'Failed to install the premium plugin: ', 'wp-module-installer' ) . $premium_slug;
// Use the install_premium_plugin function to install and activate the premium plugin
$install_status = PluginInstaller::install_premium_plugin( $premium_slug, 'yith', $should_activate );
if ( is_wp_error( $install_status ) ) {
$upgrade_status['message'] = $install_status->get_error_message();

// Reactivate the extended plugin if premium installation failed and it was deactivated
if ( $should_activate ) {
PluginInstaller::activate( $extended_slug );
$reactivation_response = PluginInstaller::activate( $extended_slug );
if ( is_wp_error( $reactivation_response ) ) {
$upgrade_status['message'] .= __( ' Also Failed to reactivate the extended plugin: ', 'wp-module-installer' ) . $extended_slug;
}
}

return $upgrade_status;
}

Expand Down
51 changes: 0 additions & 51 deletions includes/WPAdmin/Listeners/DataAttrListener.php

This file was deleted.

Loading