Edit File by line
/home/zeestwma/ceyloniy.../wp-conte.../plugins/extendif.../src/AutoLaun.../fetchers
File: get-plugins.js
import { getPluginsShape, pluginShape } from '@auto-launch/fetchers/shape';
[0] Fix | Delete
import {
[1] Fix | Delete
failWithFallback,
[2] Fix | Delete
fetchWithTimeout,
[3] Fix | Delete
retryTwice,
[4] Fix | Delete
setStatus,
[5] Fix | Delete
} from '@auto-launch/functions/helpers';
[6] Fix | Delete
import {
[7] Fix | Delete
activatePlugin,
[8] Fix | Delete
alreadyActive,
[9] Fix | Delete
getActivePlugins,
[10] Fix | Delete
installPlugin,
[11] Fix | Delete
} from '@auto-launch/functions/plugins';
[12] Fix | Delete
import { AI_HOST } from '@constants';
[13] Fix | Delete
import { reqDataBasics } from '@shared/lib/data';
[14] Fix | Delete
import { __ } from '@wordpress/i18n';
[15] Fix | Delete
import { z } from 'zod';
[16] Fix | Delete
[17] Fix | Delete
const { pluginGroupId } = window.extSharedData;
[18] Fix | Delete
const fallback = { sitePlugins: [] };
[19] Fix | Delete
const url = `${AI_HOST}/api/site-plugins`;
[20] Fix | Delete
const method = 'POST';
[21] Fix | Delete
const headers = { 'Content-Type': 'application/json' };
[22] Fix | Delete
[23] Fix | Delete
// Local due to legacy naming inconsistency
[24] Fix | Delete
const shapeLocal = z.object({
[25] Fix | Delete
selectedPlugins: z.array(pluginShape),
[26] Fix | Delete
});
[27] Fix | Delete
[28] Fix | Delete
export const handleSitePlugins = async ({
[29] Fix | Delete
siteProfile = {},
[30] Fix | Delete
requiredOnly = false,
[31] Fix | Delete
showStatus = true,
[32] Fix | Delete
}) => {
[33] Fix | Delete
if (showStatus) {
[34] Fix | Delete
// translators: this is for a action log UI. Keep it short
[35] Fix | Delete
setStatus(__('Setting up site functionality', 'extendify-local'));
[36] Fix | Delete
}
[37] Fix | Delete
[38] Fix | Delete
const body = JSON.stringify({
[39] Fix | Delete
...reqDataBasics,
[40] Fix | Delete
...siteProfile,
[41] Fix | Delete
siteProfile,
[42] Fix | Delete
siteObjective: siteProfile.objective,
[43] Fix | Delete
pluginGroupId,
[44] Fix | Delete
requiredOnly,
[45] Fix | Delete
});
[46] Fix | Delete
[47] Fix | Delete
const response = await retryTwice(() =>
[48] Fix | Delete
fetchWithTimeout(url, { method, headers, body }),
[49] Fix | Delete
);
[50] Fix | Delete
[51] Fix | Delete
if (!response?.ok) return fallback;
[52] Fix | Delete
[53] Fix | Delete
const plugins = await failWithFallback(async () => {
[54] Fix | Delete
const data = await response.json();
[55] Fix | Delete
const sitePlugins = shapeLocal
[56] Fix | Delete
.parse(data)
[57] Fix | Delete
.selectedPlugins // We add give to the front. See here why:
[58] Fix | Delete
// https://github.com/extendify/company-product/issues/713
[59] Fix | Delete
.toSorted(({ wordpressSlug }) => (wordpressSlug === 'give' ? -1 : 1));
[60] Fix | Delete
return getPluginsShape.parse({ sitePlugins });
[61] Fix | Delete
}, fallback);
[62] Fix | Delete
[63] Fix | Delete
// install partner plugins
[64] Fix | Delete
const activePlugins = await getActivePlugins();
[65] Fix | Delete
const pluginsToInstall = plugins.sitePlugins.filter(
[66] Fix | Delete
({ wordpressSlug: slug }) => !alreadyActive(activePlugins, slug),
[67] Fix | Delete
);
[68] Fix | Delete
if (showStatus && pluginsToInstall.length > 0) {
[69] Fix | Delete
setStatus(
[70] Fix | Delete
// translators: this is for a action log UI. Keep it short
[71] Fix | Delete
__('Setting up functionality for your website', 'extendify-local'),
[72] Fix | Delete
);
[73] Fix | Delete
}
[74] Fix | Delete
for (const { wordpressSlug: slug } of pluginsToInstall) {
[75] Fix | Delete
const p = await installPlugin(slug);
[76] Fix | Delete
await activatePlugin(p?.plugin ?? slug);
[77] Fix | Delete
}
[78] Fix | Delete
return plugins;
[79] Fix | Delete
};
[80] Fix | Delete
[81] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function