author | ymh <ymh.work@gmail.com> |
Mon, 08 Sep 2025 19:44:41 +0200 | |
changeset 23 | 417f20492bf7 |
parent 22 | 8c2e4d02f4ef |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
3 |
* Database Repair and Optimization Script. |
|
4 |
* |
|
5 |
* @package WordPress |
|
6 |
* @subpackage Database |
|
7 |
*/ |
|
9 | 8 |
define( 'WP_REPAIRING', true ); |
0 | 9 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
10 |
require_once dirname( __DIR__, 2 ) . '/wp-load.php'; |
0 | 11 |
|
12 |
header( 'Content-Type: text/html; charset=utf-8' ); |
|
13 |
?> |
|
14 |
<!DOCTYPE html> |
|
16 | 15 |
<html <?php language_attributes(); ?>> |
0 | 16 |
<head> |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
17 |
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> |
0 | 18 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
19 |
<meta name="robots" content="noindex,nofollow" /> |
0 | 20 |
<title><?php _e( 'WordPress › Database Repair' ); ?></title> |
9 | 21 |
<?php wp_admin_css( 'install', true ); ?> |
0 | 22 |
</head> |
23 |
<body class="wp-core-ui"> |
|
9 | 24 |
<p id="logo"><a href="<?php echo esc_url( __( 'https://wordpress.org/' ) ); ?>"><?php _e( 'WordPress' ); ?></a></p> |
0 | 25 |
|
26 |
<?php |
|
27 |
||
9 | 28 |
if ( ! defined( 'WP_ALLOW_REPAIR' ) || ! WP_ALLOW_REPAIR ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
29 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
30 |
echo '<h1 class="screen-reader-text">' . |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
31 |
/* translators: Hidden accessibility text. */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
32 |
__( 'Allow automatic database repair' ) . |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
33 |
'</h1>'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
34 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
35 |
echo '<p>'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
36 |
printf( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
37 |
/* translators: %s: wp-config.php */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
38 |
__( 'To allow use of this page to automatically repair database problems, please add the following line to your %s file. Once this line is added to your config, reload this page.' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
39 |
'<code>wp-config.php</code>' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
40 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
41 |
echo "</p><p><code>define('WP_ALLOW_REPAIR', true);</code></p>"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
42 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
43 |
$default_keys = array_unique( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
44 |
array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
45 |
'put your unique phrase here', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
46 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
47 |
* translators: This string should only be translated if wp-config-sample.php is localized. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
48 |
* You can check the localized release package or |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
49 |
* https://i18n.svn.wordpress.org/<locale code>/branches/<wp version>/dist/wp-config-sample.php |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
50 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
51 |
__( 'put your unique phrase here' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
52 |
) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
53 |
); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
54 |
$missing_key = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
55 |
$duplicated_keys = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
56 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
57 |
foreach ( array( 'AUTH_KEY', 'SECURE_AUTH_KEY', 'LOGGED_IN_KEY', 'NONCE_KEY', 'AUTH_SALT', 'SECURE_AUTH_SALT', 'LOGGED_IN_SALT', 'NONCE_SALT' ) as $key ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
58 |
if ( defined( $key ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
59 |
// Check for unique values of each key. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
60 |
$duplicated_keys[ constant( $key ) ] = isset( $duplicated_keys[ constant( $key ) ] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
61 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
62 |
// If a constant is not defined, it's missing. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
63 |
$missing_key = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
64 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
65 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
66 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
67 |
// If at least one key uses a default value, consider it duplicated. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
68 |
foreach ( $default_keys as $default_key ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
69 |
if ( isset( $duplicated_keys[ $default_key ] ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
70 |
$duplicated_keys[ $default_key ] = true; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
71 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
72 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
73 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
74 |
// Weed out all unique, non-default values. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
75 |
$duplicated_keys = array_filter( $duplicated_keys ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
76 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
77 |
if ( $duplicated_keys || $missing_key ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
78 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
79 |
echo '<h2 class="screen-reader-text">' . |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
80 |
/* translators: Hidden accessibility text. */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
81 |
__( 'Check secret keys' ) . |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
82 |
'</h2>'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
83 |
|
16 | 84 |
/* translators: 1: wp-config.php, 2: Secret key service URL. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
85 |
echo '<p>' . sprintf( __( 'While you are editing your %1$s file, take a moment to make sure you have all 8 keys and that they are unique. You can generate these using the <a href="%2$s">WordPress.org secret key service</a>.' ), '<code>wp-config.php</code>', 'https://api.wordpress.org/secret-key/1.1/salt/' ) . '</p>'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
86 |
} |
0 | 87 |
} elseif ( isset( $_GET['repair'] ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
88 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
89 |
echo '<h1 class="screen-reader-text">' . |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
90 |
/* translators: Hidden accessibility text. */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
91 |
__( 'Database repair results' ) . |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
92 |
'</h1>'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
93 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
94 |
$optimize = '2' === $_GET['repair']; |
9 | 95 |
$okay = true; |
0 | 96 |
$problems = array(); |
97 |
||
98 |
$tables = $wpdb->tables(); |
|
99 |
||
100 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
101 |
* Filters additional database tables to repair. |
0 | 102 |
* |
103 |
* @since 3.0.0 |
|
104 |
* |
|
9 | 105 |
* @param string[] $tables Array of prefixed table names to be repaired. |
0 | 106 |
*/ |
107 |
$tables = array_merge( $tables, (array) apply_filters( 'tables_to_repair', array() ) ); |
|
108 |
||
109 |
// Loop over the tables, checking and repairing as needed. |
|
110 |
foreach ( $tables as $table ) { |
|
111 |
$check = $wpdb->get_row( "CHECK TABLE $table" ); |
|
112 |
||
113 |
echo '<p>'; |
|
16 | 114 |
if ( 'OK' === $check->Msg_text ) { |
115 |
/* translators: %s: Table name. */ |
|
0 | 116 |
printf( __( 'The %s table is okay.' ), "<code>$table</code>" ); |
117 |
} else { |
|
16 | 118 |
/* translators: 1: Table name, 2: Error message. */ |
9 | 119 |
printf( __( 'The %1$s table is not okay. It is reporting the following error: %2$s. WordPress will attempt to repair this table…' ), "<code>$table</code>", "<code>$check->Msg_text</code>" ); |
0 | 120 |
|
121 |
$repair = $wpdb->get_row( "REPAIR TABLE $table" ); |
|
122 |
||
123 |
echo '<br /> '; |
|
18 | 124 |
if ( 'OK' === $repair->Msg_text ) { |
16 | 125 |
/* translators: %s: Table name. */ |
0 | 126 |
printf( __( 'Successfully repaired the %s table.' ), "<code>$table</code>" ); |
127 |
} else { |
|
16 | 128 |
/* translators: 1: Table name, 2: Error message. */ |
18 | 129 |
printf( __( 'Failed to repair the %1$s table. Error: %2$s' ), "<code>$table</code>", "<code>$repair->Msg_text</code>" ) . '<br />'; |
130 |
$problems[ $table ] = $repair->Msg_text; |
|
9 | 131 |
$okay = false; |
0 | 132 |
} |
133 |
} |
|
134 |
||
135 |
if ( $okay && $optimize ) { |
|
18 | 136 |
$analyze = $wpdb->get_row( "ANALYZE TABLE $table" ); |
0 | 137 |
|
138 |
echo '<br /> '; |
|
18 | 139 |
if ( 'Table is already up to date' === $analyze->Msg_text ) { |
16 | 140 |
/* translators: %s: Table name. */ |
0 | 141 |
printf( __( 'The %s table is already optimized.' ), "<code>$table</code>" ); |
142 |
} else { |
|
18 | 143 |
$optimize = $wpdb->get_row( "OPTIMIZE TABLE $table" ); |
0 | 144 |
|
145 |
echo '<br /> '; |
|
18 | 146 |
if ( 'OK' === $optimize->Msg_text || 'Table is already up to date' === $optimize->Msg_text ) { |
16 | 147 |
/* translators: %s: Table name. */ |
0 | 148 |
printf( __( 'Successfully optimized the %s table.' ), "<code>$table</code>" ); |
149 |
} else { |
|
16 | 150 |
/* translators: 1: Table name. 2: Error message. */ |
18 | 151 |
printf( __( 'Failed to optimize the %1$s table. Error: %2$s' ), "<code>$table</code>", "<code>$optimize->Msg_text</code>" ); |
0 | 152 |
} |
153 |
} |
|
154 |
} |
|
155 |
echo '</p>'; |
|
156 |
} |
|
157 |
||
158 |
if ( $problems ) { |
|
16 | 159 |
printf( |
160 |
/* translators: %s: URL to "Fixing WordPress" forum. */ |
|
161 |
'<p>' . __( 'Some database problems could not be repaired. Please copy-and-paste the following list of errors to the <a href="%s">WordPress support forums</a> to get additional assistance.' ) . '</p>', |
|
162 |
__( 'https://wordpress.org/support/forum/how-to-and-troubleshooting' ) |
|
163 |
); |
|
0 | 164 |
$problem_output = ''; |
9 | 165 |
foreach ( $problems as $table => $problem ) { |
0 | 166 |
$problem_output .= "$table: $problem\n"; |
9 | 167 |
} |
0 | 168 |
echo '<p><textarea name="errors" id="errors" rows="20" cols="60">' . esc_textarea( $problem_output ) . '</textarea></p>'; |
169 |
} else { |
|
5 | 170 |
echo '<p>' . __( 'Repairs complete. Please remove the following line from wp-config.php to prevent this page from being used by unauthorized users.' ) . "</p><p><code>define('WP_ALLOW_REPAIR', true);</code></p>"; |
0 | 171 |
} |
172 |
} else { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
173 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
174 |
echo '<h1 class="screen-reader-text">' . |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
175 |
/* translators: Hidden accessibility text. */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
176 |
__( 'WordPress database repair' ) . |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
177 |
'</h1>'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
178 |
|
16 | 179 |
if ( isset( $_GET['referrer'] ) && 'is_blog_installed' === $_GET['referrer'] ) { |
0 | 180 |
echo '<p>' . __( 'One or more database tables are unavailable. To allow WordPress to attempt to repair these tables, press the “Repair Database” button. Repairing can take a while, so please be patient.' ) . '</p>'; |
9 | 181 |
} else { |
0 | 182 |
echo '<p>' . __( 'WordPress can automatically look for some common database problems and repair them. Repairing can take a while, so please be patient.' ) . '</p>'; |
9 | 183 |
} |
184 |
?> |
|
0 | 185 |
<p class="step"><a class="button button-large" href="repair.php?repair=1"><?php _e( 'Repair Database' ); ?></a></p> |
186 |
<p><?php _e( 'WordPress can also attempt to optimize the database. This improves performance in some situations. Repairing and optimizing the database can take a long time and the database will be locked while optimizing.' ); ?></p> |
|
187 |
<p class="step"><a class="button button-large" href="repair.php?repair=2"><?php _e( 'Repair and Optimize Database' ); ?></a></p> |
|
9 | 188 |
<?php |
0 | 189 |
} |
190 |
?> |
|
191 |
</body> |
|
192 |
</html> |