Skip to content

Commit

Permalink
Minor changes to support PLS, add provider, lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
arunshenoy99 committed Oct 15, 2024
1 parent 443b90a commit 14f86d4
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 19 deletions.
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
14 changes: 12 additions & 2 deletions includes/Services/PluginInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,24 @@ 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 ) {
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
$license_response = $pls_utility->provision_license( $plugin );
$license_response = $pls_utility->provision_license( $plugin, $provider );
if ( is_wp_error( $license_response ) ) {
return $license_response;
}
Expand Down Expand Up @@ -197,6 +206,7 @@ public static function install_premium_plugin( $plugin, $activate ) {
}



/**
* Install the plugin from a custom ZIP.
*
Expand Down
2 changes: 1 addition & 1 deletion includes/WPAdmin/Listeners/InstallerListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private function listen_for_premium_plugin_activation() {
$pls_utility = new PLSUtility();

// Retrieve the license data (decrypted) from the option
$license_data_store = $pls_utility->retrieve_license_data();
$license_data_store = $pls_utility->retrieve_license_storage_map();

if ( ! $license_data_store || empty( $license_data_store ) ) {
return;
Expand Down
5 changes: 5 additions & 0 deletions src/Installer/components/App/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { INSTALLER_DIV } from '../../constants';
const App = () => {
const [ pluginName, setPluginName ] = useState();
const [ pluginSlug, setPluginSlug ] = useState();
const [ pluginProvider, setPluginProvider ] = useState();
const [ pluginURL, setPluginURL ] = useState();
const [ pluginActivate, setPluginActivate ] = useState();

Expand All @@ -29,6 +30,9 @@ const App = () => {
setPluginSlug(
element.getAttribute( 'nfd-installer-app__plugin--slug' )
);
setPluginProvider(
element.getAttribute( 'nfd-installer-app__plugin--provider' )
);
setPluginURL(
element.getAttribute( 'nfd-installer-app__plugin--url' )
);
Expand All @@ -45,6 +49,7 @@ const App = () => {
pluginSlug={ pluginSlug }
pluginURL={ pluginURL }
pluginActivate={ pluginActivate }
pluginProvider={ pluginProvider }
/>
) }
</div>
Expand Down
16 changes: 14 additions & 2 deletions src/Installer/components/Modal/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ import {
pluginInstallHash,
} from '../../constants';

const Modal = ( { pluginName, pluginSlug, pluginURL, pluginActivate } ) => {
const Modal = ( {
pluginName,
pluginSlug,
pluginURL,
pluginActivate,
pluginProvider,
} ) => {
/**
* Represents the status of the plugin installation process.
*
Expand Down Expand Up @@ -74,6 +80,7 @@ const Modal = ( { pluginName, pluginSlug, pluginURL, pluginActivate } ) => {
priority: 0,
premium: true,
plugin: pluginSlug,
provider: pluginProvider,
},
} );
setPluginStatus( 'completed' );
Expand Down Expand Up @@ -120,11 +127,16 @@ const Modal = ( { pluginName, pluginSlug, pluginURL, pluginActivate } ) => {
icon={ info }
/>
{ sprintf(
// translators: %1$s and %2$s are HTML tags used to format the contact support link
__(
'Sorry, there was an error installing and activating the plugin. Please try again. If the problem persists, %1$scontact support%2$s.',
'wp-module-onboarding'
),
'<a href="' + window.NewfoldRuntime.adminUrl + 'admin.php?page=' + window.NewfoldRuntime.plugin.brand + '#/help">',
'<a href="' +
window.NewfoldRuntime.adminUrl +
'admin.php?page=' +
window.NewfoldRuntime.plugin.brand +
'#/help">',
'</a>'
) }
</div>
Expand Down
24 changes: 16 additions & 8 deletions src/Scripts/dataAttrListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ import domReady from '@wordpress/dom-ready';
import { INSTALLER_DIV } from '../Installer/constants';

domReady( () => {
// function removeModal() {
// // find the modal and remove if it exists
// const modal = document.querySelector( '.nfd-installer' );
// if ( modal ) {
// modal.remove();
// }
// }

Check failure on line 8 in src/Scripts/dataAttrListener.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

Delete `⏎`
function renderModal( pluginName, pluginSlug, pluginURL, activate ) {
function renderModal(
pluginName,
pluginSlug,
pluginProvider,
pluginURL,
activate
) {
// create the installer div
document.getElementById( INSTALLER_DIV ).style.display = 'block';
document
Expand All @@ -22,6 +21,12 @@ domReady( () => {
document
.getElementById( INSTALLER_DIV )
.setAttribute( 'nfd-installer-app__plugin--slug', pluginSlug );
document
.getElementById( INSTALLER_DIV )
.setAttribute(
'nfd-installer-app__plugin--provider',
pluginProvider
);
document
.getElementById( INSTALLER_DIV )
.setAttribute( 'nfd-installer-app__plugin--url', pluginURL );
Expand Down Expand Up @@ -60,6 +65,9 @@ domReady( () => {
this.getAttribute(
'data-nfd-installer-plugin-slug'
),
this.getAttribute(
'data-nfd-installer-plugin-provider'
),
this.getAttribute(
'data-nfd-installer-plugin-url'
),
Expand Down

0 comments on commit 14f86d4

Please sign in to comment.