Skip to content

Commit 373d90a

Browse files
committed
Fix wp-admin loading on legacy WordPress versions
Three issues prevented wp-admin from working on PHP 5.6: 1. template.php and media.php were replaced with empty stubs as a workaround for the WASM parser size limit. The real fix is to strip doc comments (which stripDocCommentsFromWpIncludes already does). Remove the stub replacement. Also preserve ?> tags during comment stripping — PHP's ?> closes PHP mode even inside // comments. 2. Old WordPress (< 3.7) uses relative paths in wp-admin scripts. Patch these to use dirname(__FILE__) for absolute resolution. Covers index.php, index-extra.php, and admin.php across all old WP versions. 3. Auth cookies don't persist correctly for old WordPress admin sessions. Fix by re-generating auth cookies on every admin request: mu-plugin for WP 2.8+, direct admin.php patch for WP < 2.8 (no mu-plugin support). Handles three auth eras: - WP 2.5+: wp_generate_auth_cookie + $_COOKIE population - WP 2.0-2.4: USER_COOKIE/PASS_COOKIE with md5(md5(password)) - WP 1.5: COOKIEHASH-based hardcoded cookie names Also skip prefetchUpdateChecks for WP < 5.0 (the functions it calls don't exist in old WP), skip 0-playground.php mu-plugin for WP < 3.0 (closures in hooks cause fatal errors), and set up wp_user_roles + usermeta when missing after install.
1 parent a5fe6f7 commit 373d90a

File tree

4 files changed

+578
-23
lines changed

4 files changed

+578
-23
lines changed

packages/playground/client/src/blueprints-v1-handler.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,14 @@ export class BlueprintsV1Handler {
8787

8888
/**
8989
* Pre-fetch WordPress update checks to speed up the initial wp-admin load.
90+
* Skip for old WordPress versions — the functions called by prefetch
91+
* (wp_check_php_version, wp_update_plugins, etc.) don't exist or crash
92+
* on legacy WP, and the resulting PHP errors create noise.
9093
*
9194
* @see https://github.com/WordPress/wordpress-playground/pull/2295
9295
*/
93-
if (runtimeConfiguration.networking) {
96+
const wpMajor = parseFloat(runtimeConfiguration.wpVersion) || 99;
97+
if (runtimeConfiguration.networking && wpMajor >= 5) {
9498
await playground.prefetchUpdateChecks();
9599
}
96100

packages/playground/remote/src/lib/playground-mu-plugin/0-playground.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
<?php
2+
// WordPress < 3.0 can't handle closures as hook callbacks — the old
3+
// $wp_filter array structure uses string-indexed arrays internally
4+
// and treats Closure objects as arrays, causing fatal errors. Skip
5+
// this mu-plugin entirely for those ancient versions.
6+
if (isset($GLOBALS['wp_version']) && version_compare($GLOBALS['wp_version'], '3.0', '<')) {
7+
return;
8+
}
29

310
/**
411
* Add a notice to wp-login.php offering the username and password.

0 commit comments

Comments
 (0)