forked from WordPress/wordpress-playground
-
Notifications
You must be signed in to change notification settings - Fork 0
/
activate-plugin.ts
39 lines (37 loc) · 1.02 KB
/
activate-plugin.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { StepHandler } from '.';
export interface ActivatePluginStep {
step: 'activatePlugin';
/* Path to the plugin file relative to the plugins directory. */
pluginPath: string;
}
/**
* Activates a WordPress plugin in the Playground.
*
* @param playground The playground client.
* @param plugin The plugin slug.
*/
export const activatePlugin: StepHandler<ActivatePluginStep> = async (
playground,
{ pluginPath },
progress
) => {
progress?.tracker.setCaption(`Activating ${pluginPath}`);
const requiredFiles = [
`${await playground.documentRoot}/wp-load.php`,
`${await playground.documentRoot}/wp-admin/includes/plugin.php`,
];
const requiredFilesExist = requiredFiles.every((file) =>
playground.fileExists(file)
);
if (!requiredFilesExist) {
throw new Error(
`Required WordPress files do not exist: ${requiredFiles.join(', ')}`
);
}
await playground.run({
code: `<?php
${requiredFiles.map((file) => `require_once( '${file}' );`).join('\n')}
activate_plugin('${pluginPath}');
`,
});
};