Skip to content

Commit 8dc4e34

Browse files
committed
fix: support playground sudo challenge
1 parent dee170d commit 8dc4e34

2 files changed

Lines changed: 24 additions & 4 deletions

File tree

admin/js/wp-sudo-challenge.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,26 @@
1919
// The challenge page must render at the top level so the full admin
2020
// chrome is visible and the redirect/replay targets the correct frame.
2121
if (window.top !== window.self) {
22-
window.top.location.href = window.location.href;
23-
return;
22+
var canNavigateTop = true;
23+
try {
24+
var frame = window.frameElement;
25+
if (frame && frame.hasAttribute('sandbox')) {
26+
var sandboxTokens = (frame.getAttribute('sandbox') || '').split(/\s+/);
27+
canNavigateTop = sandboxTokens.indexOf('allow-top-navigation') !== -1;
28+
}
29+
} catch (e) {
30+
canNavigateTop = false;
31+
}
32+
33+
if (canNavigateTop) {
34+
try {
35+
window.top.location.href = window.location.href;
36+
return;
37+
} catch (e) {
38+
// Cross-origin/sandboxed hosts such as WordPress Playground must
39+
// keep the challenge functional inside the embedded frame.
40+
}
41+
}
2442
}
2543

2644
var config = window.wpSudoChallenge || {};

blueprint.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
{
1919
"step": "installPlugin",
2020
"pluginData": {
21-
"resource": "url",
22-
"url": "https://github.com/dknauss/Sudo/archive/refs/tags/v3.1.1.zip"
21+
"resource": "git:directory",
22+
"url": "https://github.com/dknauss/Sudo",
23+
"ref": "main",
24+
"refType": "branch"
2325
},
2426
"options": { "activate": true }
2527
},

0 commit comments

Comments
 (0)