Skip to content

Commit

Permalink
Code
Browse files Browse the repository at this point in the history
  • Loading branch information
officiallygod committed Oct 8, 2024
1 parent 7a87bda commit af5dc7e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
45 changes: 45 additions & 0 deletions includes/RestApi/PluginsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,19 @@ 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 @@ -126,6 +139,24 @@ public function get_install_plugin_args() {
);
}

/**
* 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(
'type' => 'boolean',
'default' => false,
),
);
}

/**
* Get args for the uninstall route.
*
Expand Down Expand Up @@ -210,6 +241,20 @@ 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
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-plugin`;
export const installerAPI = `${ wpRestURL }/${ dataRestRoute }/install-premium`;

0 comments on commit af5dc7e

Please sign in to comment.