@wp-playground/wordpress 3.1.35 → 3.1.38

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("@php-wasm/universal"),o=require("@php-wasm/util"),g=require("@wp-playground/common"),h=require("@php-wasm/logger");async function O(e){await e.writeFile("/internal/shared/mu-plugins/0-playground.php",`<?php
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("@php-wasm/universal"),a=require("@php-wasm/util"),h=require("@wp-playground/common"),d=require("@php-wasm/logger");async function P(e){await e.writeFile("/internal/shared/mu-plugins/0-playground.php",`<?php
2
2
 
3
3
  // Save WordPress environment information to a file.
4
4
  // Named function (not a closure) so this file parses on PHP 5.2.
@@ -262,7 +262,7 @@ $wpdb = $GLOBALS['wpdb'] = new Playground_SQLite_Integration_Loader();
262
262
  *
263
263
  * What WordPress demands, Playground shall provide.
264
264
  */
265
- `}const W=`
265
+ `}const B=`
266
266
  if (function_exists('is_user_logged_in') && is_user_logged_in()) {
267
267
  return;
268
268
  }
@@ -355,7 +355,7 @@ $wpdb = $GLOBALS['wpdb'] = new Playground_SQLite_Integration_Loader();
355
355
  }
356
356
  return;
357
357
  }
358
- `;async function G(e){await e.mkdir("/internal/shared/mu-plugins"),await e.writeFile("/internal/shared/auto_prepend_file.php",`<?php
358
+ `;async function H(e){await e.mkdir("/internal/shared/mu-plugins"),await e.writeFile("/internal/shared/auto_prepend_file.php",`<?php
359
359
  // Polyfill the PHP 4 superglobals WP 1.0–2.5 still reads (removed
360
360
  // in PHP 5.4). Bind by reference so later writes to $_COOKIE
361
361
  // reach $HTTP_COOKIE_VARS, which WP 1.0's get_currentuserinfo()
@@ -610,7 +610,7 @@ function playground_load_mu_plugins() {
610
610
  if ((function_exists('wp_doing_ajax') && wp_doing_ajax()) || defined('REST_REQUEST')) {
611
611
  return;
612
612
  }
613
- ${W}
613
+ ${B}
614
614
  }
615
615
  add_action('init', 'playground_auto_login', 1);
616
616
 
@@ -636,7 +636,7 @@ function playground_load_mu_plugins() {
636
636
  }
637
637
  return $interval;
638
638
  }
639
- `),await O(e),await e.writeFile("/internal/shared/preload/error-handler.php",`<?php
639
+ `),await P(e),await e.writeFile("/internal/shared/preload/error-handler.php",`<?php
640
640
  $GLOBALS['_playground_consts'] = array();
641
641
  if (file_exists('/internal/shared/consts.json')) {
642
642
  $GLOBALS['_playground_consts'] = @json_decode(file_get_contents('/internal/shared/consts.json'), true);
@@ -645,10 +645,10 @@ if (file_exists('/internal/shared/consts.json')) {
645
645
  }
646
646
  function _playground_error_handler($severity, $message, $file, $line) {
647
647
  $playground_consts = $GLOBALS['_playground_consts'];
648
- ${M}
648
+ ${X}
649
649
  return false;
650
650
  }
651
- set_error_handler('_playground_error_handler');`)}const M=`
651
+ set_error_handler('_playground_error_handler');`)}const X=`
652
652
  // http_api_transports is deprecated since 6.4.0 but Playground's
653
653
  // networking layer still registers it for wp_http_supports().
654
654
  // @see https://core.trac.wordpress.org/ticket/37708
@@ -690,7 +690,260 @@ set_error_handler('_playground_error_handler');`)}const M=`
690
690
  {
691
691
  return;
692
692
  }
693
- `;async function H(e,t){const i=E(e,t);if(i===null)return;const n=parseFloat(i);if(!Number.isFinite(n)||n<5||n>=6.2)return;const s=o.joinPaths(t,"wp-includes/load.php");if(!e.fileExists(s))return;const r=e.readFileAsText(s),a=r.replace("extension_loaded( 'mysqli' )","function_exists( 'mysqli_connect' )");a!==r&&await e.writeFile(s,a)}function E(e,t){const i=o.joinPaths(t,"wp-includes/version.php");if(!e.fileExists(i))return null;const s=e.readFileAsText(i).match(/\$wp_version\s*=\s*['"]([^'"]+)['"]/);return s?s[1]:null}const B=22527,T="E_ALL & ~8192 & ~2048";async function j(e,t){await te(e,t),await ie(e,t),await se(e,t),await _e(e,t),await le(e,t),await we(e,t),await ue(e,t),await he(e,t),await K(e,t),await Y(e,t);const i=E(e,t);if(i===null)return;const n=parseFloat(i);Number.isFinite(n)&&(n<1.2&&(await ne(e,t),await ee(e,t)),n<1.5&&await Q(e,t),1.5<=n&&n<2&&await fe(e,t),n<2&&(await z(e,t),await oe(e,t)),2.1<=n&&n<2.3&&await J(e,t),n<2.5&&await de(e,t),n<2.8&&(await ge(e,t),await me(e,t)),2.9<=n&&n<3.6&&await X(e,t),3.3<=n&&n<3.4&&await Z(e,t),n>=4.7&&await V(e,t))}async function V(e,t){const i=o.joinPaths(t,"wp-content/themes");if(e.isDir(i))for(const n of e.listFiles(i)){const s=o.joinPaths(i,n,"searchform.php");e.fileExists(s)&&e.unlink(s)}}async function X(e,t){const i=o.joinPaths(t,"wp-admin/includes/dashboard.php");if(e.fileExists(i)){let r=e.readFileAsText(i);if(r.includes("function wp_dashboard_primary()")&&!r.includes("/* pg_no_rss */")){for(const a of["wp_dashboard_primary","wp_dashboard_secondary","wp_dashboard_plugins"])r=r.replace(new RegExp(`function ${a}\\(\\)\\s*\\{`),`function ${a}() { /* pg_no_rss */ return;`);await e.writeFile(i,r)}}const n=o.joinPaths(t,"wp-admin/admin.php");if(e.fileExists(n)){let r=e.readFileAsText(n);r.includes("do_action('admin_init');")&&!r.includes("/* pg_admin_init_cleanup */")&&(r=r.replace("do_action('admin_init');",`/* pg_admin_init_cleanup */
693
+ `;function A(e){return[/(^|[^\w$])((?:require|include)(?:_once)?)\s*\(\s*(['"])(\.\.\/[^'"]+)\3\s*\)/g,/(^|[^\w$])((?:require|include)(?:_once)?)\s*\(\s*(['"])(\.\/[^'"]+)\3\s*\)/g,/(^|[^\w$])((?:require|include)(?:_once)?)\s*\(\s*(['"])([a-z][\w-]*\.php)\3\s*\)/g,/(^|[^\w$])((?:require|include)(?:_once)?)\s+(['"])(\.\.\/[^'"]+)\3/g,/(^|[^\w$])((?:require|include)(?:_once)?)\s+(['"])(\.\/[^'"]+)\3/g,/(^|[^\w$])((?:require|include)(?:_once)?)\s+(['"])([a-z][\w-]*\.php)\3/g].reduce((i,t)=>i.replace(t,(s,r,o,_,l)=>`${r}${o}(${j(l)})`),e)}function j(e){let n=e,i=0;for(;n.startsWith("../");)i++,n=n.slice(3);for(;n.startsWith("./");)n=n.slice(2);let t="dirname(__FILE__)";for(let s=0;s<i;s++)t=`dirname(${t})`;return`${t} . '/${n}'`}async function V(e,n){return U(e,n)?(await K(e,n),await Q(e,n),await z(e,n),await Z(e,n),await J(e,n),await te(e,n),await ne(e,n),!0):!1}async function Y(e){return U(e,e.documentRoot)?(await e.run({code:`<?php
694
+ $db_dir = getenv('DOCUMENT_ROOT') . '/wp-content/database/';
695
+ if (!is_dir($db_dir)) { @mkdir($db_dir, 0777, true); }
696
+ $db_path = $db_dir . '.ht.sqlite';
697
+ $pdo = new PDO('sqlite:' . $db_path);
698
+ $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
699
+ $now = date('Y-m-d H:i:s');
700
+
701
+ $tables_sql = array(
702
+ 'b2posts' => "CREATE TABLE IF NOT EXISTS b2posts (
703
+ ID INTEGER PRIMARY KEY AUTOINCREMENT,
704
+ post_author INTEGER NOT NULL DEFAULT 0,
705
+ post_date TEXT NOT NULL DEFAULT '0000-00-00 00:00:00',
706
+ post_content TEXT NOT NULL DEFAULT '',
707
+ post_title TEXT NOT NULL DEFAULT '',
708
+ post_category INTEGER NOT NULL DEFAULT 0,
709
+ post_excerpt TEXT NOT NULL DEFAULT '',
710
+ post_status TEXT NOT NULL DEFAULT 'publish',
711
+ comment_status TEXT NOT NULL DEFAULT 'open',
712
+ ping_status TEXT NOT NULL DEFAULT 'open',
713
+ post_password TEXT NOT NULL DEFAULT ''
714
+ )",
715
+ 'b2categories' => "CREATE TABLE IF NOT EXISTS b2categories (
716
+ cat_ID INTEGER PRIMARY KEY AUTOINCREMENT,
717
+ cat_name TEXT NOT NULL DEFAULT ''
718
+ )",
719
+ 'b2comments' => "CREATE TABLE IF NOT EXISTS b2comments (
720
+ comment_ID INTEGER PRIMARY KEY AUTOINCREMENT,
721
+ comment_post_ID INTEGER NOT NULL DEFAULT 0,
722
+ comment_author TEXT NOT NULL DEFAULT '',
723
+ comment_author_email TEXT NOT NULL DEFAULT '',
724
+ comment_author_url TEXT NOT NULL DEFAULT '',
725
+ comment_author_IP TEXT NOT NULL DEFAULT '',
726
+ comment_date TEXT NOT NULL DEFAULT '0000-00-00 00:00:00',
727
+ comment_content TEXT NOT NULL DEFAULT '',
728
+ comment_karma INTEGER NOT NULL DEFAULT 0
729
+ )",
730
+ 'b2settings' => "CREATE TABLE IF NOT EXISTS b2settings (
731
+ ID INTEGER NOT NULL DEFAULT 1,
732
+ posts_per_page INTEGER NOT NULL DEFAULT 20,
733
+ what_to_show TEXT NOT NULL DEFAULT 'posts',
734
+ archive_mode TEXT NOT NULL DEFAULT 'postbypost',
735
+ time_difference INTEGER NOT NULL DEFAULT 0,
736
+ AutoBR INTEGER NOT NULL DEFAULT 1,
737
+ time_format TEXT NOT NULL DEFAULT 'g:i a',
738
+ date_format TEXT NOT NULL DEFAULT 'n/j/Y',
739
+ PRIMARY KEY (ID)
740
+ )",
741
+ 'b2users' => "CREATE TABLE IF NOT EXISTS b2users (
742
+ ID INTEGER PRIMARY KEY AUTOINCREMENT,
743
+ user_login TEXT NOT NULL DEFAULT '',
744
+ user_pass TEXT NOT NULL DEFAULT '',
745
+ user_firstname TEXT NOT NULL DEFAULT '',
746
+ user_lastname TEXT NOT NULL DEFAULT '',
747
+ user_nickname TEXT NOT NULL DEFAULT '',
748
+ user_icq INTEGER NOT NULL DEFAULT 0,
749
+ user_email TEXT NOT NULL DEFAULT '',
750
+ user_url TEXT NOT NULL DEFAULT '',
751
+ user_ip TEXT NOT NULL DEFAULT '',
752
+ user_domain TEXT NOT NULL DEFAULT '',
753
+ user_browser TEXT NOT NULL DEFAULT '',
754
+ dateYMDhour TEXT NOT NULL DEFAULT '0000-00-00 00:00:00',
755
+ user_level INTEGER NOT NULL DEFAULT 0,
756
+ user_aim TEXT NOT NULL DEFAULT '',
757
+ user_msn TEXT NOT NULL DEFAULT '',
758
+ user_yim TEXT NOT NULL DEFAULT '',
759
+ user_idmode TEXT NOT NULL DEFAULT ''
760
+ )",
761
+ 'b2links' => "CREATE TABLE IF NOT EXISTS b2links (
762
+ link_id INTEGER PRIMARY KEY AUTOINCREMENT,
763
+ link_url TEXT NOT NULL DEFAULT '',
764
+ link_name TEXT NOT NULL DEFAULT '',
765
+ link_image TEXT NOT NULL DEFAULT '',
766
+ link_target TEXT NOT NULL DEFAULT '',
767
+ link_category INTEGER NOT NULL DEFAULT 0,
768
+ link_description TEXT NOT NULL DEFAULT '',
769
+ link_visible TEXT NOT NULL DEFAULT 'Y',
770
+ link_owner INTEGER NOT NULL DEFAULT 1,
771
+ link_rating INTEGER NOT NULL DEFAULT 0,
772
+ link_updated TEXT NOT NULL DEFAULT '0000-00-00 00:00:00',
773
+ link_rel TEXT NOT NULL DEFAULT '',
774
+ link_notes TEXT NOT NULL DEFAULT '',
775
+ link_rss TEXT NOT NULL DEFAULT ''
776
+ )",
777
+ 'b2linkcategories' => "CREATE TABLE IF NOT EXISTS b2linkcategories (
778
+ cat_id INTEGER PRIMARY KEY AUTOINCREMENT,
779
+ cat_name TEXT NOT NULL DEFAULT '',
780
+ auto_toggle TEXT NOT NULL DEFAULT 'N',
781
+ show_images TEXT NOT NULL DEFAULT 'Y',
782
+ show_description TEXT NOT NULL DEFAULT 'N',
783
+ show_rating TEXT NOT NULL DEFAULT 'Y',
784
+ show_updated TEXT NOT NULL DEFAULT 'Y',
785
+ sort_order TEXT NOT NULL DEFAULT 'name',
786
+ sort_desc TEXT NOT NULL DEFAULT 'ASC',
787
+ text_before_link TEXT NOT NULL DEFAULT '<li>',
788
+ text_after_link TEXT NOT NULL DEFAULT '<br />',
789
+ text_after_all TEXT NOT NULL DEFAULT '</li>',
790
+ list_limit INTEGER NOT NULL DEFAULT -1
791
+ )"
792
+ );
793
+ foreach ($tables_sql as $sql) {
794
+ $pdo->exec($sql);
795
+ }
796
+
797
+ if (!$pdo->query("SELECT COUNT(*) FROM b2categories")->fetchColumn()) {
798
+ $pdo->exec("INSERT INTO b2categories (cat_ID, cat_name) VALUES (1, 'General')");
799
+ }
800
+ if (!$pdo->query("SELECT COUNT(*) FROM b2settings")->fetchColumn()) {
801
+ $pdo->exec("INSERT INTO b2settings (ID, posts_per_page, what_to_show, archive_mode, time_difference, AutoBR, time_format, date_format) VALUES (1, 20, 'posts', 'postbypost', 0, 1, 'g:i a', 'n/j/Y')");
802
+ }
803
+ if (!$pdo->query("SELECT COUNT(*) FROM b2users")->fetchColumn()) {
804
+ $pass = md5('password');
805
+ $pdo->exec("INSERT INTO b2users (ID, user_login, user_pass, user_nickname, user_email, user_level, dateYMDhour, user_idmode) VALUES (1, 'admin', '{$pass}', 'admin', 'admin@localhost.com', 10, '{$now}', 'nickname')");
806
+ } else {
807
+ $pass = md5('password');
808
+ $pdo->exec("UPDATE b2users SET user_pass = '{$pass}', user_level = 10 WHERE user_login = 'admin'");
809
+ }
810
+ if (!$pdo->query("SELECT COUNT(*) FROM b2posts")->fetchColumn()) {
811
+ $content = 'Welcome to WordPress. This is the first post. Edit or delete it, then start blogging!';
812
+ $pdo->exec("INSERT INTO b2posts (ID, post_author, post_date, post_content, post_title, post_category, post_excerpt, post_status, comment_status, ping_status, post_password) VALUES (1, 1, '{$now}', '{$content}', 'Hello world!', 1, '', 'publish', 'open', 'open', '')");
813
+ }
814
+ if (!$pdo->query("SELECT COUNT(*) FROM b2comments")->fetchColumn()) {
815
+ $pdo->exec("INSERT INTO b2comments (comment_post_ID, comment_author, comment_author_email, comment_author_url, comment_author_IP, comment_date, comment_content, comment_karma) VALUES (1, 'Mr WordPress', 'mr@wordpress.org', 'http://wordpress.org', '127.0.0.1', '{$now}', 'Hi, this is a comment. To delete a comment, just log in and view the comments for this post.', 0)");
816
+ }
817
+ if (!$pdo->query("SELECT COUNT(*) FROM b2linkcategories")->fetchColumn()) {
818
+ $pdo->exec("INSERT INTO b2linkcategories (cat_id, cat_name) VALUES (1, 'General')");
819
+ }
820
+ if (!$pdo->query("SELECT COUNT(*) FROM b2links")->fetchColumn()) {
821
+ $pdo->exec("INSERT INTO b2links (link_url, link_name, link_category, link_visible, link_owner) VALUES ('http://wordpress.org', 'WordPress', 1, 'Y', 1)");
822
+ }
823
+ `,env:{DOCUMENT_ROOT:e.documentRoot}}),!0):!1}function U(e,n){const i=a.joinPaths(n,"b2config.php"),t=a.joinPaths(n,"b2-include/b2vars.php");return!e.fileExists(i)||!e.fileExists(t)?!1:e.readFileAsText(t).includes("$b2_version = '0.71'")}async function K(e,n){for(const i of[a.joinPaths(n,"wp-includes"),a.joinPaths(n,"wp-content"),a.joinPaths(n,"wp-content/database")])e.isDir(i)||await e.mkdir(i)}async function Q(e,n){const i=a.joinPaths(n,"wp-includes/version.php");await e.writeFile(i,`<?php
824
+ $wp_version = '0.71';
825
+ $wp_db_version = 71;
826
+ `);const t=a.joinPaths(n,"wp-config.php");e.fileExists(t)||await e.writeFile(t,"<?php require_once dirname(__FILE__) . '/b2config.php';");const s=a.joinPaths(n,"wp-load.php");e.fileExists(s)||await e.writeFile(s,`<?php
827
+ if (!defined('ABSPATH')) {
828
+ define('ABSPATH', dirname(__FILE__) . '/');
829
+ }
830
+ require_once ABSPATH . 'b2config.php';
831
+ `);const r=a.joinPaths(n,"wp-admin/post.php");e.fileExists(r)||await e.writeFile(r,"<?php require_once dirname(__FILE__) . '/b2edit.php';")}async function z(e,n){const i=a.joinPaths(n,"b2config.php");let t=e.readFileAsText(i);const s=t;t.includes("pg_wp07_bootstrap")||(t=t.replace("<?php",`<?php
832
+ if (!defined('ABSPATH')) define('ABSPATH', dirname(__FILE__) . '/'); /* pg_wp07_bootstrap */
833
+ if (!defined('WPINC')) define('WPINC', 'b2-include');
834
+ if (!defined('WP_CONTENT_DIR')) define('WP_CONTENT_DIR', ABSPATH . 'wp-content');
835
+ if (!defined('DB_ENGINE')) define('DB_ENGINE', 'sqlite');
836
+ if (!isset($table_prefix)) $table_prefix = 'b2';
837
+ error_reporting(E_ALL & ~E_NOTICE & ~8192 & ~2048);
838
+ `)),t=t.replace(/\$siteurl\s*=\s*'http:\/\/example\.com';[^\n]*/,"$siteurl = defined('WP_SITEURL') ? WP_SITEURL : 'http://localhost'; // pg_wp07_siteurl").replace('$blogname = "my weblog";','$blogname = "My WordPress Website";').replace('$blogdescription = "babblings !";','$blogdescription = "Just another WordPress weblog";').replace("$admin_email = 'you@example.com';","$admin_email = 'admin@localhost.com';").replace("$abspath = getenv('DOCUMENT_ROOT') . $relpath . '/';","$abspath = dirname(__FILE__) . '/';"),t!==s&&await e.writeFile(i,t)}async function Z(e,n){const i=a.joinPaths(n,"blog.header.php");let t=e.readFileAsText(i);const s=t;t=t.replace(`$where .= ' AND (post_status = "publish"';`,`$where .= " AND (post_status = 'publish'";`),t!==s&&await e.writeFile(i,t)}async function J(e,n){const i=a.joinPaths(n,"b2-include/wp-db.php");let t=e.readFileAsText(i);const s=t;t=ee(t),t=t.replace("$wpdb = new wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);",`if (!isset($GLOBALS['wpdb'])) {
839
+ $GLOBALS['wpdb'] = new wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
840
+ }
841
+ $wpdb = $GLOBALS['wpdb']; /* pg_wp07_preserve_sqlite_loader */`),t!==s&&await e.writeFile(i,t)}function ee(e){const n=[];if(e.includes("function set_prefix")||n.push(`
842
+ function set_prefix($prefix) {
843
+ $this->prefix = $prefix;
844
+ $tables = array('posts', 'users', 'categories', 'comments', 'links', 'linkcategories', 'settings', 'options', 'postmeta', 'usermeta', 'terms', 'term_taxonomy', 'term_relationships');
845
+ foreach ($tables as $table) {
846
+ $this->$table = $prefix . $table;
847
+ }
848
+ return $prefix;
849
+ }`),e.includes("function timer_start")||n.push(`
850
+ function timer_start() {
851
+ $this->time_start = microtime(true);
852
+ return true;
853
+ }`),e.includes("function timer_stop")||n.push(`
854
+ function timer_stop() {
855
+ return microtime(true) - $this->time_start;
856
+ }`),e.includes("function init_charset")||n.push(`
857
+ function init_charset() {
858
+ if (defined('DB_CHARSET')) $this->charset = DB_CHARSET;
859
+ if (defined('DB_COLLATE')) $this->collate = DB_COLLATE;
860
+ }`),e.includes("function bail")||n.push(`
861
+ function bail($message, $error_code = '500') {
862
+ die($message);
863
+ }`),e.includes("function check_connection")||n.push(`
864
+ function check_connection($allow_bail = true) {
865
+ return true;
866
+ }`),n.length===0)return e;const i=e.match(/^(\s*})\s*\n+(\$wpdb|if\s*\(\s*!\s*isset\(\s*\$GLOBALS\['wpdb'\]\s*\))/m);if(!i||i.index===void 0)throw new Error("WP 0.7 wpdb polyfill anchor not found; b2-include/wp-db.php layout changed");const t=`
867
+ // Polyfills added by WordPress Playground for WP 0.7.
868
+ `+n.join(`
869
+ `)+`
870
+
871
+ `;return e.substring(0,i.index)+t+e.substring(i.index)}async function te(e,n){const i=a.joinPaths(n,"b2-include/b2template.functions.php");let t=e.readFileAsText(i);const s=t;t.includes("pg_wp07_apply_filters")||(t=t.replace(`function apply_filters($tag, $string) {
872
+ global $b2_filter;
873
+ if (isset($b2_filter['all'])) {
874
+ $b2_filter['all'] = (is_string($b2_filter['all'])) ? array($b2_filter['all']) : $b2_filter['all'];
875
+ $b2_filter[$tag] = array_merge($b2_filter['all'], $b2_filter[$tag]);
876
+ $b2_filter[$tag] = array_unique($b2_filter[$tag]);
877
+ }
878
+ if (isset($b2_filter[$tag])) {
879
+ $b2_filter[$tags] = (is_string($b2_filter[$tag])) ? array($b2_filter[$tag]) : $b2_filter[$tag];
880
+ $functions = $b2_filter[$tag];
881
+ foreach($functions as $function) {
882
+ $string = $function($string);
883
+ }
884
+ }
885
+ return $string;
886
+ }`,`function apply_filters($tag, $string) { /* pg_wp07_apply_filters */
887
+ global $b2_filter;
888
+ $functions = array();
889
+ // WP_SQLite_DB uses apply_filters('query'); b2's all filter texturizes SQL.
890
+ if ($tag != 'query' && isset($b2_filter['all'])) {
891
+ $all = is_array($b2_filter['all']) ? $b2_filter['all'] : array($b2_filter['all']);
892
+ $functions = array_merge($functions, $all);
893
+ }
894
+ if (isset($b2_filter[$tag])) {
895
+ $tag_functions = is_array($b2_filter[$tag]) ? $b2_filter[$tag] : array($b2_filter[$tag]);
896
+ $functions = array_merge($functions, $tag_functions);
897
+ }
898
+ $functions = array_unique($functions);
899
+ foreach($functions as $function) {
900
+ if (function_exists($function)) {
901
+ $string = $function($string);
902
+ }
903
+ }
904
+ return $string;
905
+ }`),t!==s&&await e.writeFile(i,t))}async function ne(e,n){await ie(e,n),await se(e,n),await re(e,n),await ae(e,n)}async function ie(e,n){const i=a.joinPaths(n,"b2login.php");let t=e.readFileAsText(i);const s=t;t.includes("pg_wp07_login_auto_login")||(t=t.replace("switch($action) {",`${S("pg_wp07_login_auto_login")}
906
+ switch($action) {`)),t.includes("pg_wp07_logout_guard")||(t=t.replace(` setcookie('wordpressuser');
907
+ setcookie('wordpresspass');`,` setcookie('wordpressuser', '', time() - 31536000);
908
+ setcookie('wordpresspass', '', time() - 31536000);
909
+ setcookie('wordpressblogid', '', time() - 31536000);
910
+ setcookie('wordpressuser', '', time() - 31536000, '/');
911
+ setcookie('wordpresspass', '', time() - 31536000, '/');
912
+ setcookie('wordpressblogid', '', time() - 31536000, '/');
913
+ setcookie('playground_auto_login_already_logged_out', '1', time() + 172800, '/'); /* pg_wp07_logout_guard */`),t=t.replace("header('Refresh: 0;url=b2login.php');","header('Refresh: 0;url=b2login.php?loggedout=1');").replace("header('Location: b2login.php');","header('Location: b2login.php?loggedout=1');")),t!==s&&await e.writeFile(i,t)}async function se(e,n){const i=a.joinPaths(n,"wp-admin");if(e.isDir(i))for(const t of e.listFiles(i)){if(!t.endsWith(".php"))continue;const s=a.joinPaths(i,t),r=e.readFileAsText(s),o=A(r);o!==r&&await e.writeFile(s,o)}}async function re(e,n){const i=a.joinPaths(n,"wp-admin/b2menutop.php");let t=e.readFileAsText(i);const s=t;t=t.replace('file("./b2menutop.txt")',"file(dirname(__FILE__) . '/b2menutop.txt')").replace('<a href="http://wordpress.org" rel="external"><span>WordPress</span></a>','<a href="#" rel="external"><span>WordPress</span></a>'),t!==s&&await e.writeFile(i,t)}async function ae(e,n){const i=a.joinPaths(n,"wp-admin/b2verifauth.php");let t=e.readFileAsText(i);const s=t;t.includes("pg_wp07_auto_login")||(t=t.replace("require_once('../b2config.php');",`require_once('../b2config.php');
914
+ ${S("pg_wp07_auto_login")}`),t!==s&&await e.writeFile(i,t))}function S(e){return`
915
+ if (isset($_GET['loggedout']) || isset($HTTP_GET_VARS['loggedout'])) {
916
+ $_COOKIE['playground_auto_login_already_logged_out'] = '1';
917
+ unset($_COOKIE['wordpressuser']);
918
+ unset($_COOKIE['wordpresspass']);
919
+ unset($_COOKIE['wordpressblogid']);
920
+ unset($HTTP_COOKIE_VARS['wordpressuser']);
921
+ unset($HTTP_COOKIE_VARS['wordpresspass']);
922
+ unset($HTTP_COOKIE_VARS['wordpressblogid']);
923
+ if (!headers_sent()) {
924
+ setcookie('playground_auto_login_already_logged_out', '1', time() + 172800, '/');
925
+ }
926
+ }
927
+ if (
928
+ defined('PLAYGROUND_AUTO_LOGIN_AS_USER') &&
929
+ empty($_COOKIE['playground_auto_login_already_logged_out']) &&
930
+ (!isset($action) || $action != 'logout')
931
+ ) {
932
+ $_pg_wp07_user = PLAYGROUND_AUTO_LOGIN_AS_USER;
933
+ $_pg_wp07_pass = md5(md5('password'));
934
+ $_COOKIE['wordpressuser'] = $_pg_wp07_user;
935
+ $_COOKIE['wordpresspass'] = $_pg_wp07_pass;
936
+ $_COOKIE['wordpressblogid'] = 1;
937
+ $HTTP_COOKIE_VARS = $_COOKIE;
938
+ $GLOBALS['HTTP_COOKIE_VARS'] = $HTTP_COOKIE_VARS;
939
+ if (!headers_sent()) {
940
+ $_pg_wp07_exp = time() + 172800;
941
+ setcookie('wordpressuser', $_pg_wp07_user, $_pg_wp07_exp, '/');
942
+ setcookie('wordpresspass', $_pg_wp07_pass, $_pg_wp07_exp, '/');
943
+ setcookie('wordpressblogid', 1, $_pg_wp07_exp, '/');
944
+ }
945
+ } /* ${e} */
946
+ `}async function oe(e,n){const i=T(e,n);if(i===null)return;const t=parseFloat(i);if(!Number.isFinite(t)||t<5||t>=6.2)return;const s=a.joinPaths(n,"wp-includes/load.php");if(!e.fileExists(s))return;const r=e.readFileAsText(s),o=r.replace("extension_loaded( 'mysqli' )","function_exists( 'mysqli_connect' )");o!==r&&await e.writeFile(s,o)}function T(e,n){const i=a.joinPaths(n,"wp-includes/version.php");if(!e.fileExists(i))return null;const s=e.readFileAsText(i).match(/\$wp_version\s*=\s*['"]([^'"]+)['"]/);return s?s[1]:null}const _e=22527,E="E_ALL & ~8192 & ~2048";async function le(e,n){if(await V(e,n))return;await Te(e,n),await we(e,n),await Le(e,n),await Pe(e,n),await Ne(e,n),await Fe(e,n),await Ue(e,n),await ve(e,n),await de(e,n),await pe(e,n);const i=T(e,n);if(i===null)return;const t=parseFloat(i);Number.isFinite(t)&&(t<1.2&&(await Ee(e,n),await me(e,n)),t<1.5&&await fe(e,n),1.5<=t&&t<2&&await Ie(e,n),t<2&&(await $e(e,n),await Oe(e,n)),2.1<=t&&t<2.3&&await ge(e,n),t<2.5&&await Se(e,n),t<2.8&&(await ke(e,n),await De(e,n)),2.9<=t&&t<3.6&&await ue(e,n),3.3<=t&&t<3.4&&await he(e,n),t>=4.7&&await ce(e,n))}async function ce(e,n){const i=a.joinPaths(n,"wp-content/themes");if(e.isDir(i))for(const t of e.listFiles(i)){const s=a.joinPaths(i,t,"searchform.php");e.fileExists(s)&&e.unlink(s)}}async function ue(e,n){const i=a.joinPaths(n,"wp-admin/includes/dashboard.php");if(e.fileExists(i)){let r=e.readFileAsText(i);if(r.includes("function wp_dashboard_primary()")&&!r.includes("/* pg_no_rss */")){for(const o of["wp_dashboard_primary","wp_dashboard_secondary","wp_dashboard_plugins"])r=r.replace(new RegExp(`function ${o}\\(\\)\\s*\\{`),`function ${o}() { /* pg_no_rss */ return;`);await e.writeFile(i,r)}}const t=a.joinPaths(n,"wp-admin/admin.php");if(e.fileExists(t)){let r=e.readFileAsText(t);r.includes("do_action('admin_init');")&&!r.includes("/* pg_admin_init_cleanup */")&&(r=r.replace("do_action('admin_init');",`/* pg_admin_init_cleanup */
694
947
  if (function_exists('remove_action')) {
695
948
  @remove_action('admin_init', '_maybe_update_plugins');
696
949
  @remove_action('admin_init', '_maybe_update_themes');
@@ -699,21 +952,21 @@ if (function_exists('remove_action')) {
699
952
  @remove_action('admin_init', 'wp_update_plugins');
700
953
  @remove_action('admin_init', 'wp_update_themes');
701
954
  }
702
- do_action('admin_init');`),await e.writeFile(n,r))}const s=o.joinPaths(t,"wp-admin/includes/update.php");if(e.fileExists(s)){let r=e.readFileAsText(s);if(!r.includes("/* pg_admin_no_updates */")){for(const a of["wp_plugin_update_rows","wp_plugin_update_row","wp_theme_update_rows","wp_theme_update_row","wp_update_plugins","wp_update_themes"]){const _=new RegExp(`function ${a}\\s*\\([^)]*\\)\\s*\\{`);_.test(r)&&(r=r.replace(_,l=>l+" /* pg_admin_no_updates */ return;"))}await e.writeFile(s,r)}}for(const r of[o.joinPaths(t,"wp-includes/SimplePie/File.php"),o.joinPaths(t,"wp-includes/class-simplepie.php")]){if(!e.fileExists(r))continue;let a=e.readFileAsText(r);a.includes("function SimplePie_File(")&&!a.includes("/* pg_no_fetch */")&&(a=a.replace(/function SimplePie_File\([^)]*\)\s*\{/,_=>_+`
955
+ do_action('admin_init');`),await e.writeFile(t,r))}const s=a.joinPaths(n,"wp-admin/includes/update.php");if(e.fileExists(s)){let r=e.readFileAsText(s);if(!r.includes("/* pg_admin_no_updates */")){for(const o of["wp_plugin_update_rows","wp_plugin_update_row","wp_theme_update_rows","wp_theme_update_row","wp_update_plugins","wp_update_themes"]){const _=new RegExp(`function ${o}\\s*\\([^)]*\\)\\s*\\{`);_.test(r)&&(r=r.replace(_,l=>l+" /* pg_admin_no_updates */ return;"))}await e.writeFile(s,r)}}for(const r of[a.joinPaths(n,"wp-includes/SimplePie/File.php"),a.joinPaths(n,"wp-includes/class-simplepie.php")]){if(!e.fileExists(r))continue;let o=e.readFileAsText(r);o.includes("function SimplePie_File(")&&!o.includes("/* pg_no_fetch */")&&(o=o.replace(/function SimplePie_File\([^)]*\)\s*\{/,_=>_+`
703
956
  /* pg_no_fetch */
704
957
  $this->error = 'Network requests disabled in Playground';
705
958
  $this->success = false;
706
- return;`),await e.writeFile(r,a))}}async function Y(e,t){const i=[["function wp_new_blog_notification","pg_no_blog_notification"],["function wp_install_maybe_enable_pretty_permalinks","pg_no_permalink_check"]],n=[o.joinPaths(t,"wp-admin/includes/upgrade.php"),o.joinPaths(t,"wp-admin/upgrade-functions.php")];for(const s of n){if(!e.fileExists(s))continue;let r=e.readFileAsText(s),a=!1;for(const[_,l]of i){if(r.includes(`/* ${l} */`))continue;const c=r.indexOf(_);if(c===-1)continue;const u=r.indexOf("{",c);u!==-1&&(r=r.substring(0,u+1)+` /* ${l} */ return;`+r.substring(u+1),a=!0)}a&&await e.writeFile(s,r)}}async function K(e,t){const i=o.joinPaths(t,"wp-load.php");if(!e.fileExists(i))return;const n=e.readFileAsText(i);if(!n.includes("error_reporting(")||n.includes("~8192")&&n.includes("~2048"))return;const s=n.replace(/error_reporting\(([^)]+)\)/g,(r,a)=>`error_reporting((${a}) & ~8192 & ~2048)`);await e.writeFile(i,s)}async function Q(e,t){const i=o.joinPaths(t,"wp-admin/menu.php");if(e.fileExists(i)){const r=e.readFileAsText(i);if(!r.includes("/* pg_wp10_logo_link */")){const a='<h1 id="wphead"><a href="http://wordpress.org" rel="external">WordPress</a></h1>';if(r.includes(a)){const _=r.replace(a,'<h1 id="wphead"><a href="#" rel="external">WordPress</a></h1> <!-- pg_wp10_logo_link -->');_!==r&&await e.writeFile(i,_)}}}const n=o.joinPaths(t,"wp-admin/admin-header.php");if(e.fileExists(n)){const r=e.readFileAsText(n);if(!r.includes("/* pg_wp12_logo_link */")){const a='<a href="http://wordpress.org" rel="external"',_="</a>",l=r.indexOf(a);if(l!==-1){const c=r.indexOf(_,l);if(c!==-1){const u=r.substring(0,l)+'<a href="#">WordPress</a><!-- pg_wp12_logo_link -->'+r.substring(c+_.length);u!==r&&await e.writeFile(n,u)}}}}const s=o.joinPaths(t,"wp-admin/admin-footer.php");if(e.fileExists(s)){const r=e.readFileAsText(s);if(!r.includes("/* pg_wp10_footer_link */")){const a=r.replace('<a href="http://wordpress.org">WordPress</a>',"WordPress<!-- pg_wp10_footer_link -->").replace('<a href="http://wordpress.org/">WordPress</a>',"WordPress<!-- pg_wp10_footer_link -->");a!==r&&await e.writeFile(s,a)}}}async function z(e,t){const i=o.joinPaths(t,"wp-admin/edit.php");if(!e.fileExists(i))return;const n=e.readFileAsText(i);if(n.includes("/* pg_wp10_post_title_edit */"))return;let s=n;const r='<strong><a href="<?php permalink_link(); ?>" rel="permalink"><?php the_title() ?></a></strong>';s.includes(r)&&(s=s.replace(r,'<strong><a href="post.php?action=edit&amp;post=<?php echo $id /* pg_wp10_post_title_edit */ ?>"><?php the_title() ?></a></strong>'));const a='<td><a href="<?php the_permalink(); ?>" rel="permalink">';s.includes(a)&&(s=s.replace(a,'<td><a href="post.php?action=edit&amp;post=<?php echo $id /* pg_wp10_post_title_edit */ ?>">'));const _=`<td><?php the_title() ?>
959
+ return;`),await e.writeFile(r,o))}}async function pe(e,n){const i=[["function wp_new_blog_notification","pg_no_blog_notification"],["function wp_install_maybe_enable_pretty_permalinks","pg_no_permalink_check"]],t=[a.joinPaths(n,"wp-admin/includes/upgrade.php"),a.joinPaths(n,"wp-admin/upgrade-functions.php")];for(const s of t){if(!e.fileExists(s))continue;let r=e.readFileAsText(s),o=!1;for(const[_,l]of i){if(r.includes(`/* ${l} */`))continue;const c=r.indexOf(_);if(c===-1)continue;const u=r.indexOf("{",c);u!==-1&&(r=r.substring(0,u+1)+` /* ${l} */ return;`+r.substring(u+1),o=!0)}o&&await e.writeFile(s,r)}}async function de(e,n){const i=a.joinPaths(n,"wp-load.php");if(!e.fileExists(i))return;const t=e.readFileAsText(i);if(!t.includes("error_reporting(")||t.includes("~8192")&&t.includes("~2048"))return;const s=t.replace(/error_reporting\(([^)]+)\)/g,(r,o)=>`error_reporting((${o}) & ~8192 & ~2048)`);await e.writeFile(i,s)}async function fe(e,n){const i=a.joinPaths(n,"wp-admin/menu.php");if(e.fileExists(i)){const r=e.readFileAsText(i);if(!r.includes("/* pg_wp10_logo_link */")){const o='<h1 id="wphead"><a href="http://wordpress.org" rel="external">WordPress</a></h1>';if(r.includes(o)){const _=r.replace(o,'<h1 id="wphead"><a href="#" rel="external">WordPress</a></h1> <!-- pg_wp10_logo_link -->');_!==r&&await e.writeFile(i,_)}}}const t=a.joinPaths(n,"wp-admin/admin-header.php");if(e.fileExists(t)){const r=e.readFileAsText(t);if(!r.includes("/* pg_wp12_logo_link */")){const o='<a href="http://wordpress.org" rel="external"',_="</a>",l=r.indexOf(o);if(l!==-1){const c=r.indexOf(_,l);if(c!==-1){const u=r.substring(0,l)+'<a href="#">WordPress</a><!-- pg_wp12_logo_link -->'+r.substring(c+_.length);u!==r&&await e.writeFile(t,u)}}}}const s=a.joinPaths(n,"wp-admin/admin-footer.php");if(e.fileExists(s)){const r=e.readFileAsText(s);if(!r.includes("/* pg_wp10_footer_link */")){const o=r.replace('<a href="http://wordpress.org">WordPress</a>',"WordPress<!-- pg_wp10_footer_link -->").replace('<a href="http://wordpress.org/">WordPress</a>',"WordPress<!-- pg_wp10_footer_link -->");o!==r&&await e.writeFile(s,o)}}}async function $e(e,n){const i=a.joinPaths(n,"wp-admin/edit.php");if(!e.fileExists(i))return;const t=e.readFileAsText(i);if(t.includes("/* pg_wp10_post_title_edit */"))return;let s=t;const r='<strong><a href="<?php permalink_link(); ?>" rel="permalink"><?php the_title() ?></a></strong>';s.includes(r)&&(s=s.replace(r,'<strong><a href="post.php?action=edit&amp;post=<?php echo $id /* pg_wp10_post_title_edit */ ?>"><?php the_title() ?></a></strong>'));const o='<td><a href="<?php the_permalink(); ?>" rel="permalink">';s.includes(o)&&(s=s.replace(o,'<td><a href="post.php?action=edit&amp;post=<?php echo $id /* pg_wp10_post_title_edit */ ?>">'));const _=`<td><?php the_title() ?>
707
960
  <?php if ('private' == $post->post_status) _e(' - <strong>Private</strong>'); ?></td>`;s.includes(_)&&(s=s.replace(_,`<td><a href="post.php?action=edit&amp;post=<?php echo $id /* pg_wp10_post_title_edit */ ?>"><?php the_title() ?></a>
708
- <?php if ('private' == $post->post_status) _e(' - <strong>Private</strong>'); ?></td>`)),s!==n&&await e.writeFile(i,s)}async function Z(e,t){const i=o.joinPaths(t,"wp-admin/includes/screen.php");if(!e.fileExists(i))return;const n=e.readFileAsText(i);if(!n.includes("self::$this->_help_sidebar"))return;const s=n.replace(/self::\$this->_help_sidebar/g,"$this->_help_sidebar");s!==n&&await e.writeFile(i,s)}async function J(e,t){const i=o.joinPaths(t,"wp-admin/plugins.php");if(!e.fileExists(i))return;const n=e.readFileAsText(i);if(n.includes("/* pg_wp21_active_plugins_array */"))return;const s="$current = get_option('active_plugins');";if(!n.includes(s))return;const r=n.replace(s,s+`
709
- if (!is_array($current)) $current = array(); /* pg_wp21_active_plugins_array */`);r!==n&&await e.writeFile(i,r)}async function ee(e,t){const i=o.joinPaths(t,"wp-login.php");if(!e.fileExists(i))return;const n=e.readFileAsText(i),s="AND user_pass = '$password'";if(!n.includes(s)||n.includes("pg_wp10_plain_or_md5"))return;let r=n.replace(s,"AND (user_pass = '$password' OR user_pass = MD5('$password')) /* pg_wp10_plain_or_md5 */");r=r.replace("$login->user_pass == $password","($login->user_pass == $password || $login->user_pass == md5($password))"),r!==n&&await e.writeFile(i,r)}async function te(e,t){const i=o.joinPaths(t,"wp-includes");if(!e.isDir(i))return;const n=o.joinPaths(i,"version.php");e.fileExists(n)||await e.writeFile(n,"<?php $wp_version = '1.0';")}async function ne(e,t){const i=o.joinPaths(t,"wp-blog-header.php");if(e.fileExists(i)){const s=e.readFileAsText(i),r=`$where .= ' AND (post_status = "publish"';`;s.includes(r)&&await e.writeFile(i,s.replace(r,`$where .= " AND (post_status = 'publish'";`))}const n=o.joinPaths(t,"wp-includes/vars.php");if(e.fileExists(n)){const s=e.readFileAsText(n),r="add_filter('all', 'wptexturize');";s.includes(r)&&await e.writeFile(n,s.replace(r,`// ${r} // Disabled by Playground: mangles SQL literals.`))}}async function ie(e,t){const i=o.joinPaths(t,"wp-load.php");e.fileExists(i)||await e.writeFile(i,`<?php
961
+ <?php if ('private' == $post->post_status) _e(' - <strong>Private</strong>'); ?></td>`)),s!==t&&await e.writeFile(i,s)}async function he(e,n){const i=a.joinPaths(n,"wp-admin/includes/screen.php");if(!e.fileExists(i))return;const t=e.readFileAsText(i);if(!t.includes("self::$this->_help_sidebar"))return;const s=t.replace(/self::\$this->_help_sidebar/g,"$this->_help_sidebar");s!==t&&await e.writeFile(i,s)}async function ge(e,n){const i=a.joinPaths(n,"wp-admin/plugins.php");if(!e.fileExists(i))return;const t=e.readFileAsText(i);if(t.includes("/* pg_wp21_active_plugins_array */"))return;const s="$current = get_option('active_plugins');";if(!t.includes(s))return;const r=t.replace(s,s+`
962
+ if (!is_array($current)) $current = array(); /* pg_wp21_active_plugins_array */`);r!==t&&await e.writeFile(i,r)}async function me(e,n){const i=a.joinPaths(n,"wp-login.php");if(!e.fileExists(i))return;const t=e.readFileAsText(i),s="AND user_pass = '$password'";if(!t.includes(s)||t.includes("pg_wp10_plain_or_md5"))return;let r=t.replace(s,"AND (user_pass = '$password' OR user_pass = MD5('$password')) /* pg_wp10_plain_or_md5 */");r=r.replace("$login->user_pass == $password","($login->user_pass == $password || $login->user_pass == md5($password))"),r!==t&&await e.writeFile(i,r)}async function Te(e,n){const i=a.joinPaths(n,"wp-includes");if(!e.isDir(i))return;const t=a.joinPaths(i,"version.php");e.fileExists(t)||await e.writeFile(t,"<?php $wp_version = '1.0';")}async function Ee(e,n){const i=a.joinPaths(n,"wp-blog-header.php");if(e.fileExists(i)){const s=e.readFileAsText(i),r=`$where .= ' AND (post_status = "publish"';`;s.includes(r)&&await e.writeFile(i,s.replace(r,`$where .= " AND (post_status = 'publish'";`))}const t=a.joinPaths(n,"wp-includes/vars.php");if(e.fileExists(t)){const s=e.readFileAsText(t),r="add_filter('all', 'wptexturize');";s.includes(r)&&await e.writeFile(t,s.replace(r,`// ${r} // Disabled by Playground: mangles SQL literals.`))}}async function we(e,n){const i=a.joinPaths(n,"wp-load.php");e.fileExists(i)||await e.writeFile(i,`<?php
710
963
  if ( !defined('ABSPATH') ) {
711
964
  define('ABSPATH', dirname(__FILE__) . '/');
712
965
  }
713
966
  require_once(ABSPATH . 'wp-config.php');
714
- `)}async function se(e,t){const i=o.joinPaths(t,"wp-settings.php");if(!e.fileExists(i))return;const n=e.readFileAsText(i);let s=n;s=s.replace(/if\s*\(\s*!extension_loaded\('mysql'\)\s*\)\s*\n\s*die/,`if ( false ) // Patched for SQLite
715
- die`),s=s.replace(/error_reporting\(([^)]+)\)/g,(r,a)=>a.includes("~8192")&&a.includes("~2048")?r:`error_reporting((${a}) & ~8192 & ~2048)`),s=s.replace(/set_magic_quotes_runtime\(\s*0\s*\)\s*;/g,"// set_magic_quotes_runtime(0); // Removed"),s.includes("function_exists('get_magic_quotes_gpc')")||(s=s.replace(/get_magic_quotes_gpc\(\)/g,"(function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc())")),s=s.replace(/=\s*&\s*new\b/g,"= new"),s=s.replace(/\$HTTP_SERVER_VARS/g,"$_SERVER"),!s.includes("WP_CONTENT_DIR")&&s.includes("define('WPINC'")&&(s=s.replace(/define\('WPINC',\s*'wp-includes'\);/,`define('WPINC', 'wp-includes');
716
- if (!defined('WP_CONTENT_DIR')) define('WP_CONTENT_DIR', ABSPATH . 'wp-content');`)),s=s.replace(/unset\(\s*\$wp_filter\s*,/,"unset("),s=re(s),s=ae(s),s!==n&&await e.writeFile(i,s)}function re(e){const t=e.indexOf("installed WP");if(t===-1)return e;const i=e.lastIndexOf("die(",t);if(i===-1)return e;let n=0;for(let s=i+3;s<e.length;s++)if(e[s]==="(")n++;else if(e[s]===")"&&(n--,n===0)){let r=s+1;return e[r]===";"&&r++,e.substring(0,i)+"true; /* die removed by Playground */"+e.substring(r)}return e}function ae(e){return e.replace("do_action('init');",`// Remove hooks that make outbound HTTP requests (crash WASM).
967
+ `)}async function Le(e,n){const i=a.joinPaths(n,"wp-settings.php");if(!e.fileExists(i))return;const t=e.readFileAsText(i);let s=t;s=s.replace(/if\s*\(\s*!extension_loaded\('mysql'\)\s*\)\s*\n\s*die/,`if ( false ) // Patched for SQLite
968
+ die`),s=s.replace(/error_reporting\(([^)]+)\)/g,(r,o)=>o.includes("~8192")&&o.includes("~2048")?r:`error_reporting((${o}) & ~8192 & ~2048)`),s=s.replace(/set_magic_quotes_runtime\(\s*0\s*\)\s*;/g,"// set_magic_quotes_runtime(0); // Removed"),s.includes("function_exists('get_magic_quotes_gpc')")||(s=s.replace(/get_magic_quotes_gpc\(\)/g,"(function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc())")),s=s.replace(/=\s*&\s*new\b/g,"= new"),s=s.replace(/\$HTTP_SERVER_VARS/g,"$_SERVER"),!s.includes("WP_CONTENT_DIR")&&s.includes("define('WPINC'")&&(s=s.replace(/define\('WPINC',\s*'wp-includes'\);/,`define('WPINC', 'wp-includes');
969
+ if (!defined('WP_CONTENT_DIR')) define('WP_CONTENT_DIR', ABSPATH . 'wp-content');`)),s=s.replace(/unset\(\s*\$wp_filter\s*,/,"unset("),s=ye(s),s=be(s),s!==t&&await e.writeFile(i,s)}function ye(e){const n=e.indexOf("installed WP");if(n===-1)return e;const i=e.lastIndexOf("die(",n);if(i===-1)return e;let t=0;for(let s=i+3;s<e.length;s++)if(e[s]==="(")t++;else if(e[s]===")"&&(t--,t===0)){let r=s+1;return e[r]===";"&&r++,e.substring(0,i)+"true; /* die removed by Playground */"+e.substring(r)}return e}function be(e){return e.replace("do_action('init');",`// Remove hooks that make outbound HTTP requests (crash WASM).
717
970
  if (function_exists('remove_action')) {
718
971
  @remove_action('init', 'wp_cron');
719
972
  @remove_action('init', 'wp_version_check');
@@ -739,8 +992,8 @@ if (function_exists('add_filter')) {
739
992
  @add_filter('use_ftp_transport', '_pg_disable_curl');
740
993
  @add_filter('use_fsockopen_transport', '_pg_disable_streams');
741
994
  }
742
- do_action('init');`)}async function oe(e,t){const i=o.joinPaths(t,"wp-includes/functions.php");if(!e.fileExists(i))return;let n=e.readFileAsText(i),s=!1;n.includes("$all_options->{$option->option_name}")&&!n.includes("$all_options = new stdClass")&&(n=n.replace("foreach ($options as $option) {",`$all_options = new stdClass;
743
- foreach ($options as $option) {`),s=!0),s&&await e.writeFile(i,n)}async function _e(e,t){const i=o.joinPaths(t,"wp-admin/install.php");if(!e.fileExists(i))return;const n=e.readFileAsText(i);let s=n;const r=o.joinPaths(t,"wp-admin");s=s.replace(/'\.\.\/(wp-config\.php)'/g,`'${t}/$1'`).replace(/'\.\.\/(wp-load\.php)'/g,`'${t}/$1'`).replace(/'\.\/(upgrade-functions\.php)'/g,`'${r}/$1'`).replace(/'(upgrade-functions\.php)'/g,`'${r}/$1'`).replace(/'\.\/(includes\/upgrade\.php)'/g,`'${r}/$1'`).replace(/'\.\.\/(wp-includes\/[^']+)'/g,`'${t}/$1'`),s=s.replace(/\$HTTP_GET_VARS/g,"$_GET").replace(/\$HTTP_POST_VARS/g,"$_POST"),s!==n&&await e.writeFile(i,s)}async function le(e,t){const i=o.joinPaths(t,"wp-includes/wp-db.php");if(!e.fileExists(i))return;const n=e.readFileAsText(i);let s=n;s.includes("isset($wpdb)")||(s=s.replace("$wpdb = new wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);","if ( !isset($wpdb) ) { $wpdb = new wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST); }")),s.includes("db_connect")||(s=s.replace(/\$this->dbh\s*=\s*@mysql_connect\(\$dbhost\s*,\s*\$dbuser\s*,\s*\$dbpassword(?:\s*,\s*true)?\);/,'if (method_exists($this, "db_connect")) { $this->dbname = $dbname; $this->db_connect(); } else { $this->dbh = @mysql_connect($dbhost, $dbuser, $dbpassword); }')),s=ce(s),s!==n&&await e.writeFile(i,s)}function ce(e){const t=[];if(e.includes("function set_prefix")||t.push(`
995
+ do_action('init');`)}async function Oe(e,n){const i=a.joinPaths(n,"wp-includes/functions.php");if(!e.fileExists(i))return;let t=e.readFileAsText(i),s=!1;t.includes("$all_options->{$option->option_name}")&&!t.includes("$all_options = new stdClass")&&(t=t.replace("foreach ($options as $option) {",`$all_options = new stdClass;
996
+ foreach ($options as $option) {`),s=!0),s&&await e.writeFile(i,t)}async function Pe(e,n){const i=a.joinPaths(n,"wp-admin/install.php");if(!e.fileExists(i))return;const t=e.readFileAsText(i);let s=t;const r=a.joinPaths(n,"wp-admin");s=s.replace(/'\.\.\/(wp-config\.php)'/g,`'${n}/$1'`).replace(/'\.\.\/(wp-load\.php)'/g,`'${n}/$1'`).replace(/'\.\/(upgrade-functions\.php)'/g,`'${r}/$1'`).replace(/'(upgrade-functions\.php)'/g,`'${r}/$1'`).replace(/'\.\/(includes\/upgrade\.php)'/g,`'${r}/$1'`).replace(/'\.\.\/(wp-includes\/[^']+)'/g,`'${n}/$1'`),s=s.replace(/\$HTTP_GET_VARS/g,"$_GET").replace(/\$HTTP_POST_VARS/g,"$_POST"),s!==t&&await e.writeFile(i,s)}async function Ne(e,n){const i=a.joinPaths(n,"wp-includes/wp-db.php");if(!e.fileExists(i))return;const t=e.readFileAsText(i);let s=t;s.includes("isset($wpdb)")||(s=s.replace("$wpdb = new wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);","if ( !isset($wpdb) ) { $wpdb = new wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST); }")),s.includes("db_connect")||(s=s.replace(/\$this->dbh\s*=\s*@mysql_connect\(\$dbhost\s*,\s*\$dbuser\s*,\s*\$dbpassword(?:\s*,\s*true)?\);/,'if (method_exists($this, "db_connect")) { $this->dbname = $dbname; $this->db_connect(); } else { $this->dbh = @mysql_connect($dbhost, $dbuser, $dbpassword); }')),s=Ae(s),s!==t&&await e.writeFile(i,s)}function Ae(e){const n=[];if(e.includes("function set_prefix")||n.push(`
744
997
  function set_prefix($prefix) {
745
998
  $this->prefix = $prefix;
746
999
  $tables = array('posts', 'users', 'categories', 'post2cat', 'comments', 'link2cat', 'links', 'options', 'postmeta', 'usermeta', 'terms', 'term_taxonomy', 'term_relationships');
@@ -748,31 +1001,31 @@ do_action('init');`)}async function oe(e,t){const i=o.joinPaths(t,"wp-includes/f
748
1001
  $this->$t = $prefix . $t;
749
1002
  }
750
1003
  return $prefix;
751
- }`),e.includes("function timer_start")||t.push(`
1004
+ }`),e.includes("function timer_start")||n.push(`
752
1005
  function timer_start() {
753
1006
  $this->time_start = microtime(true);
754
1007
  return true;
755
- }`),e.includes("function timer_stop")||t.push(`
1008
+ }`),e.includes("function timer_stop")||n.push(`
756
1009
  function timer_stop() {
757
1010
  return microtime(true) - $this->time_start;
758
- }`),e.includes("function init_charset")||t.push(`
1011
+ }`),e.includes("function init_charset")||n.push(`
759
1012
  function init_charset() {
760
1013
  if (defined('DB_CHARSET')) $this->charset = DB_CHARSET;
761
1014
  if (defined('DB_COLLATE')) $this->collate = DB_COLLATE;
762
- }`),e.includes("function bail")||t.push(`
1015
+ }`),e.includes("function bail")||n.push(`
763
1016
  function bail($message, $error_code = '500') {
764
1017
  die($message);
765
- }`),e.includes("function check_connection")||t.push(`
1018
+ }`),e.includes("function check_connection")||n.push(`
766
1019
  function check_connection($allow_bail = true) {
767
1020
  return true;
768
- }`),t.length===0)return e;const i=e.match(/^(\s*})\s*\n+(\$wpdb|\?>\s*$|if\s*\(\s*!\s*isset\(\s*\$wpdb\s*\))/m);if(!i||i.index===void 0)return e;const n=`
1021
+ }`),n.length===0)return e;const i=e.match(/^(\s*})\s*\n+(\$wpdb|\?>\s*$|if\s*\(\s*!\s*isset\(\s*\$wpdb\s*\))/m);if(!i||i.index===void 0)return e;const t=`
769
1022
  // Polyfills added by WordPress Playground.
770
- `+t.join(`
1023
+ `+n.join(`
771
1024
  `)+`
772
1025
 
773
- `;return e.substring(0,i.index)+n+e.substring(i.index)}async function ue(e,t){const i=a=>{let _=a,l=0;for(;_.startsWith("../");)l++,_=_.slice(3);for(;_.startsWith("./");)_=_.slice(2);let c="dirname(__FILE__)";for(let u=0;u<l;u++)c=`dirname(${c})`;return`${c} . '/${_}'`},n=o.joinPaths(t,"wp-admin");if(e.isDir(n))for(const a of e.listFiles(n)){if(!a.endsWith(".php"))continue;const _=o.joinPaths(n,a),l=e.readFileAsText(_),c=l.replace(/((?:require|include)(?:_once)?)\s*\(\s*(['"])(\.\.\/[^'"]+)\2\s*\)/g,(u,d,$,p)=>`${d}(${i(p)})`).replace(/((?:require|include)(?:_once)?)\s*\(\s*(['"])(\.\/[^'"]+)\2\s*\)/g,(u,d,$,p)=>`${d}(${i(p)})`).replace(/((?:require|include)(?:_once)?)\s*\(\s*(['"])([a-z][\w-]*\.php)\2\s*\)/g,(u,d,$,p)=>`${d}(${i(p)})`).replace(/((?:require|include)(?:_once)?)\s+(['"])(\.\.\/[^'"]+)\2/g,(u,d,$,p)=>`${d}(${i(p)})`).replace(/((?:require|include)(?:_once)?)\s+(['"])(\.\/[^'"]+)\2/g,(u,d,$,p)=>`${d}(${i(p)})`).replace(/((?:require|include)(?:_once)?)\s+(['"])([a-z][\w-]*\.php)\2/g,(u,d,$,p)=>`${d}(${i(p)})`).replace(/ABSPATH\s*\.\s*'\/wp-/g,"ABSPATH . 'wp-");c!==l&&await e.writeFile(_,c)}const s=o.joinPaths(t,"wp-admin/index.php");if(e.fileExists(s)){let a=e.readFileAsText(s);a.includes("get_settings('siteurl')")&&(a=a.replace(/get_settings\('siteurl'\)\s*\.\s*'\/wp-admin\//g,"'"),await e.writeFile(s,a))}const r=o.joinPaths(t,"wp-admin/menu.php");if(e.fileExists(r)){const a=e.readFileAsText(r),_="file('./menu.txt')";a.includes(_)&&await e.writeFile(r,a.replace(_,"file(dirname(__FILE__) . '/menu.txt')"))}}async function de(e,t){const i=o.joinPaths(t,"wp-admin/admin-functions.php");if(!e.fileExists(i))return;const n=e.readFileAsText(i);if(!n.includes("function check_admin_referer()")||!n.includes("$_SERVER['HTTP_REFERER']"))return;const s=pe(n,"check_admin_referer",`
1026
+ `;return e.substring(0,i.index)+t+e.substring(i.index)}async function Ue(e,n){const i=a.joinPaths(n,"wp-admin");if(e.isDir(i))for(const r of e.listFiles(i)){if(!r.endsWith(".php"))continue;const o=a.joinPaths(i,r),_=e.readFileAsText(o),l=A(_).replace(/ABSPATH\s*\.\s*'\/wp-/g,"ABSPATH . 'wp-");l!==_&&await e.writeFile(o,l)}const t=a.joinPaths(n,"wp-admin/index.php");if(e.fileExists(t)){let r=e.readFileAsText(t);r.includes("get_settings('siteurl')")&&(r=r.replace(/get_settings\('siteurl'\)\s*\.\s*'\/wp-admin\//g,"'"),await e.writeFile(t,r))}const s=a.joinPaths(n,"wp-admin/menu.php");if(e.fileExists(s)){const r=e.readFileAsText(s),o="file('./menu.txt')";r.includes(o)&&await e.writeFile(s,r.replace(o,"file(dirname(__FILE__) . '/menu.txt')"))}}async function Se(e,n){const i=a.joinPaths(n,"wp-admin/admin-functions.php");if(!e.fileExists(i))return;const t=e.readFileAsText(i);if(!t.includes("function check_admin_referer()")||!t.includes("$_SERVER['HTTP_REFERER']"))return;const s=Re(t,"check_admin_referer",`
774
1027
  do_action('check_admin_referer', '');
775
- `);s!==n&&await e.writeFile(i,s)}function pe(e,t,i){const n=`function ${t}()`,s=e.indexOf(n);if(s===-1)return e;const r=e.indexOf("{",s+n.length);if(r===-1)return e;let a=1;for(let _=r+1;_<e.length;_++){const l=e[_];if(l==="{")a++;else if(l==="}"&&(a--,a===0))return e.substring(0,r+1)+i+e.substring(_)}return e}async function fe(e,t){const i=o.joinPaths(t,"wp-admin/index.php");if(e.fileExists(i)){const n=e.readFileAsText(i),s=n.replace(/AND post_date_gmt < '\$today'/,"");s!==n&&await e.writeFile(i,s)}await $e(e,t)}async function $e(e,t){const i=o.joinPaths(t,"wp-includes/rss-functions.php");if(!e.fileExists(i))return;let n=e.readFileAsText(i);!/^\s*error\s*\(/m.test(n)||/^function\s+error\s*\(/m.test(n)||(n=n.replace(/^(<\?php\s*)/,`$1
1028
+ `);s!==t&&await e.writeFile(i,s)}function Re(e,n,i){const t=`function ${n}()`,s=e.indexOf(t);if(s===-1)return e;const r=e.indexOf("{",s+t.length);if(r===-1)return e;let o=1;for(let _=r+1;_<e.length;_++){const l=e[_];if(l==="{")o++;else if(l==="}"&&(o--,o===0))return e.substring(0,r+1)+i+e.substring(_)}return e}async function Ie(e,n){const i=a.joinPaths(n,"wp-admin/index.php");if(e.fileExists(i)){const t=e.readFileAsText(i),s=t.replace(/AND post_date_gmt < '\$today'/,"");s!==t&&await e.writeFile(i,s)}await xe(e,n)}async function xe(e,n){const i=a.joinPaths(n,"wp-includes/rss-functions.php");if(!e.fileExists(i))return;let t=e.readFileAsText(i);!/^\s*error\s*\(/m.test(t)||/^function\s+error\s*\(/m.test(t)||(t=t.replace(/^(<\?php\s*)/,`$1
776
1029
  if (!function_exists('error')) {
777
1030
  function error($msg = '', $lvl = E_USER_WARNING) {
778
1031
  if (defined('MAGPIE_DEBUG') && MAGPIE_DEBUG) {
@@ -780,7 +1033,7 @@ if (!function_exists('error')) {
780
1033
  }
781
1034
  }
782
1035
  }
783
- `),await e.writeFile(i,n))}async function he(e,t){const i=o.joinPaths(t,"wp-login.php");if(!e.fileExists(i))return;let n=e.readFileAsText(i),s=!1;for(const r of["log","pwd"]){const a=new RegExp(`(\\bname=(['"])${r}\\2)(?![^>]*data-1p-ignore)`);a.test(n)&&(n=n.replace(a,"$1 data-1p-ignore"),s=!0)}s&&await e.writeFile(i,n)}async function ge(e,t){const i=o.joinPaths(t,"wp-admin/admin.php");if(e.fileExists(i)){const s=e.readFileAsText(i);if(s.includes("auth_redirect()")){const r=`
1036
+ `),await e.writeFile(i,t))}async function ve(e,n){const i=a.joinPaths(n,"wp-login.php");if(!e.fileExists(i))return;let t=e.readFileAsText(i),s=!1;for(const r of["log","pwd"]){const o=new RegExp(`(\\bname=(['"])${r}\\2)(?![^>]*data-1p-ignore)`);o.test(t)&&(t=t.replace(o,"$1 data-1p-ignore"),s=!0)}s&&await e.writeFile(i,t)}async function ke(e,n){const i=a.joinPaths(n,"wp-admin/admin.php");if(e.fileExists(i)){const s=e.readFileAsText(i);if(s.includes("auth_redirect()")){const r=`
784
1037
  // Playground: populate auth cookies and force admin user before auth_redirect.
785
1038
  if (defined('PLAYGROUND_AUTO_LOGIN_AS_USER')) {
786
1039
  if (function_exists('is_user_logged_in') && is_user_logged_in()) {
@@ -795,7 +1048,7 @@ if (defined('PLAYGROUND_AUTO_LOGIN_AS_USER')) {
795
1048
  $_COOKIE[LOGGED_IN_COOKIE] = wp_generate_auth_cookie($_pg_uid, $_pg_exp, 'logged_in');
796
1049
  }
797
1050
  } else {
798
- ${A("PLAYGROUND_AUTO_LOGIN_AS_USER")}
1051
+ ${R("PLAYGROUND_AUTO_LOGIN_AS_USER")}
799
1052
  // WP 2.0-2.4: kses_init() runs during do_action('init') inside
800
1053
  // wp-settings.php and caches $current_user as WP_User(0) when
801
1054
  // no cookies were set yet. Reset and re-evaluate so capability
@@ -845,7 +1098,7 @@ if (defined('PLAYGROUND_AUTO_LOGIN_AS_USER')) {
845
1098
  }
846
1099
  }
847
1100
  }
848
- `,a=s.replace("auth_redirect();",r+"auth_redirect();");a!==s&&await e.writeFile(i,a)}}const n=o.joinPaths(t,"wp-admin/auth.php");if(e.fileExists(n)){const s=e.readFileAsText(n);if(s.includes("$cookiehash")&&!s.includes("Playground: bypass auth")){const r=`<?php
1101
+ `,o=s.replace("auth_redirect();",r+"auth_redirect();");o!==s&&await e.writeFile(i,o)}}const t=a.joinPaths(n,"wp-admin/auth.php");if(e.fileExists(t)){const s=e.readFileAsText(t);if(s.includes("$cookiehash")&&!s.includes("Playground: bypass auth")){const r=`<?php
849
1102
  require_once(ABSPATH . 'wp-config.php');
850
1103
  // Playground: bypass auth and manually populate user globals.
851
1104
  global $user_login, $userdata, $user_level, $user_ID,
@@ -884,12 +1137,12 @@ if (function_exists('get_userdatabylogin')) {
884
1137
  );
885
1138
  }
886
1139
  }
887
- ?>`;r!==s&&await e.writeFile(n,r)}}}async function me(e,t){const i=o.joinPaths(t,"wp-admin/admin-ajax.php");if(!e.fileExists(i))return;let n=e.readFileAsText(i);if(!n.includes("is_user_logged_in"))return;const s=`
1140
+ ?>`;r!==s&&await e.writeFile(t,r)}}}async function De(e,n){const i=a.joinPaths(n,"wp-admin/admin-ajax.php");if(!e.fileExists(i))return;let t=e.readFileAsText(i);if(!t.includes("is_user_logged_in"))return;const s=`
888
1141
  // Playground: authenticate admin user for AJAX requests on WP < 2.8.
889
1142
  if (defined('PLAYGROUND_AUTO_LOGIN_AS_USER')) {
890
- ${A("PLAYGROUND_AUTO_LOGIN_AS_USER")}
1143
+ ${R("PLAYGROUND_AUTO_LOGIN_AS_USER")}
891
1144
  }
892
- `;n=n.replace(/if\s*\(\s*!\s*is_user_logged_in\(\)\s*\)/,s+"if ( !is_user_logged_in() )"),await e.writeFile(i,n)}function A(e){return`
1145
+ `;t=t.replace(/if\s*\(\s*!\s*is_user_logged_in\(\)\s*\)/,s+"if ( !is_user_logged_in() )"),await e.writeFile(i,t)}function R(e){return`
893
1146
  $_pg_user = null;
894
1147
  if (function_exists('wp_generate_auth_cookie')) {
895
1148
  $_pg_user = function_exists('get_user_by')
@@ -907,16 +1160,16 @@ if (function_exists('wp_generate_auth_cookie')) {
907
1160
  $_COOKIE[LOGGED_IN_COOKIE] = wp_generate_auth_cookie($_pg_user->ID, $_pg_exp, 'logged_in');
908
1161
  }
909
1162
  }
910
- `}async function we(e,t){const i=E(e,t);if(i===null)return;const n=parseFloat(i);if(!Number.isFinite(n)||n>=3.3)return;const s=o.joinPaths(t,"wp-admin/includes/schema.php");if(!e.fileExists(s))return;const r=e.readFileAsText(s);/\$wp_queries\s*=\s*"CREATE TABLE/.test(r)&&!r.includes("function wp_get_db_schema")&&await Ee(e,t,s,r)}async function Ee(e,t,i,n){const s=n.match(/\$wp_queries\s*=\s*"CREATE TABLE/);if(!s||s.index===void 0)return;const r=s.index,a='";',_=n.indexOf(a,r);if(_===-1)return;const l=_+a.length,u=`function wp_get_db_schema( $scope = 'all', $blog_id = null ) {
1163
+ `}async function Fe(e,n){const i=T(e,n);if(i===null)return;const t=parseFloat(i);if(!Number.isFinite(t)||t>=3.3)return;const s=a.joinPaths(n,"wp-admin/includes/schema.php");if(!e.fileExists(s))return;const r=e.readFileAsText(s);/\$wp_queries\s*=\s*"CREATE TABLE/.test(r)&&!r.includes("function wp_get_db_schema")&&await Ce(e,n,s,r)}async function Ce(e,n,i,t){const s=t.match(/\$wp_queries\s*=\s*"CREATE TABLE/);if(!s||s.index===void 0)return;const r=s.index,o='";',_=t.indexOf(o,r);if(_===-1)return;const l=_+o.length,u=`function wp_get_db_schema( $scope = 'all', $blog_id = null ) {
911
1164
  global $wpdb, $wp_queries, $charset_collate;
912
1165
  $charset_collate = '';
913
1166
  if ( ! empty($wpdb->charset) )
914
1167
  $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
915
1168
  if ( ! empty($wpdb->collate) )
916
1169
  $charset_collate .= " COLLATE $wpdb->collate";
917
- ${n.substring(r,l)}
1170
+ ${t.substring(r,l)}
918
1171
  return $wp_queries;
919
- }`,d=n.substring(0,r)+u+n.substring(l);await e.writeFile(i,d);const $=o.joinPaths(t,"wp-admin/includes/upgrade.php");if(e.fileExists($)){const p=e.readFileAsText($),P=p.replace(/(\$alterations\s*=\s*dbDelta\(\s*\$wp_queries\s*\))/g,"if ( function_exists('wp_get_db_schema') ) { $wp_queries = wp_get_db_schema(); } $1");P!==p&&await e.writeFile($,P)}}function Te(){return`<?php
1172
+ }`,f=t.substring(0,r)+u+t.substring(l);await e.writeFile(i,f);const $=a.joinPaths(n,"wp-admin/includes/upgrade.php");if(e.fileExists($)){const y=e.readFileAsText($),b=y.replace(/(\$alterations\s*=\s*dbDelta\(\s*\$wp_queries\s*\))/g,"if ( function_exists('wp_get_db_schema') ) { $wp_queries = wp_get_db_schema(); } $1");b!==y&&await e.writeFile($,b)}}function qe(){return`<?php
920
1173
  // @playground-managed — Playground-generated db.php.
921
1174
  // WP < 3.0 loads only db.php and skips wp-db.php, so we pull
922
1175
  // in the wpdb class definition explicitly.
@@ -965,10 +1218,10 @@ if (!function_exists('mysqli_select_db')) {
965
1218
  if (!function_exists('mysqli_close')) {
966
1219
  function mysqli_close() { return true; }
967
1220
  }
968
- `}async function Le(e,t){let i=null;const n=o.joinPaths(e.documentRoot,"wp-includes/version.php");if(e.fileExists(n)){const r=e.readFileAsText(n).match(/\$wp_version\s*=\s*['"]([^'"]+)['"]/);r&&(i=r[1])}const s=i!==null&&parseFloat(i)<3.5;try{await e.run({code:`<?php
1221
+ `}async function We(e,n){if(await Y(e))return;let i=null;const t=a.joinPaths(e.documentRoot,"wp-includes/version.php");if(e.fileExists(t)){const r=e.readFileAsText(t).match(/\$wp_version\s*=\s*['"]([^'"]+)['"]/);r&&(i=r[1])}const s=i!==null&&parseFloat(i)<3.5;try{await e.run({code:`<?php
969
1222
  // WP_INSTALLING bypasses WP 1.x's "not installed" die() in wp-settings.php.
970
1223
  define('WP_INSTALLING', true);
971
- error_reporting(${T});
1224
+ error_reporting(${E});
972
1225
  ini_set('display_errors', '0');
973
1226
  ob_start();
974
1227
  $_pg_db_path = getenv('DOCUMENT_ROOT') . '/wp-content/database/.ht.sqlite';
@@ -1107,7 +1360,7 @@ if (!function_exists('mysqli_close')) {
1107
1360
  $wpdb->query("INSERT INTO {$wpdb->post2cat} (rel_id, post_id, category_id) VALUES (1, 1, 1)");
1108
1361
  }
1109
1362
  }
1110
- `,env:{DOCUMENT_ROOT:e.documentRoot,PLAYGROUND_SITE_URL:t||""}})}catch(r){h.logger.warn("Legacy WP post-install fixups failed (non-fatal):",r)}if(s)try{await e.run({code:`<?php
1363
+ `,env:{DOCUMENT_ROOT:e.documentRoot,PLAYGROUND_SITE_URL:n||""}})}catch(r){d.logger.warn("Legacy WP post-install fixups failed (non-fatal):",r)}if(s)try{await e.run({code:`<?php
1111
1364
  $db_dir = getenv('DOCUMENT_ROOT') . '/wp-content/database/';
1112
1365
  if (!is_dir($db_dir)) { @mkdir($db_dir, 0777, true); }
1113
1366
  $db_path = $db_dir . '.ht.sqlite';
@@ -1400,7 +1653,7 @@ if (!function_exists('mysqli_close')) {
1400
1653
  }
1401
1654
  }
1402
1655
  } catch (Exception $e) {}
1403
- `,env:{DOCUMENT_ROOT:e.documentRoot,PLAYGROUND_SITE_URL:t||""}})}catch(r){h.logger.warn("Legacy WP PDO fallback failed (non-fatal):",r)}}const ye=`
1656
+ `,env:{DOCUMENT_ROOT:e.documentRoot,PLAYGROUND_SITE_URL:n||""}})}catch(r){d.logger.warn("Legacy WP PDO fallback failed (non-fatal):",r)}}const Ge=`
1404
1657
  // Connection stubs — wpdb::__construct bails on a falsy return.
1405
1658
  if (!function_exists('mysqli_connect')) {
1406
1659
  function mysqli_connect() { return true; }
@@ -1418,6 +1671,9 @@ if (!function_exists('mysql_select_db')) {
1418
1671
  if (!function_exists('mysql_set_charset')) {
1419
1672
  function mysql_set_charset() { return true; }
1420
1673
  }
1674
+ if (!defined('MYSQL_ASSOC')) define('MYSQL_ASSOC', 1);
1675
+ if (!defined('MYSQL_NUM')) define('MYSQL_NUM', 2);
1676
+ if (!defined('MYSQL_BOTH')) define('MYSQL_BOTH', 3);
1421
1677
  // Functional mysql_* stubs that delegate to $wpdb (SQLite driver).
1422
1678
  $GLOBALS['_mysql_results'] = array();
1423
1679
  $GLOBALS['_mysql_result_id'] = 0;
@@ -1483,6 +1739,23 @@ if (!function_exists('mysql_fetch_row')) {
1483
1739
  return array_values((array)$row);
1484
1740
  }
1485
1741
  }
1742
+ if (!function_exists('mysql_fetch_assoc')) {
1743
+ function mysql_fetch_assoc($result) {
1744
+ if (!isset($GLOBALS['_mysql_results'][$result])) return null;
1745
+ $r = &$GLOBALS['_mysql_results'][$result];
1746
+ if ($r['index'] >= count($r['rows'])) return null;
1747
+ return (array)$r['rows'][$r['index']++];
1748
+ }
1749
+ }
1750
+ if (!function_exists('mysql_fetch_array')) {
1751
+ function mysql_fetch_array($result, $result_type = null) {
1752
+ $row = mysql_fetch_assoc($result);
1753
+ if ($row === null) return null;
1754
+ if ($result_type === MYSQL_ASSOC) return $row;
1755
+ if ($result_type === MYSQL_NUM) return array_values($row);
1756
+ return array_merge(array_values($row), $row);
1757
+ }
1758
+ }
1486
1759
  if (!function_exists('mysql_fetch_object')) {
1487
1760
  function mysql_fetch_object($result) {
1488
1761
  if (!isset($GLOBALS['_mysql_results'][$result])) return null;
@@ -1540,22 +1813,22 @@ if (!function_exists('mysql_real_escape_string')) {
1540
1813
  }
1541
1814
  if (!function_exists('mysql_escape_string')) {
1542
1815
  function mysql_escape_string($s) { return addslashes($s); }
1543
- }`;async function Pe(e,t,i={}){await e.isDir("/tmp/sqlite-database-integration")&&await e.rmdir("/tmp/sqlite-database-integration",{recursive:!0}),await e.mkdir("/tmp/sqlite-database-integration"),await g.unzipFile(e,t,"/tmp/sqlite-database-integration");const n="/internal/shared/sqlite-database-integration",s=`/tmp/sqlite-database-integration/${(await e.listFiles("/tmp/sqlite-database-integration"))[0]}`;await e.mv(s,n),await be(e,n),await e.defineConstant("SQLITE_MAIN_FILE","1");let a=(await e.readFileAsText(o.joinPaths(n,"db.copy"))).replace("'{SQLITE_IMPLEMENTATION_FOLDER_PATH}'",o.phpVar(n)).replace("'{SQLITE_PLUGIN}'",o.phpVar(o.joinPaths(n,"load.php")));a=a.replace(/^add_action\(/gm,'function_exists("add_action") && add_action(');const _=o.joinPaths(await e.documentRoot,"wp-content/db.php"),l="/internal/shared/mu-plugins/sqlite-database-integration.php",c=`
1544
- if(file_exists(${o.phpVar(_)})) {
1545
- $_pg_db_php = @file_get_contents(${o.phpVar(_)});
1816
+ }`;async function Me(e,n,i={}){await e.isDir("/tmp/sqlite-database-integration")&&await e.rmdir("/tmp/sqlite-database-integration",{recursive:!0}),await e.mkdir("/tmp/sqlite-database-integration"),await h.unzipFile(e,n,"/tmp/sqlite-database-integration");const t="/internal/shared/sqlite-database-integration",s=`/tmp/sqlite-database-integration/${(await e.listFiles("/tmp/sqlite-database-integration"))[0]}`;await e.mv(s,t),await Be(e,t),await e.defineConstant("SQLITE_MAIN_FILE","1");let o=(await e.readFileAsText(a.joinPaths(t,"db.copy"))).replace("'{SQLITE_IMPLEMENTATION_FOLDER_PATH}'",a.phpVar(t)).replace("'{SQLITE_PLUGIN}'",a.phpVar(a.joinPaths(t,"load.php")));o=o.replace(/^add_action\(/gm,'function_exists("add_action") && add_action(');const _=a.joinPaths(await e.documentRoot,"wp-content/db.php"),l="/internal/shared/mu-plugins/sqlite-database-integration.php",c=`
1817
+ if(file_exists(${a.phpVar(_)})) {
1818
+ $_pg_db_php = @file_get_contents(${a.phpVar(_)});
1546
1819
  if (strpos($_pg_db_php, '@playground-managed') === false) {
1547
1820
  return;
1548
1821
  }
1549
1822
  unset($_pg_db_php);
1550
1823
  }
1551
1824
  `;await e.writeFile(l,`<?php
1552
- ${c}?>`+a),await e.writeFile("/internal/shared/preload/0-sqlite.php",Oe(c,l)),await e.writeFile("/internal/shared/mu-plugins/sqlite-test.php",`<?php
1825
+ ${c}?>`+o),await e.writeFile("/internal/shared/preload/0-sqlite.php",He(c,l)),await e.writeFile("/internal/shared/mu-plugins/sqlite-test.php",`<?php
1553
1826
  global $wpdb;
1554
1827
  if(!($wpdb instanceof WP_SQLite_DB)) {
1555
1828
  var_dump(isset($wpdb));
1556
1829
  die("SQLite integration not loaded " . get_class($wpdb));
1557
1830
  }
1558
- `)}async function be(e,t){const i=o.joinPaths(t,"wp-includes/database/sqlite/class-wp-pdo-mysql-on-sqlite.php");if(!await e.fileExists(i))return;const n=await e.readFileAsText(i),s=n.replace(/\$active_sql_modes\s*=\s*array\s*\([^)]*\)\s*;/,"$active_sql_modes = array();");s!==n&&await e.writeFile(i,s)}function Oe(e,t){return`<?php
1831
+ `)}async function Be(e,n){const i=a.joinPaths(n,"wp-includes/database/sqlite/class-wp-pdo-mysql-on-sqlite.php");if(!await e.fileExists(i))return;const t=await e.readFileAsText(i),s=t.replace(/\$active_sql_modes\s*=\s*array\s*\([^)]*\)\s*;/,"$active_sql_modes = array();");s!==t&&await e.writeFile(i,s)}function He(e,n){return`<?php
1559
1832
  ${e}?>
1560
1833
  <?php
1561
1834
  // Shim __() etc. only for WP < 1.2 (no l10n layer; the SQLite
@@ -1587,23 +1860,23 @@ if (
1587
1860
  }
1588
1861
  ?>
1589
1862
  <?php
1590
- ${N(`require_once ${o.phpVar(t)};
1863
+ ${N(`require_once ${a.phpVar(n)};
1591
1864
  if (
1592
1865
  isset($GLOBALS['wpdb']) &&
1593
1866
  method_exists($GLOBALS['wpdb'], 'reinitialize_sqlite')
1594
1867
  ) {
1595
1868
  $GLOBALS['wpdb']->reinitialize_sqlite();
1596
1869
  }`)}
1597
- ${ye}
1870
+ ${Ge}
1598
1871
  if (PHP_MAJOR_VERSION < 7) {
1599
1872
  // E_DEPRECATED (8192) / E_STRICT (2048) are PHP 5.3+ symbols;
1600
1873
  // LEGACY_WP_ERROR_REPORTING_PHP_EXPR uses numeric literals.
1601
- $level = ${T};
1874
+ $level = ${E};
1602
1875
  error_reporting($level);
1603
1876
  ini_set('error_reporting', $level);
1604
1877
  }
1605
1878
 
1606
- `}const S=`<?php
1879
+ `}const I=`<?php
1607
1880
 
1608
1881
  /**
1609
1882
  * Transforms the "wp-config.php" file.
@@ -2074,12 +2347,12 @@ class WP_Config_Transformer {
2074
2347
  && ( T_WHITESPACE === $token[0] || T_COMMENT === $token[0] || T_DOC_COMMENT === $token[0] );
2075
2348
  }
2076
2349
  }
2077
- `;async function v(e,t){const i=o.joinPaths(t,"wp-config.php");!e.fileExists(i)&&e.fileExists(o.joinPaths(t,"wp-config-sample.php"))&&await e.writeFile(i,await e.readFileAsBuffer(o.joinPaths(t,"wp-config-sample.php"))),e.fileExists(i)&&await Ae(e,i,{DB_NAME:"wordpress"})}async function Ne(e,t,i){const n=o.phpVars({wpConfigPath:t,constants:i});if((await e.run({code:`${S}
2078
- $wp_config_path = ${n.wpConfigPath};
2350
+ `;async function x(e,n){const i=a.joinPaths(n,"wp-config.php");!e.fileExists(i)&&e.fileExists(a.joinPaths(n,"wp-config-sample.php"))&&await e.writeFile(i,await e.readFileAsBuffer(a.joinPaths(n,"wp-config-sample.php"))),e.fileExists(i)&&await je(e,i,{DB_NAME:"wordpress"})}async function Xe(e,n,i){const t=a.phpVars({wpConfigPath:n,constants:i});if((await e.run({code:`${I}
2351
+ $wp_config_path = ${t.wpConfigPath};
2079
2352
  $transformer = WP_Config_Transformer::from_file($wp_config_path);
2080
- $transformer->define_constants(${n.constants});
2353
+ $transformer->define_constants(${t.constants});
2081
2354
  $transformer->to_file($wp_config_path);
2082
- `})).errors.length>0)throw new Error("Failed to rewrite constants in wp-config.php.")}async function Ae(e,t,i){const n=Object.keys(i),s=o.phpVars({wpConfigPath:t,constantNames:n}),r=await e.run({code:`${S}
2355
+ `})).errors.length>0)throw new Error("Failed to rewrite constants in wp-config.php.")}async function je(e,n,i){const t=Object.keys(i),s=a.phpVars({wpConfigPath:n,constantNames:t}),r=await e.run({code:`${I}
2083
2356
  $transformer = WP_Config_Transformer::from_file(${s.wpConfigPath});
2084
2357
  $missing = [];
2085
2358
  foreach (${s.constantNames} as $name) {
@@ -2088,7 +2361,7 @@ class WP_Config_Transformer {
2088
2361
  }
2089
2362
  }
2090
2363
  echo json_encode($missing);
2091
- `});if(r.errors.length>0)throw new Error("Failed to check wp-config.php for constants.");let a;try{a=JSON.parse(r.text)}catch{throw new Error(`Failed to parse wp-config.php constant check output: ${r.text}`)}for(const _ of a)await e.defineConstant(_,i[_])}async function w(e,{usesSqlite:t,hasCustomDatabasePath:i}){const n=await e.getPrimaryPhp();if(n.isFile("/internal/shared/preload/0-sqlite.php"))return;const s=o.joinPaths(e.documentRoot,"wp-content/mu-plugins/sqlite-database-integration");if(!n.isDir(s)&&!t&&!i&&!Se(n))throw new Error("Error connecting to the MySQL database.")}function Se(e){const t=o.joinPaths(e.documentRoot,"wp-config.php");if(!e.isFile(t))return!1;const i=e.readFileAsText(t),n=i.match(/define\s*\(\s*['"]DB_NAME['"]\s*,\s*['"]([^'"]*)['"]/),s=i.match(/define\s*\(\s*['"]DB_USER['"]\s*,\s*['"]([^'"]*)['"]/);return!n||!s?!1:n[1]!=="database_name_here"&&s[1]!=="username_here"}const x=["fsockopen","pfsockopen","curl_init","curl_exec","curl_multi_exec","mail"];function ve(e,t){var r,a;if(!f.isLegacyPHPVersion(t.phpVersion))return;const i=(((r=t.phpIniEntries)==null?void 0:r.disable_functions)??"").split(",").map(_=>_.trim()).filter(_=>_),s={disable_functions:Array.from(new Set([...i,...x])).join(","),allow_url_fopen:"0"};(a=t.phpIniEntries)!=null&&a["date.timezone"]||(s["date.timezone"]="UTC"),f.setPhpIniEntries(e,s)}async function xe(e,t){var a,_;const i=await e.getPrimaryPhp();if((a=t.hooks)!=null&&a.beforeWordPressFiles&&await t.hooks.beforeWordPressFiles(i),t.wordPressZip&&await y(i,await t.wordPressZip),t.constants)for(const l in t.constants)i.defineConstant(l,t.constants[l]);i.defineConstant("WP_HOME",t.siteUrl),i.defineConstant("WP_SITEURL",t.siteUrl),await Re(i,e.documentRoot),await j(i,e.documentRoot),(_=t.hooks)!=null&&_.beforeDatabaseSetup&&await t.hooks.beforeDatabaseSetup(i);let n=!1;t.sqliteIntegrationPluginZip&&(n=!0,await L(i,await t.sqliteIntegrationPluginZip,{phpVersion:t.phpVersion}),await Ue(i,e.documentRoot));const s=t.wordpressInstallMode??"download-and-install",r=!!t.dataSqlPath;return(s==="download-and-install"||s==="install-from-existing-files"||s==="install-from-existing-files-if-needed")&&(await w(e,{usesSqlite:n,hasCustomDatabasePath:r}),await ke(i,e)),e}async function Re(e,t){const i=o.joinPaths(t,"wp-config.php"),n=o.joinPaths(t,"wp-config-sample.php");!e.fileExists(i)&&e.fileExists(n)&&await e.writeFile(i,await e.readFileAsBuffer(n))}async function Ue(e,t){const i=o.joinPaths(t,"wp-content"),n=o.joinPaths(i,"db.php");e.isDir(i)&&!e.fileExists(n)&&await e.writeFile(n,Te())}async function ke(e,t){try{await Ie(e)}catch(i){h.logger.warn("Legacy PHP WordPress installation error:",i)}await Le(e,t.absoluteUrl)}async function Ie(e){var r,a,_,l,c,u;const t=Ce(e,e.documentRoot);if(t!==null){const d=parseFloat(t);if(d<2.1)return;if(d<=3){await Fe(e);return}}const i={disable_functions:x.join(","),allow_url_fopen:"0",error_reporting:String(B)},n=await f.withPHPIniValues(e,i,async()=>await e.request({url:"/wp-admin/install.php?step=2",method:"POST",body:{language:"en",prefix:"wp_",weblog_title:"My WordPress Website",user_name:"admin",admin_password:"password",admin_password2:"password",Submit:"Install WordPress",pw_weak:"1",admin_email:"admin@localhost.com"}}));if(!(((r=n.text)==null?void 0:r.includes("Success"))||((a=n.text)==null?void 0:a.includes("successful"))||((_=n.text)==null?void 0:_.includes("Finished"))||((l=n.text)==null?void 0:l.includes("Already Installed"))||((c=n.text)==null?void 0:c.includes("already have WordPress installed"))||!1))throw new Error(`Failed to install WordPress – installer responded with "${(u=n.text)==null?void 0:u.substring(0,100)}"`);await De(e)}async function De(e){try{(await e.run({code:`<?php
2364
+ `});if(r.errors.length>0)throw new Error("Failed to check wp-config.php for constants.");let o;try{o=JSON.parse(r.text)}catch{throw new Error(`Failed to parse wp-config.php constant check output: ${r.text}`)}for(const _ of o)await e.defineConstant(_,i[_])}async function m(e,{usesSqlite:n,hasCustomDatabasePath:i}){const t=await e.getPrimaryPhp();if(t.isFile("/internal/shared/preload/0-sqlite.php"))return;const s=a.joinPaths(e.documentRoot,"wp-content/mu-plugins/sqlite-database-integration");if(!t.isDir(s)&&!n&&!i&&!Ve(t))throw new Error("Error connecting to the MySQL database.")}function Ve(e){const n=a.joinPaths(e.documentRoot,"wp-config.php");if(!e.isFile(n))return!1;const i=e.readFileAsText(n),t=i.match(/define\s*\(\s*['"]DB_NAME['"]\s*,\s*['"]([^'"]*)['"]/),s=i.match(/define\s*\(\s*['"]DB_USER['"]\s*,\s*['"]([^'"]*)['"]/);return!t||!s?!1:t[1]!=="database_name_here"&&s[1]!=="username_here"}const v=["fsockopen","pfsockopen","curl_init","curl_exec","curl_multi_exec","mail"];function Ye(e,n){var r,o;if(!p.isLegacyPHPVersion(n.phpVersion))return;const i=(((r=n.phpIniEntries)==null?void 0:r.disable_functions)??"").split(",").map(_=>_.trim()).filter(_=>_),s={disable_functions:Array.from(new Set([...i,...v])).join(","),allow_url_fopen:"0"};(o=n.phpIniEntries)!=null&&o["date.timezone"]||(s["date.timezone"]="UTC"),p.setPhpIniEntries(e,s)}async function Ke(e,n){var o,_;const i=await e.getPrimaryPhp();if((o=n.hooks)!=null&&o.beforeWordPressFiles&&await n.hooks.beforeWordPressFiles(i),n.wordPressZip&&await L(i,await n.wordPressZip),n.constants)for(const l in n.constants)i.defineConstant(l,n.constants[l]);i.defineConstant("WP_HOME",n.siteUrl),i.defineConstant("WP_SITEURL",n.siteUrl),await Qe(i,e.documentRoot),await le(i,e.documentRoot),(_=n.hooks)!=null&&_.beforeDatabaseSetup&&await n.hooks.beforeDatabaseSetup(i);let t=!1;n.sqliteIntegrationPluginZip&&(t=!0,await w(i,await n.sqliteIntegrationPluginZip,{phpVersion:n.phpVersion}),await ze(i,e.documentRoot));const s=n.wordpressInstallMode??"download-and-install",r=!!n.dataSqlPath;return(s==="download-and-install"||s==="install-from-existing-files"||s==="install-from-existing-files-if-needed")&&(await m(e,{usesSqlite:t,hasCustomDatabasePath:r}),await Ze(i,e)),e}async function Qe(e,n){const i=a.joinPaths(n,"wp-config.php"),t=a.joinPaths(n,"wp-config-sample.php");!e.fileExists(i)&&e.fileExists(t)&&await e.writeFile(i,await e.readFileAsBuffer(t))}async function ze(e,n){const i=a.joinPaths(n,"wp-content"),t=a.joinPaths(i,"db.php");e.isDir(i)&&!e.fileExists(t)&&await e.writeFile(t,qe())}async function Ze(e,n){try{await Je(e)}catch(i){d.logger.warn("Legacy PHP WordPress installation error:",i)}await We(e,n.absoluteUrl)}async function Je(e){var r,o,_,l,c,u;const n=nt(e,e.documentRoot);if(n!==null){const f=parseFloat(n);if(f<2.1)return;if(f<=3){await tt(e);return}}const i={disable_functions:v.join(","),allow_url_fopen:"0",error_reporting:String(_e)},t=await p.withPHPIniValues(e,i,async()=>await e.request({url:"/wp-admin/install.php?step=2",method:"POST",body:{language:"en",prefix:"wp_",weblog_title:"My WordPress Website",user_name:"admin",admin_password:"password",admin_password2:"password",Submit:"Install WordPress",pw_weak:"1",admin_email:"admin@localhost.com"}}));if(!(((r=t.text)==null?void 0:r.includes("Success"))||((o=t.text)==null?void 0:o.includes("successful"))||((_=t.text)==null?void 0:_.includes("Finished"))||((l=t.text)==null?void 0:l.includes("Already Installed"))||((c=t.text)==null?void 0:c.includes("already have WordPress installed"))||!1))throw new Error(`Failed to install WordPress – installer responded with "${(u=t.text)==null?void 0:u.substring(0,100)}"`);await et(e)}async function et(e){try{(await e.run({code:`<?php
2092
2365
  $db_dir = getenv('DOCUMENT_ROOT') . '/wp-content/database/';
2093
2366
  $db_path = $db_dir . '.ht.sqlite';
2094
2367
  if (!file_exists($db_path)) { echo '0'; exit; }
@@ -2109,9 +2382,9 @@ class WP_Config_Transformer {
2109
2382
  "SELECT option_value FROM wp_options WHERE option_name = 'permalink_structure'"
2110
2383
  )->fetchColumn();
2111
2384
  echo $check === $nice_permalinks ? '1' : '0';
2112
- `,env:{DOCUMENT_ROOT:e.documentRoot}})).text!=="1"&&h.logger.warn("Failed to default to pretty permalinks after WP install.")}catch{h.logger.warn("Failed to set pretty permalinks after WP install (non-fatal).")}}async function Fe(e){try{await e.run({code:`<?php
2385
+ `,env:{DOCUMENT_ROOT:e.documentRoot}})).text!=="1"&&d.logger.warn("Failed to default to pretty permalinks after WP install.")}catch{d.logger.warn("Failed to set pretty permalinks after WP install (non-fatal).")}}async function tt(e){try{await e.run({code:`<?php
2113
2386
  define('WP_INSTALLING', true);
2114
- error_reporting(${T});
2387
+ error_reporting(${E});
2115
2388
  ini_set('display_errors', '0');
2116
2389
  ob_start();
2117
2390
  require getenv('DOCUMENT_ROOT') . '/wp-load.php';
@@ -2130,7 +2403,7 @@ class WP_Config_Transformer {
2130
2403
  if (function_exists('populate_options')) populate_options();
2131
2404
  if (function_exists('populate_roles')) populate_roles();
2132
2405
  echo 'OK';
2133
- `,env:{DOCUMENT_ROOT:e.documentRoot}})}catch(t){h.logger.warn("runDbDeltaOnly failed (non-fatal):",t)}}function Ce(e,t){const i=o.joinPaths(t,"wp-includes/version.php");if(!e.fileExists(i))return null;const s=e.readFileAsText(i).match(/\$wp_version\s*=\s*['"]([^'"]+)['"]/);return s?s[1]:null}async function qe(e){const t=await U(e);return await R(t,e),t}async function R(e,t){var a,_;if(f.isLegacyPHPVersion(t.phpVersion))return xe(e,t);const i=await e.getPrimaryPhp();if((a=t.hooks)!=null&&a.beforeWordPressFiles&&await t.hooks.beforeWordPressFiles(i),t.wordPressZip&&await y(i,await t.wordPressZip),t.constants)for(const l in t.constants)i.defineConstant(l,t.constants[l]);t.dataSqlPath&&(i.defineConstant("DB_DIR",o.dirname(t.dataSqlPath)),i.defineConstant("DB_FILE",o.basename(t.dataSqlPath))),i.defineConstant("WP_HOME",t.siteUrl),i.defineConstant("WP_SITEURL",t.siteUrl),await v(i,e.documentRoot),(_=t.hooks)!=null&&_.beforeDatabaseSetup&&await t.hooks.beforeDatabaseSetup(i);let n=!1;t.sqliteIntegrationPluginZip&&(n=!0,await L(i,await t.sqliteIntegrationPluginZip,{phpVersion:t.phpVersion}),await H(i,e.documentRoot));const s=t.wordpressInstallMode??"download-and-install",r=!!t.dataSqlPath;if(["download-and-install","install-from-existing-files"].includes(s)){await w(e,{usesSqlite:n,hasCustomDatabasePath:r});try{await b(i)}catch(l){throw r||await m(e),l}r||await m(e)}else if(s==="install-from-existing-files-if-needed"){if(await w(e,{usesSqlite:n,hasCustomDatabasePath:r}),!await k(i))try{await b(i)}catch(l){throw r||await m(e),l}r||await m(e)}return e}async function m(e){const t=await e.getPrimaryPhp();if(await We(t))return;if(t.isFile("/internal/shared/preload/0-sqlite.php"))throw new Error("Error connecting to the SQLite database.");const n=o.joinPaths(e.documentRoot,"wp-content/mu-plugins/sqlite-database-integration");throw t.isDir(n)?new Error("Error connecting to the SQLite database."):new Error("Error connecting to the MySQL database.")}async function U(e){const t=e.spawnHandler??f.sandboxedSpawnHandlerFactory;async function i(s,r=!1){const a=await e.createPhpRuntime(r),_=new f.PHP(a);if(e.sapiName&&_.setSapiName(e.sapiName),s&&(_.requestHandler=s),e.phpIniEntries&&f.setPhpIniEntries(_,e.phpIniEntries),ve(_,{phpVersion:e.phpVersion,phpIniEntries:e.phpIniEntries}),_.defineConstant("WP_SQLITE_AST_DRIVER",!0),e.constants)for(const l in e.constants)_.defineConstant(l,e.constants[l]);return r&&!_.isFile("/internal/.boot-files-written")&&(await C(_,{phpVersion:e.phpVersion}),await f.writeFiles(_,"/",e.createFiles||{}),await q(_,o.joinPaths(new URL(e.siteUrl).pathname,"phpinfo.php")),await f.writeFiles(_,"/internal",{".boot-files-written":""})),t&&await _.setSpawnHandler(t(s?()=>s.instanceManager.acquirePHPInstance():void 0)),_.enableRuntimeRotation({recreateRuntime:e.createPhpRuntime,maxRequests:400}),e.onPHPInstanceCreated&&await e.onPHPInstanceCreated(_,{isPrimary:r}),_}const n=new f.PHPRequestHandler({documentRoot:e.documentRoot||"/wordpress",absoluteUrl:e.siteUrl,rewriteRules:F,pathAliases:e.pathAliases,getFileNotFoundAction:e.getFileNotFoundAction??I,cookieStore:e.cookieStore,php:e.maxPhpInstances===1?await i(void 0,!0):void 0,phpFactory:e.maxPhpInstances!==1?async({isPrimary:s})=>i(n,s):void 0,maxPhpInstances:e.maxPhpInstances});return n}async function k(e){return(await e.run({code:`<?php
2406
+ `,env:{DOCUMENT_ROOT:e.documentRoot}})}catch(n){d.logger.warn("runDbDeltaOnly failed (non-fatal):",n)}}function nt(e,n){const i=a.joinPaths(n,"wp-includes/version.php");if(!e.fileExists(i))return null;const s=e.readFileAsText(i).match(/\$wp_version\s*=\s*['"]([^'"]+)['"]/);return s?s[1]:null}async function it(e){const n=await D(e);return await k(n,e),n}async function k(e,n){var o,_;if(p.isLegacyPHPVersion(n.phpVersion))return Ke(e,n);const i=await e.getPrimaryPhp();if((o=n.hooks)!=null&&o.beforeWordPressFiles&&await n.hooks.beforeWordPressFiles(i),n.wordPressZip&&await L(i,await n.wordPressZip),n.constants)for(const l in n.constants)i.defineConstant(l,n.constants[l]);n.dataSqlPath&&(i.defineConstant("DB_DIR",a.dirname(n.dataSqlPath)),i.defineConstant("DB_FILE",a.basename(n.dataSqlPath))),i.defineConstant("WP_HOME",n.siteUrl),i.defineConstant("WP_SITEURL",n.siteUrl),await x(i,e.documentRoot),(_=n.hooks)!=null&&_.beforeDatabaseSetup&&await n.hooks.beforeDatabaseSetup(i);let t=!1;n.sqliteIntegrationPluginZip&&(t=!0,await w(i,await n.sqliteIntegrationPluginZip,{phpVersion:n.phpVersion}),await oe(i,e.documentRoot));const s=n.wordpressInstallMode??"download-and-install",r=!!n.dataSqlPath;if(["download-and-install","install-from-existing-files"].includes(s)){await m(e,{usesSqlite:t,hasCustomDatabasePath:r});try{await O(i)}catch(l){throw r||await g(e),l}r||await g(e)}else if(s==="install-from-existing-files-if-needed"){if(await m(e,{usesSqlite:t,hasCustomDatabasePath:r}),!await F(i))try{await O(i)}catch(l){throw r||await g(e),l}r||await g(e)}return e}async function g(e){const n=await e.getPrimaryPhp();if(await st(n))return;if(n.isFile("/internal/shared/preload/0-sqlite.php"))throw new Error("Error connecting to the SQLite database.");const t=a.joinPaths(e.documentRoot,"wp-content/mu-plugins/sqlite-database-integration");throw n.isDir(t)?new Error("Error connecting to the SQLite database."):new Error("Error connecting to the MySQL database.")}async function D(e){const n=e.spawnHandler??p.sandboxedSpawnHandlerFactory;async function i(s,r=!1){const o=await e.createPhpRuntime(r),_=new p.PHP(o);if(e.sapiName&&_.setSapiName(e.sapiName),s&&(_.requestHandler=s),e.phpIniEntries&&p.setPhpIniEntries(_,e.phpIniEntries),Ye(_,{phpVersion:e.phpVersion,phpIniEntries:e.phpIniEntries}),_.defineConstant("WP_SQLITE_AST_DRIVER",!0),e.constants)for(const l in e.constants)_.defineConstant(l,e.constants[l]);return r&&!_.isFile("/internal/.boot-files-written")&&(await G(_,{phpVersion:e.phpVersion}),await p.writeFiles(_,"/",e.createFiles||{}),await M(_,a.joinPaths(new URL(e.siteUrl).pathname,"phpinfo.php")),await p.writeFiles(_,"/internal",{".boot-files-written":""})),n&&await _.setSpawnHandler(n(s?()=>s.instanceManager.acquirePHPInstance():void 0)),_.enableRuntimeRotation({recreateRuntime:e.createPhpRuntime,maxRequests:400}),e.onPHPInstanceCreated&&await e.onPHPInstanceCreated(_,{isPrimary:r}),_}const t=new p.PHPRequestHandler({documentRoot:e.documentRoot||"/wordpress",absoluteUrl:e.siteUrl,rewriteRules:W,pathAliases:e.pathAliases,getFileNotFoundAction:e.getFileNotFoundAction??C,cookieStore:e.cookieStore,php:e.maxPhpInstances===1?await i(void 0,!0):void 0,phpFactory:e.maxPhpInstances!==1?async({isPrimary:s})=>i(t,s):void 0,maxPhpInstances:e.maxPhpInstances});return t}async function F(e){return(await e.run({code:`<?php
2134
2407
  ob_start();
2135
2408
  $wp_load = getenv('DOCUMENT_ROOT') . '/wp-load.php';
2136
2409
  if (!file_exists($wp_load)) {
@@ -2141,7 +2414,7 @@ class WP_Config_Transformer {
2141
2414
  ob_clean();
2142
2415
  echo is_blog_installed() ? '1' : '0';
2143
2416
  ob_end_flush();
2144
- `,env:{DOCUMENT_ROOT:e.documentRoot}})).text==="1"}async function b(e){var n;const t=await f.withPHPIniValues(e,{disable_functions:"fsockopen",allow_url_fopen:"0"},async()=>await e.request({url:"/wp-admin/install.php?step=2",method:"POST",body:{language:"en",prefix:"wp_",weblog_title:"My WordPress Website",user_name:"admin",admin_password:"password",admin_password2:"password",Submit:"Install WordPress",pw_weak:"1",admin_email:"admin@localhost.com"}}));if(!await k(e))throw new Error(`Failed to install WordPress – installer responded with "${(n=t.text)==null?void 0:n.substring(0,100)}"`);(await e.run({code:`<?php
2417
+ `,env:{DOCUMENT_ROOT:e.documentRoot}})).text==="1"}async function O(e){var t;const n=await p.withPHPIniValues(e,{disable_functions:"fsockopen",allow_url_fopen:"0"},async()=>await e.request({url:"/wp-admin/install.php?step=2",method:"POST",body:{language:"en",prefix:"wp_",weblog_title:"My WordPress Website",user_name:"admin",admin_password:"password",admin_password2:"password",Submit:"Install WordPress",pw_weak:"1",admin_email:"admin@localhost.com"}}));if(!await F(e))throw new Error(`Failed to install WordPress – installer responded with "${(t=n.text)==null?void 0:t.substring(0,100)}"`);(await e.run({code:`<?php
2145
2418
  ob_start();
2146
2419
  $wp_load = getenv('DOCUMENT_ROOT') . '/wp-load.php';
2147
2420
  if (!file_exists($wp_load)) {
@@ -2161,7 +2434,7 @@ class WP_Config_Transformer {
2161
2434
  echo '0';
2162
2435
  }
2163
2436
  ob_end_flush();
2164
- `,env:{DOCUMENT_ROOT:e.documentRoot}})).text!=="1"&&h.logger.warn("Failed to default to pretty permalinks after WP install.")}function I(e){return{type:"internal-redirect",uri:"/index.php"}}async function We(e){return(await e.run({code:`<?php
2437
+ `,env:{DOCUMENT_ROOT:e.documentRoot}})).text!=="1"&&d.logger.warn("Failed to default to pretty permalinks after WP install.")}function C(e){return{type:"internal-redirect",uri:"/index.php"}}async function st(e){return(await e.run({code:`<?php
2165
2438
  ob_start();
2166
2439
  $wp_load = getenv('DOCUMENT_ROOT') . '/wp-load.php';
2167
2440
  if (!file_exists($wp_load)) {
@@ -2172,10 +2445,10 @@ class WP_Config_Transformer {
2172
2445
  ob_clean();
2173
2446
  echo $wpdb->check_connection( false ) ? '1' : '0';
2174
2447
  ob_end_flush();
2175
- `,env:{DOCUMENT_ROOT:e.documentRoot}})).text==="1"}async function Ge(e){const{php:t,reap:i}=await e.instanceManager.acquirePHPInstance();try{const s=(await t.run({code:`<?php
2448
+ `,env:{DOCUMENT_ROOT:e.documentRoot}})).text==="1"}async function rt(e){const{php:n,reap:i}=await e.instanceManager.acquirePHPInstance();try{const s=(await n.run({code:`<?php
2176
2449
  require '${e.documentRoot}/wp-includes/version.php';
2177
2450
  echo $wp_version;
2178
- `})).text;if(!s)throw new Error("Unable to read loaded WordPress version.");return D(s)}finally{i()}}function D(e){if(/-(alpha|beta|RC)\d*-\d+$/.test(e))return"trunk";if(/-(beta|RC)\d*$/.test(e))return"beta";const n=e.match(/^(\d+\.\d+)(?:\.\d+)?$/);return n!==null?n[1]:e}const F=[{match:new RegExp("^(/[_0-9a-zA-Z-]+)?(/wp-(content|admin|includes)/.*)"),replacement:"$2"}];async function C(e,t={}){if(f.isLegacyPHPVersion(t.phpVersion))return G(e);await e.mkdir("/internal/shared/mu-plugins"),await e.writeFile("/internal/shared/preload/env.php",`<?php
2451
+ `})).text;if(!s)throw new Error("Unable to read loaded WordPress version.");return q(s)}finally{i()}}function q(e){if(/-(alpha|beta|RC)\d*-\d+$/.test(e))return"trunk";if(/-(beta|RC)\d*$/.test(e))return"beta";const t=e.match(/^(\d+\.\d+)(?:\.\d+)?$/);return t!==null?t[1]:e}const W=[{match:new RegExp("^(/[_0-9a-zA-Z-]+)?(/wp-(content|admin|includes)/.*)"),replacement:"$2"}];async function G(e,n={}){if(p.isLegacyPHPVersion(n.phpVersion))return H(e);await e.mkdir("/internal/shared/mu-plugins"),await e.writeFile("/internal/shared/preload/env.php",`<?php
2179
2452
 
2180
2453
  // Allow adding filters/actions prior to loading WordPress.
2181
2454
  // $function_to_add MUST be a string.
@@ -2356,7 +2629,7 @@ class WP_Config_Transformer {
2356
2629
  }
2357
2630
  return $interval;
2358
2631
  });
2359
- `),await O(e),await e.writeFile("/internal/shared/preload/error-handler.php",`<?php
2632
+ `),await P(e),await e.writeFile("/internal/shared/preload/error-handler.php",`<?php
2360
2633
  (function() {
2361
2634
  $playground_consts = [];
2362
2635
  if(file_exists('/internal/shared/consts.json')) {
@@ -2404,29 +2677,29 @@ class WP_Config_Transformer {
2404
2677
  }
2405
2678
  return false;
2406
2679
  });
2407
- })();`)}async function q(e,t="/phpinfo.php"){await e.writeFile("/internal/shared/preload/phpinfo.php",`<?php
2680
+ })();`)}async function M(e,n="/phpinfo.php"){await e.writeFile("/internal/shared/preload/phpinfo.php",`<?php
2408
2681
  // Render PHPInfo if the requested page is /phpinfo.php
2409
- if ( isset($_SERVER['REQUEST_URI']) && ${o.phpVar(t)} === $_SERVER['REQUEST_URI'] ) {
2682
+ if ( isset($_SERVER['REQUEST_URI']) && ${a.phpVar(n)} === $_SERVER['REQUEST_URI'] ) {
2410
2683
  phpinfo();
2411
2684
  exit;
2412
2685
  }
2413
- `)}async function L(e,t,i={}){if(f.isLegacyPHPVersion(i.phpVersion))return Pe(e,t,i);await e.isDir("/tmp/sqlite-database-integration")&&await e.rmdir("/tmp/sqlite-database-integration",{recursive:!0}),await e.mkdir("/tmp/sqlite-database-integration"),await g.unzipFile(e,t,"/tmp/sqlite-database-integration");const n="/internal/shared/sqlite-database-integration",s=`/tmp/sqlite-database-integration/${(await e.listFiles("/tmp/sqlite-database-integration"))[0]}`;await e.mv(s,n);const r=o.joinPaths(n,"wp-includes/sqlite/class-wp-sqlite-db.php");if(await e.fileExists(r)){const d=await e.readFileAsText(r),$=d.replace("private $allow_unsafe_unquoted_parameters","protected $allow_unsafe_unquoted_parameters");$!==d&&await e.writeFile(r,$)}await e.defineConstant("SQLITE_MAIN_FILE","1");const _=(await e.readFileAsText(o.joinPaths(n,"db.copy"))).replace("'{SQLITE_IMPLEMENTATION_FOLDER_PATH}'",o.phpVar(n)).replace("'{SQLITE_PLUGIN}'",o.phpVar(o.joinPaths(n,"load.php"))),l=o.joinPaths(await e.documentRoot,"wp-content/db.php"),c=`<?php
2686
+ `)}async function w(e,n,i={}){if(p.isLegacyPHPVersion(i.phpVersion))return Me(e,n,i);await e.isDir("/tmp/sqlite-database-integration")&&await e.rmdir("/tmp/sqlite-database-integration",{recursive:!0}),await e.mkdir("/tmp/sqlite-database-integration"),await h.unzipFile(e,n,"/tmp/sqlite-database-integration");const t="/internal/shared/sqlite-database-integration",s=`/tmp/sqlite-database-integration/${(await e.listFiles("/tmp/sqlite-database-integration"))[0]}`;await e.mv(s,t);const r=a.joinPaths(t,"wp-includes/sqlite/class-wp-sqlite-db.php");if(await e.fileExists(r)){const f=await e.readFileAsText(r),$=f.replace("private $allow_unsafe_unquoted_parameters","protected $allow_unsafe_unquoted_parameters");$!==f&&await e.writeFile(r,$)}await e.defineConstant("SQLITE_MAIN_FILE","1");const _=(await e.readFileAsText(a.joinPaths(t,"db.copy"))).replace("'{SQLITE_IMPLEMENTATION_FOLDER_PATH}'",a.phpVar(t)).replace("'{SQLITE_PLUGIN}'",a.phpVar(a.joinPaths(t,"load.php"))),l=a.joinPaths(await e.documentRoot,"wp-content/db.php"),c=`<?php
2414
2687
  // Do not preload this if WordPress comes with a custom db.php file.
2415
- if(file_exists(${o.phpVar(l)})) {
2688
+ if(file_exists(${a.phpVar(l)})) {
2416
2689
  return;
2417
2690
  }
2418
- ?>`,u="/internal/shared/mu-plugins/sqlite-database-integration.php";await e.writeFile(u,c+_),await e.writeFile("/internal/shared/preload/0-sqlite.php",Me(c,u)),await e.writeFile("/internal/shared/mu-plugins/sqlite-test.php",`<?php
2691
+ ?>`,u="/internal/shared/mu-plugins/sqlite-database-integration.php";await e.writeFile(u,c+_),await e.writeFile("/internal/shared/preload/0-sqlite.php",at(c,u)),await e.writeFile("/internal/shared/mu-plugins/sqlite-test.php",`<?php
2419
2692
  global $wpdb;
2420
2693
  if(!($wpdb instanceof WP_SQLite_DB)) {
2421
2694
  var_dump(isset($wpdb));
2422
2695
  die("SQLite integration not loaded " . get_class($wpdb));
2423
2696
  }
2424
- `)}function Me(e,t){return e+`<?php
2697
+ `)}function at(e,n){return e+`<?php
2425
2698
 
2426
- ${N(`require_once ${o.phpVar(t)};`)}
2699
+ ${N(`require_once ${a.phpVar(n)};`)}
2427
2700
  if(!function_exists('mysqli_connect')) {
2428
2701
  function mysqli_connect() {}
2429
2702
  }
2430
2703
 
2431
- `}async function y(e,t){e.mkdir("/tmp/unzipped-wordpress"),await g.unzipFile(e,t,"/tmp/unzipped-wordpress"),e.fileExists("/tmp/unzipped-wordpress/wordpress.zip")&&await g.unzipFile(e,"/tmp/unzipped-wordpress/wordpress.zip","/tmp/unzipped-wordpress");let i=e.fileExists("/tmp/unzipped-wordpress/wordpress")?"/tmp/unzipped-wordpress/wordpress":e.fileExists("/tmp/unzipped-wordpress/build")?"/tmp/unzipped-wordpress/build":"/tmp/unzipped-wordpress";if(!e.fileExists(o.joinPaths(i,"wp-config-sample.php"))){const s=e.listFiles(i);if(s.length){const r=s[0];e.fileExists(o.joinPaths(i,r,"wp-config-sample.php"))&&(i=o.joinPaths(i,r))}}const n=(s,r,a)=>{if(a.isDir(s)&&a.isDir(r))for(const _ of a.listFiles(s)){const l=o.joinPaths(s,_),c=o.joinPaths(r,_);n(l,c,a)}else{if(a.fileExists(r)){const _=s.replace(/^\/tmp\/unzipped-wordpress\//,"/");h.logger.warn(`Cannot unzip WordPress files at ${r}: ${_} already exists.`);return}a.mv(s,r)}};n(i,e.documentRoot,e),e.fileExists(i)&&e.rmdir(i,{recursive:!0}),!e.fileExists(o.joinPaths(e.documentRoot,"wp-config.php"))&&e.fileExists(o.joinPaths(e.documentRoot,"wp-config-sample.php"))&&e.writeFile(o.joinPaths(e.documentRoot,"wp-config.php"),e.readFileAsText(o.joinPaths(e.documentRoot,"/wp-config-sample.php")))}const He=g.createMemoizedFetch(fetch),Be="https://github.com/WordPress/WordPress/archive/refs/heads/master.zip";async function je(e="latest"){if(e===null)e="latest";else if(e.startsWith("https://")||e.startsWith("http://")){const n=await crypto.subtle.digest("SHA-1",new TextEncoder().encode(e)),s=Array.from(new Uint8Array(n)).map(r=>r.toString(16).padStart(2,"0")).join("");return{releaseUrl:e,version:"custom-"+s.substring(0,8),source:"inferred"}}else if(e==="trunk"||e==="nightly"){const n=new Date().toISOString().split("T")[0];return{releaseUrl:`${Be}?ts=${n}`,version:"trunk",source:"inferred"}}let i=await(await He("https://api.wordpress.org/core/version-check/1.7/?channel=beta")).json();i=i.offers.filter(n=>n.response==="autoupdate");for(const n of i){if(e==="beta"&&(n.version.includes("beta")||n.version.includes("RC")))return{releaseUrl:n.download,version:n.version,source:"api"};if(e==="latest"&&!n.version.includes("beta")&&!n.version.includes("RC"))return{releaseUrl:n.download,version:n.version,source:"api"};if(n.version.substring(0,e.length)===e)return{releaseUrl:n.download,version:n.version,source:"api"}}return e.match(/^\d+\.\d+\.0$/)&&(e=e.split(".").slice(0,2).join(".")),{releaseUrl:`https://wordpress.org/wordpress-${e}.zip`,version:e,source:"inferred"}}exports.bootRequestHandler=U;exports.bootWordPress=R;exports.bootWordPressAndRequestHandler=qe;exports.defineWpConfigConstants=Ne;exports.ensureWpConfig=v;exports.getFileNotFoundActionForWordPress=I;exports.getLoadedWordPressVersion=Ge;exports.preloadPhpInfoRoute=q;exports.preloadSqliteIntegration=L;exports.resolveWordPressRelease=je;exports.setupPlatformLevelMuPlugins=C;exports.unzipWordPress=y;exports.versionStringToLoadedWordPressVersion=D;exports.wordPressRewriteRules=F;
2704
+ `}async function L(e,n){e.mkdir("/tmp/unzipped-wordpress"),await h.unzipFile(e,n,"/tmp/unzipped-wordpress"),e.fileExists("/tmp/unzipped-wordpress/wordpress.zip")&&await h.unzipFile(e,"/tmp/unzipped-wordpress/wordpress.zip","/tmp/unzipped-wordpress");let i=e.fileExists("/tmp/unzipped-wordpress/wordpress")?"/tmp/unzipped-wordpress/wordpress":e.fileExists("/tmp/unzipped-wordpress/build")?"/tmp/unzipped-wordpress/build":"/tmp/unzipped-wordpress";if(!e.fileExists(a.joinPaths(i,"wp-config-sample.php"))){const s=e.listFiles(i);if(s.length){const r=s[0];e.fileExists(a.joinPaths(i,r,"wp-config-sample.php"))&&(i=a.joinPaths(i,r))}}const t=(s,r,o)=>{if(o.isDir(s)&&o.isDir(r))for(const _ of o.listFiles(s)){const l=a.joinPaths(s,_),c=a.joinPaths(r,_);t(l,c,o)}else{if(o.fileExists(r)){const _=s.replace(/^\/tmp\/unzipped-wordpress\//,"/");d.logger.warn(`Cannot unzip WordPress files at ${r}: ${_} already exists.`);return}o.mv(s,r)}};t(i,e.documentRoot,e),e.fileExists(i)&&e.rmdir(i,{recursive:!0}),!e.fileExists(a.joinPaths(e.documentRoot,"wp-config.php"))&&e.fileExists(a.joinPaths(e.documentRoot,"wp-config-sample.php"))&&e.writeFile(a.joinPaths(e.documentRoot,"wp-config.php"),e.readFileAsText(a.joinPaths(e.documentRoot,"/wp-config-sample.php")))}const ot=h.createMemoizedFetch(fetch),_t="https://github.com/WordPress/WordPress/archive/refs/heads/master.zip";async function lt(e="latest"){if(e===null)e="latest";else if(e.startsWith("https://")||e.startsWith("http://")){const t=await crypto.subtle.digest("SHA-1",new TextEncoder().encode(e)),s=Array.from(new Uint8Array(t)).map(r=>r.toString(16).padStart(2,"0")).join("");return{releaseUrl:e,version:"custom-"+s.substring(0,8),source:"inferred"}}else if(e==="trunk"||e==="nightly"){const t=new Date().toISOString().split("T")[0];return{releaseUrl:`${_t}?ts=${t}`,version:"trunk",source:"inferred"}}let i=await(await ot("https://api.wordpress.org/core/version-check/1.7/?channel=beta")).json();i=i.offers.filter(t=>t.response==="autoupdate");for(const t of i){if(e==="beta"&&(t.version.includes("beta")||t.version.includes("RC")))return{releaseUrl:t.download,version:t.version,source:"api"};if(e==="latest"&&!t.version.includes("beta")&&!t.version.includes("RC"))return{releaseUrl:t.download,version:t.version,source:"api"};if(t.version.substring(0,e.length)===e)return{releaseUrl:t.download,version:t.version,source:"api"}}return e.match(/^\d+\.\d+\.0$/)&&(e=e.split(".").slice(0,2).join(".")),{releaseUrl:`https://wordpress.org/wordpress-${e}.zip`,version:e,source:"inferred"}}exports.bootRequestHandler=D;exports.bootWordPress=k;exports.bootWordPressAndRequestHandler=it;exports.defineWpConfigConstants=Xe;exports.ensureWpConfig=x;exports.getFileNotFoundActionForWordPress=C;exports.getLoadedWordPressVersion=rt;exports.preloadPhpInfoRoute=M;exports.preloadSqliteIntegration=w;exports.resolveWordPressRelease=lt;exports.setupPlatformLevelMuPlugins=G;exports.unzipWordPress=L;exports.versionStringToLoadedWordPressVersion=q;exports.wordPressRewriteRules=W;
2432
2705
  //# sourceMappingURL=index.cjs.map