Skip to content

Commit

Permalink
Download plugins and themes directly from WordPress.org, not via plug…
Browse files Browse the repository at this point in the history
…in-proxy.php (#711)

WordPress.org now serves the `Access-Control-Allow-*` headers necessary
to perform a direct `fetch()` without going through plugin-proxy.php.
This commit thus removes the usages of plugin-proxy.php.

The plugin proxy is now only used by the Pull Request previewers. As a
follow up, let's consider splitting them to a separate package or even
to the playground-tools repo.

## Testing Instructions

To test, go to
http://localhost:5400/website-server/?theme=pendant&plugin=gutenberg and
confirm that both the Pendant theme and the Gutenberg plugins are
installed, and also that the zip files are downloaded directly from
wordpress.org
  • Loading branch information
adamziel authored Oct 19, 2023
1 parent 6890ff9 commit 83fab85
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
9 changes: 8 additions & 1 deletion packages/playground/blueprints/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export * from './lib/steps';
export * from './lib/steps/handlers';
export { runBlueprintSteps, compileBlueprint } from './lib/compile';
export { setPluginProxyURL } from './lib/resources';
export type { Blueprint } from './lib/blueprint';
export type {
CompiledStep,
Expand Down Expand Up @@ -29,3 +28,11 @@ export type {
VFSReference,
VFSResource,
} from './lib/resources';

/**
* @deprecated This function is a no-op. Playground no longer uses a proxy to download plugins and themes.
* To be removed in v0.3.0
*/
export function setPluginProxyURL() {

}
9 changes: 2 additions & 7 deletions packages/playground/blueprints/src/lib/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,6 @@ export class UrlResource extends FetchResource {
}
}

let pluginProxyURL = 'https://playground.wordpress.net/plugin-proxy';
export function setPluginProxyURL(url: string) {
pluginProxyURL = url;
}

/**
* A `Resource` that represents a WordPress core theme.
*/
Expand All @@ -301,7 +296,7 @@ export class CoreThemeResource extends FetchResource {
}
getURL() {
const zipName = toDirectoryZipName(this.resource.slug);
return `${pluginProxyURL}?theme=` + zipName;
return `https://downloads.wordpress.org/theme/${zipName}`;
}
}

Expand All @@ -324,7 +319,7 @@ export class CorePluginResource extends FetchResource {
/** @inheritDoc */
getURL() {
const zipName = toDirectoryZipName(this.resource.slug);
return `${pluginProxyURL}?plugin=` + zipName;
return `https://downloads.wordpress.org/plugin/${zipName}`;
}
}

Expand Down
3 changes: 3 additions & 0 deletions packages/playground/website/public/plugin-proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ function ($curl, $body) use (&$extra_headers_sent, $default_headers) {
header('Access-Control-Allow-Origin: *');
$pluginResponse;
try {
/** @deprecated Plugins and themes downloads are no longer needed now that WordPress.org serves
* the proper CORS headers. This code will be removed in one of the next releases.
*/
if (isset($_GET['plugin'])) {
$downloader->streamFromDirectory($_GET['plugin'], PluginDownloader::PLUGINS);
} else if (isset($_GET['theme'])) {
Expand Down

0 comments on commit 83fab85

Please sign in to comment.