Skip to content

Commit

Permalink
allow install of wp directory plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
cairocoder01 committed May 15, 2023
1 parent a7b709d commit 95e4087
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 18 deletions.
55 changes: 41 additions & 14 deletions admin/js/wizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,50 @@ function buildFormData (formData, data, parentKey) {
};

function install(pluginUrl) {
const slug = pluginUrl.split('/')[4];
const isDtPlugin = pluginUrl.includes('http') || pluginUrl.includes('/');
const slug = isDtPlugin
? pluginUrl.split('/')[4]
: pluginUrl;
console.log('installing: ' + slug);
showMessage(`Installing: ${slug}`);
sendApiRequest('/plugin-install', { download_url: pluginUrl })
.then((success) => {
if (success) {
console.log('Successfully installed ' + slug);
showMessage(`Installed ${slug}`, 'success');
activate(slug);
} else {
throw new Exception('Error');
if (isDtPlugin) {
sendApiRequest('/plugin-install', { download_url: pluginUrl })
.then((success) => {
if (success) {
console.log('Successfully installed ' + slug);
showMessage(`Installed ${slug}`, 'success');
activate(slug);
} else {
throw new Exception('Error');
}
})
.catch((error) => {
console.error('Error installing plugin.', error);
showMessage(`Error installing plugin ${pluginUrl}`, 'error');
});
} else {
const body = new FormData();
body.append('slug', slug);
body.append('status', 'active');
// console.log(window.wpApiSettings);
const url = `${window.wpApiSettings.root}${window.wpApiSettings.versionString}plugins`;

fetch(url, {
method: 'POST',
body,
headers: {
"X-WP-Nonce": window.wpApiSettings.nonce,
}
})
.catch((error) => {
console.error('Error installing plugin.', error);
showMessage(`Error installing plugin ${pluginUrl}`, 'error');
});
}).then((response) => response.json())
.then((success) => {
console.log('Successfully installed ' + slug, success);
showMessage(`Installed and Activated ${slug}`, 'success');
})
.catch((error) => {
console.error('Error installing plugin.', error);
showMessage(`Error installing plugin ${pluginUrl}`, 'error');
});
}
}

function activate(pluginSlug) {
Expand Down
7 changes: 6 additions & 1 deletion disciple-tools-setup-wizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Description: Disciple.Tools - Setup Wizard is intended to help developers and integrator jumpstart their extension of the Disciple.Tools system.
* Text Domain: disciple-tools-setup-wizard
* Domain Path: /languages
* Version: 0.1
* Version: 0.2
* Author URI: https://github.com/cairocoder01
* GitHub Plugin URI: https://github.com/cairocoder01/disciple-tools-setup-wizard
* Requires at least: 4.7.0
Expand Down Expand Up @@ -98,6 +98,11 @@ private function __construct() {

$this->i18n();

add_filter( 'allowed_wp_v2_paths', function ( $paths ) {
array_push( $paths, '/wp/v2/plugins');
return $paths;
} );

}

/**
Expand Down
6 changes: 3 additions & 3 deletions version-control.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Disciple.Tools - Setup Wizard",
"version": "0.1",
"last_updated": "2023-03",
"version": "0.2",
"last_updated": "2023-05-15",
"author": "cairocoder01",
"author_homepage": "https://github.com/cairocoder01",
"git_owner": "cairocoder01",
Expand All @@ -15,7 +15,7 @@
"license_url": "https://raw.githubusercontent.com/cairocoder01/disciple-tools-setup-wizard/master/LICENSE",
"readme_url": "https://raw.githubusercontent.com/cairocoder01/disciple-tools-setup-wizard/master/README.md",
"requires": "4.7",
"tested": "6.1.1",
"tested": "6.2",
"upgrade_notice": "Upgrade to get the latest features.",
"banners": {
"low": "https://raw.githubusercontent.com/cairocoder01/disciple-tools-setup-wizard/master/documentation/banner.png",
Expand Down

0 comments on commit 95e4087

Please sign in to comment.