/
githubmirror
/
wp-calypso
Обзор
Документация
Войти
/
githubmirror
/
wp-calypso
Код
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
trunk
packages/wpcom.js/src/lib/site.plugin.js
133 строки
3 KB
Calypso Bot
chore(deps): update linters (major) (#80830)
27 сен 2023, 16:26
Не верифицирован
27 сен 2023, 16:26
e1f240e
Код
Авторство
О чём код?
/** * Module vars */ const root = '/sites'; class SitePlugin { /** * `SitePlugin` constructor. * @param {string} [slug] - the plugin slug * @param {number|string} sid - site identifier * @param {WPCOM} wpcom - wpcom instance * @returns {undefined} undefined */ constructor( slug, sid, wpcom ) { if ( ! ( this instanceof SitePlugin ) ) { return new SitePlugin( slug, sid, wpcom ); } if ( ! slug ) { throw new Error( '`slug` is not correctly defined' ); } this._slug = encodeURIComponent( slug ); this._sid = sid; this.wpcom = wpcom; const path = `${ root }/${ this._sid }/plugins`; this.pluginPath = `${ path }/${ this._slug }`; } /** * Get informtion about the plugin * @param {Object} [query] - query object parameter * @param {Function} [fn] - callback function * @returns {Promise} Promise */ get( query, fn ) { return this.wpcom.req.get( this.pluginPath, query, fn ); } /** * Update the plugin configuration * @param {Object} [query] - query object parameter * @param {Object} body - plugin body object * @param {Function} [fn] - callback function * @returns {Promise} Promise */ update( query, body, fn ) { return this.wpcom.req.put( this.pluginPath, query, body, fn ); } /** * Update the plugin version * @param {Object} [query] - query object parameter * @param {Function} [fn] - callback function * @returns {Promise} Promise */ updateVersion( query, fn ) { return this.wpcom.req.put( `${ this.pluginPath }/update`, query, fn ); } /** * Install the plugin * @param {Object} [query] - query object parameter * @param {Function} [fn] - callback function * @returns {Promise} Promise */ install( query, fn ) { const body = { slug: this._slug, }; return this.wpcom.req.post( `${ root }/${ this._sid }/plugins/install`, query, body, fn ); } /** * Delete the plugin * @param {Object} [query] - query object parameter * @param {Function} [fn] - callback function * @returns {Promise} Promise */ delete( query, fn ) { return this.wpcom.req.put( `${ this.pluginPath }/delete`, query, fn ); } /** * Activate the plugin * This method is a shorthand of update() * @param {Object} [query] - query object parameter * @param {Function} [fn] - callback function * @returns {Promise} Promise */ activate( query, fn ) { return this.update( query, { active: true }, fn ); } /** * Deactivate the plugin * This method is a shorthand of update() * @param {Object} [query] - query object parameter * @param {Function} [fn] - callback function * @returns {Promise} Promise */ deactivate( query, fn ) { return this.update( query, { active: false }, fn ); } /** * Enable plugin autoupdate * This method is a shorthand of update() * @param {Object} [query] - query object parameter * @param {Function} [fn] - callback function * @returns {Promise} Promise */ enableAutoupdate( query, fn ) { return this.update( query, { autoupdate: true }, fn ); } /** * Disable plugin autoupdate * This method is a shorthand of update() * @param {Object} [query] - query object parameter * @param {Function} [fn] - callback function * @returns {Promise} Promise */ disableAutoupdate( query, fn ) { return this.update( query, { autoupdate: false }, fn ); } } /** * Expose `SitePlugin` module */ export default SitePlugin;