/
githubmirror
/
wp-calypso
Обзор
Документация
Войти
/
githubmirror
/
wp-calypso
Код
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
trunk
packages/api-core/src/site-plugins/mutators.ts
104 строки
3 KB
James Kenneth Guidaven
A4A WooPayments: migrate the page data layer to the MSD standard (#112324)
14 июл 2026, 15:00
Не верифицирован
14 июл 2026, 15:00
10688b8
Код
Авторство
О чём код?
import { wpcom } from '../wpcom-fetcher'; import type { SitePlugin } from './types'; // Activate a plugin on a site export async function activateSitePlugin( siteId: number, pluginId: string ): Promise< SitePlugin > { return wpcom.req.post( { path: `/sites/${ siteId }/plugins/${ encodeURIComponent( pluginId ) }`, apiVersion: '1.2', }, { active: true } ); } // Deactivate a plugin on a site export async function deactivateSitePlugin( siteId: number, pluginId: string ): Promise< SitePlugin > { return wpcom.req.post( { path: `/sites/${ siteId }/plugins/${ encodeURIComponent( pluginId ) }`, apiVersion: '1.2', }, { active: false } ); } // Update a plugin on a site export async function updateSitePlugin( siteId: number, pluginId: string ): Promise< SitePlugin > { return wpcom.req.post( { path: `/sites/${ siteId }/plugins/${ encodeURIComponent( pluginId ) }/update`, apiVersion: '1.2', } ); } // Enable autoupdates for a plugin export async function enableSitePluginAutoupdate( siteId: number, pluginId: string ): Promise< SitePlugin > { return wpcom.req.post( { path: `/sites/${ siteId }/plugins/${ encodeURIComponent( pluginId ) }`, apiVersion: '1.2', }, { autoupdate: true } ); } // Disable autoupdates for a plugin export async function disableSitePluginAutoupdate( siteId: number, pluginId: string ): Promise< SitePlugin > { return wpcom.req.post( { path: `/sites/${ siteId }/plugins/${ encodeURIComponent( pluginId ) }`, apiVersion: '1.2', }, { autoupdate: false } ); } // Install a plugin by slug export async function installSitePlugin( siteId: number, slug: string ): Promise< SitePlugin > { return wpcom.req.post( { path: `/sites/${ siteId }/plugins/new`, apiVersion: '1.2' }, { slug } ); } // Install and activate a plugin by slug via the WordPress Core (wp/v2) endpoint. export async function installSiteCorePlugin( siteId: number, slug: string ): Promise< void > { return wpcom.req.post( { apiNamespace: 'wp/v2', path: `/sites/${ siteId }/plugins`, body: { slug, status: 'active', }, } ); } // Activate a plugin via the WordPress Core (wp/v2) endpoint. `plugin` is the plugin file path // (e.g. "woocommerce/woocommerce") and is intentionally not URL-encoded to match the endpoint. export async function activateSiteCorePlugin( siteId: number, plugin: string ): Promise< void > { return wpcom.req.post( { apiNamespace: 'wp/v2', path: `/sites/${ siteId }/plugins/${ plugin }`, body: { status: 'active', }, } ); } // Remove a plugin (deletes files) export async function removeSitePlugin( siteId: number, pluginId: string ): Promise< void > { return wpcom.req.post( { path: `/sites/${ siteId }/plugins/${ encodeURIComponent( pluginId ) }/delete`, apiVersion: '1.2', method: 'POST', } ); }