diff --git a/packages/playground/website/public/plugin-proxy.php b/packages/playground/website/public/plugin-proxy.php index 57095b60b3..9981abce61 100644 --- a/packages/playground/website/public/plugin-proxy.php +++ b/packages/playground/website/public/plugin-proxy.php @@ -334,6 +334,29 @@ function ($curl, $body) use (&$extra_headers_sent, $default_response_headers) { } $downloader->streamFromGithubReleases($_GET['repo'], $_GET['name']); + } else if ( isset( $_GET['wordpress-branch'] ) ) { + $branch = strtolower( $_GET['wordpress-branch'] ); + if ( $branch === 'trunk' || $branch === 'master' ) { + $branch = 'master'; + // If the brach is of the form x.x append '-branch' to it. + } elseif ( preg_match( '/^\d+\.\d+$/', $branch ) ) { + $branch .= '-branch'; + } elseif ( ! preg_match( '/^\d+\.\d+-branch$/', $branch ) ) { + throw new ApiException( 'Invalid branch' ); + } + + $url = "https://codeload.github.com/WordPress/WordPress/zip/refs/heads/{$branch}"; + + streamHttpResponse( + $url, + 'GET', + [], + file_get_contents('php://input'), + null, + [ + 'Content-Disposition: attachment; filename="wordpress.zip"', + ] + ); } else if (isset($_GET['url'])) { // Proxy the current request to $_GET['url'] and return the response, // but only if the URL is allowlisted. diff --git a/packages/playground/wordpress/src/index.ts b/packages/playground/wordpress/src/index.ts index f1e9134d79..711a9dcc8b 100644 --- a/packages/playground/wordpress/src/index.ts +++ b/packages/playground/wordpress/src/index.ts @@ -329,12 +329,32 @@ export async function unzipWordPress(php: PHP, wpZip: File) { // @TODO: Don't make so many guesses about the zip file contents. Allow the // API consumer to specify the exact "coordinates" of WordPress inside // the zip archive. - const wpPath = php.fileExists('/tmp/unzipped-wordpress/wordpress') + let wpPath = php.fileExists('/tmp/unzipped-wordpress/wordpress') ? '/tmp/unzipped-wordpress/wordpress' : php.fileExists('/tmp/unzipped-wordpress/build') ? '/tmp/unzipped-wordpress/build' : '/tmp/unzipped-wordpress'; + // Dive one directory deeper if the zip root does not contain the sample + // config file. This is relevant when unzipping a zipped branch from the + // https://github.com/WordPress/WordPress repository. + if (!php.fileExists(joinPaths(wpPath, 'wp-config-sample.php'))) { + // Still don't know the directory structure of the zip file. + // 1. Get the first item in path. + const files = php.listFiles(wpPath); + if (files.length) { + const firstDir = files[0]; + // 2. If it's a directory that contains wp-config-sample.php, use it. + if ( + php.fileExists( + joinPaths(wpPath, firstDir, 'wp-config-sample.php') + ) + ) { + wpPath = joinPaths(wpPath, firstDir); + } + } + } + if ( php.isDir(php.documentRoot) && isCleanDirContainingSiteMetadata(php.documentRoot, php)