0
ˆ
ƒ�½_•I|¥‰ÓMdœv ©ƒ&íK<óo¬ÂÁ ¢
Index of /FSS-BCZ/root/sys/dev/char/4:53/subsystem/tty44/power
Index of /FSS-BCZ/root/sys/dev/char/4:53/subsystem/tty44/power
/ ˆl–ß=¿Jµ5*q@½p ¸&ÔÅ£Å
ƒyà·_‹I|¥Žƒî4ÃVŸÄà "o /**
* Plugin Utility Functions
*
* Contains reusable functions for installing and activating plugins.
*
*/
import { __, sprintf } from '@wordpress/i18n';
/**
* Performs the given plugin or theme operation (install or activate).
*
* @param {Object} plugin - The plugin or theme object.
* @param {string} operation - The operation ('install' or 'activate').
* @param {Function} setLoadingState - Function to update loading state (array of plugin slugs).
* @return {Promise} Resolves when operation is complete.
*/
export const handlePluginOperation = ( plugin, operation, setLoadingState ) => {
return new Promise( async ( resolve, reject ) => {
const isInstall = operation === 'install';
// Determine the item type. If plugin.type is 'theme', we treat it as a theme; otherwise, as a plugin.
const itemType = plugin.type === 'theme' ? 'theme' : 'plugin';
if ( ! wp.updates ) {
reject(
new Error(
__( 'WordPress updates API not available.', 'suremails' )
)
);
return;
}
// Add the plugin slug to the loading state.
setLoadingState( ( prev ) => [ ...prev, plugin.slug ] );
// For install, use the appropriate wp.updates function.
// For activate, we use wp.ajax.send with an action based on the item type.
const operationFunction = isInstall
? wp.updates[
`install${
itemType.charAt( 0 ).toUpperCase() + itemType.slice( 1 )
}`
]
: wp.ajax.send;
// Data to send: for installation, we simply send the slug;
// for activation: for plugins we use the plugin file path; for themes, just the slug.
const data = isInstall
? { slug: plugin.slug }
: {
slug: plugin.init,
_ajax_nonce: window.suremails?._ajax_nonce,
};
const commonOptions = {
success: () => {
resolve();
},
error: ( error ) => {
reject(
new Error(
error.errorMessage ||
__( 'Operation failed.', 'suremails' )
)
);
},
};
if ( isInstall ) {
operationFunction( {
...data,
...commonOptions,
} );
} else {
// For activation, use a different ajax action if it's a theme.
const actionName =
itemType === 'plugin'
? 'suremails-activate_plugin'
: 'suremails-activate_theme';
operationFunction( actionName, {