Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
officiallygod committed Oct 8, 2024
1 parent af5dc7e commit 50f0a5c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 44 deletions.
49 changes: 7 additions & 42 deletions includes/RestApi/PluginsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,6 @@ public function register_routes() {
)
);

\register_rest_route(
$this->namespace,
$this->rest_base . '/install-premium',
array(
array(
'methods' => \WP_REST_Server::READABLE,
'callback' => array( $this, 'install_premium' ),
'args' => $this->get_install_premium_plugin_args(),
'permission_callback' => array( Permissions::class, 'rest_is_authorized_admin' ),
),
)
);

\register_rest_route(
$this->namespace,
$this->rest_base . '/uninstall',
Expand Down Expand Up @@ -136,21 +123,7 @@ public function get_install_plugin_args() {
'type' => 'integer',
'default' => 0,
),
);
}

/**
* Get args for the premium install route.
*
* @return array
*/
public function get_install_premium_plugin_args() {
return array(
'plugin' => array(
'type' => 'string',
'required' => true,
),
'activate' => array(
'premium' => array(
'type' => 'boolean',
'default' => false,
),
Expand Down Expand Up @@ -209,6 +182,12 @@ public function install( \WP_REST_Request $request ) {
$activate = $request->get_param( 'activate' );
$queue = $request->get_param( 'queue' );
$priority = $request->get_param( 'priority' );
$premium = $request->get_param( 'premium' );

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

// Checks if a plugin with the given slug and activation criteria already exists.
if ( PluginInstaller::exists( $plugin, $activate ) ) {
Expand Down Expand Up @@ -241,20 +220,6 @@ public function install( \WP_REST_Request $request ) {
return $plugin_install_task->execute();
}

/**
* Install the requested premium plugin.
*
* @param \WP_REST_Request $request the incoming request object.
*
* @return \WP_REST_Response|\WP_Error
*/
public function install_premium( \WP_REST_Request $request ) {
$plugin = $request->get_param( 'plugin' );
$activate = $request->get_param( 'activate' );

return PluginInstaller::install_premium_plugin( $plugin, $activate );
}

/**
* Handle an uninstall requuest.
*
Expand Down
3 changes: 3 additions & 0 deletions src/Scripts/dataAttrListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ domReady( () => {
) === 'true'
? true
: false,
queue: true,
priority: 0,
premium: true,
},
} );
}
Expand Down
2 changes: 1 addition & 1 deletion src/constants.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export const wpRestURL = window.nfdInstallerDataAttrListener?.restUrl;
export const dataRestRoute = 'newfold-installer/v1';
export const installerAPI = `${ wpRestURL }/${ dataRestRoute }/install-premium`;
export const installerAPI = `${ wpRestURL }/${ dataRestRoute }/install`;
2 changes: 1 addition & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const version = require( './package.json' ).version; // never require full confi
const nfdSurveyWebpackConfig = {
output: {
path: path.resolve( process.cwd(), `build/${ version }` ),
library: [ 'newfold', 'Survey', '[name]' ],
library: [ 'newfold', 'Installer', '[name]' ],
libraryTarget: 'window',
},
};
Expand Down

0 comments on commit 50f0a5c

Please sign in to comment.