author | ymh <ymh.work@gmail.com> |
Fri, 05 Sep 2025 18:40:08 +0200 | |
changeset 21 | 48c4eec2b7e6 |
parent 19 | 3d72ae0968f4 |
child 22 | 8c2e4d02f4ef |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
3 |
* Misc WordPress Administration API. |
|
4 |
* |
|
5 |
* @package WordPress |
|
6 |
* @subpackage Administration |
|
7 |
*/ |
|
8 |
||
9 |
/** |
|
10 |
* Returns whether the server is running Apache with the mod_rewrite module loaded. |
|
11 |
* |
|
12 |
* @since 2.0.0 |
|
13 |
* |
|
16 | 14 |
* @return bool Whether the server is running Apache with the mod_rewrite module loaded. |
0 | 15 |
*/ |
16 |
function got_mod_rewrite() { |
|
9 | 17 |
$got_rewrite = apache_mod_loaded( 'mod_rewrite', true ); |
0 | 18 |
|
19 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
20 |
* Filters whether Apache and mod_rewrite are present. |
0 | 21 |
* |
22 |
* This filter was previously used to force URL rewriting for other servers, |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
23 |
* like nginx. Use the {@see 'got_url_rewrite'} filter in got_url_rewrite() instead. |
0 | 24 |
* |
5 | 25 |
* @since 2.5.0 |
26 |
* |
|
0 | 27 |
* @see got_url_rewrite() |
28 |
* |
|
29 |
* @param bool $got_rewrite Whether Apache and mod_rewrite are present. |
|
30 |
*/ |
|
5 | 31 |
return apply_filters( 'got_rewrite', $got_rewrite ); |
0 | 32 |
} |
33 |
||
34 |
/** |
|
35 |
* Returns whether the server supports URL rewriting. |
|
36 |
* |
|
37 |
* Detects Apache's mod_rewrite, IIS 7.0+ permalink support, and nginx. |
|
38 |
* |
|
39 |
* @since 3.7.0 |
|
40 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
41 |
* @global bool $is_nginx |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
42 |
* @global bool $is_caddy |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
43 |
* |
0 | 44 |
* @return bool Whether the server supports URL rewriting. |
45 |
*/ |
|
46 |
function got_url_rewrite() { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
47 |
$got_url_rewrite = ( got_mod_rewrite() || $GLOBALS['is_nginx'] || $GLOBALS['is_caddy'] || iis7_supports_permalinks() ); |
0 | 48 |
|
49 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
50 |
* Filters whether URL rewriting is available. |
0 | 51 |
* |
52 |
* @since 3.7.0 |
|
5 | 53 |
* |
0 | 54 |
* @param bool $got_url_rewrite Whether URL rewriting is available. |
55 |
*/ |
|
56 |
return apply_filters( 'got_url_rewrite', $got_url_rewrite ); |
|
57 |
} |
|
58 |
||
59 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
60 |
* Extracts strings from between the BEGIN and END markers in the .htaccess file. |
0 | 61 |
* |
62 |
* @since 1.5.0 |
|
63 |
* |
|
16 | 64 |
* @param string $filename Filename to extract the strings from. |
65 |
* @param string $marker The marker to extract the strings from. |
|
66 |
* @return string[] An array of strings from a file (.htaccess) from between BEGIN and END markers. |
|
0 | 67 |
*/ |
68 |
function extract_from_markers( $filename, $marker ) { |
|
9 | 69 |
$result = array(); |
0 | 70 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
71 |
if ( ! file_exists( $filename ) ) { |
0 | 72 |
return $result; |
73 |
} |
|
74 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
75 |
$markerdata = explode( "\n", implode( '', file( $filename ) ) ); |
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 |
$state = false; |
19 | 78 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
79 |
foreach ( $markerdata as $markerline ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
80 |
if ( str_contains( $markerline, '# END ' . $marker ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
81 |
$state = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
82 |
} |
19 | 83 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
84 |
if ( $state ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
85 |
if ( str_starts_with( $markerline, '#' ) ) { |
16 | 86 |
continue; |
87 |
} |
|
19 | 88 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
89 |
$result[] = $markerline; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
90 |
} |
19 | 91 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
92 |
if ( str_contains( $markerline, '# BEGIN ' . $marker ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
93 |
$state = true; |
0 | 94 |
} |
95 |
} |
|
96 |
||
97 |
return $result; |
|
98 |
} |
|
99 |
||
100 |
/** |
|
16 | 101 |
* Inserts an array of strings into a file (.htaccess), placing it between |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
102 |
* BEGIN and END markers. |
0 | 103 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
104 |
* Replaces existing marked info. Retains surrounding |
0 | 105 |
* data. Creates file if none exists. |
106 |
* |
|
107 |
* @since 1.5.0 |
|
108 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
109 |
* @param string $filename Filename to alter. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
110 |
* @param string $marker The marker to alter. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
111 |
* @param array|string $insertion The new content to insert. |
0 | 112 |
* @return bool True on write success, false on failure. |
113 |
*/ |
|
114 |
function insert_with_markers( $filename, $marker, $insertion ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
115 |
if ( ! file_exists( $filename ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
116 |
if ( ! is_writable( dirname( $filename ) ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
117 |
return false; |
0 | 118 |
} |
16 | 119 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
120 |
if ( ! touch( $filename ) ) { |
0 | 121 |
return false; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
122 |
} |
16 | 123 |
|
124 |
// Make sure the file is created with a minimum set of permissions. |
|
125 |
$perms = fileperms( $filename ); |
|
19 | 126 |
|
16 | 127 |
if ( $perms ) { |
128 |
chmod( $filename, $perms | 0644 ); |
|
129 |
} |
|
18 | 130 |
} elseif ( ! is_writable( $filename ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
131 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
132 |
} |
0 | 133 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
134 |
if ( ! is_array( $insertion ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
135 |
$insertion = explode( "\n", $insertion ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
136 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
137 |
|
16 | 138 |
$switched_locale = switch_to_locale( get_locale() ); |
139 |
||
140 |
$instructions = sprintf( |
|
141 |
/* translators: 1: Marker. */ |
|
142 |
__( |
|
143 |
'The directives (lines) between "BEGIN %1$s" and "END %1$s" are |
|
144 |
dynamically generated, and should only be modified via WordPress filters. |
|
145 |
Any changes to the directives between these markers will be overwritten.' |
|
146 |
), |
|
147 |
$marker |
|
148 |
); |
|
149 |
||
150 |
$instructions = explode( "\n", $instructions ); |
|
19 | 151 |
|
16 | 152 |
foreach ( $instructions as $line => $text ) { |
153 |
$instructions[ $line ] = '# ' . $text; |
|
154 |
} |
|
155 |
||
156 |
/** |
|
157 |
* Filters the inline instructions inserted before the dynamically generated content. |
|
158 |
* |
|
159 |
* @since 5.3.0 |
|
160 |
* |
|
161 |
* @param string[] $instructions Array of lines with inline instructions. |
|
162 |
* @param string $marker The marker being inserted. |
|
163 |
*/ |
|
164 |
$instructions = apply_filters( 'insert_with_markers_inline_instructions', $instructions, $marker ); |
|
165 |
||
166 |
if ( $switched_locale ) { |
|
167 |
restore_previous_locale(); |
|
168 |
} |
|
169 |
||
170 |
$insertion = array_merge( $instructions, $insertion ); |
|
171 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
172 |
$start_marker = "# BEGIN {$marker}"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
173 |
$end_marker = "# END {$marker}"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
174 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
175 |
$fp = fopen( $filename, 'r+' ); |
19 | 176 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
177 |
if ( ! $fp ) { |
0 | 178 |
return false; |
179 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
180 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
181 |
// Attempt to get a lock. If the filesystem supports locking, this will block until the lock is acquired. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
182 |
flock( $fp, LOCK_EX ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
183 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
184 |
$lines = array(); |
19 | 185 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
186 |
while ( ! feof( $fp ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
187 |
$lines[] = rtrim( fgets( $fp ), "\r\n" ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
188 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
189 |
|
16 | 190 |
// Split out the existing file into the preceding lines, and those that appear after the marker. |
191 |
$pre_lines = array(); |
|
192 |
$post_lines = array(); |
|
193 |
$existing_lines = array(); |
|
194 |
$found_marker = false; |
|
195 |
$found_end_marker = false; |
|
19 | 196 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
197 |
foreach ( $lines as $line ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
198 |
if ( ! $found_marker && str_contains( $line, $start_marker ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
199 |
$found_marker = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
200 |
continue; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
201 |
} elseif ( ! $found_end_marker && str_contains( $line, $end_marker ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
202 |
$found_end_marker = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
203 |
continue; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
204 |
} |
19 | 205 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
206 |
if ( ! $found_marker ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
207 |
$pre_lines[] = $line; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
208 |
} elseif ( $found_marker && $found_end_marker ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
209 |
$post_lines[] = $line; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
210 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
211 |
$existing_lines[] = $line; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
212 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
213 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
214 |
|
16 | 215 |
// Check to see if there was a change. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
216 |
if ( $existing_lines === $insertion ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
217 |
flock( $fp, LOCK_UN ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
218 |
fclose( $fp ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
219 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
220 |
return true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
221 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
222 |
|
16 | 223 |
// Generate the new file data. |
9 | 224 |
$new_file_data = implode( |
225 |
"\n", |
|
226 |
array_merge( |
|
227 |
$pre_lines, |
|
228 |
array( $start_marker ), |
|
229 |
$insertion, |
|
230 |
array( $end_marker ), |
|
231 |
$post_lines |
|
232 |
) |
|
233 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
234 |
|
16 | 235 |
// Write to the start of the file, and truncate it to that length. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
236 |
fseek( $fp, 0 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
237 |
$bytes = fwrite( $fp, $new_file_data ); |
19 | 238 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
239 |
if ( $bytes ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
240 |
ftruncate( $fp, ftell( $fp ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
241 |
} |
19 | 242 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
243 |
fflush( $fp ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
244 |
flock( $fp, LOCK_UN ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
245 |
fclose( $fp ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
246 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
247 |
return (bool) $bytes; |
0 | 248 |
} |
249 |
||
250 |
/** |
|
251 |
* Updates the htaccess file with the current rules if it is writable. |
|
252 |
* |
|
253 |
* Always writes to the file if it exists and is writable to ensure that we |
|
254 |
* blank out old rules. |
|
255 |
* |
|
256 |
* @since 1.5.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
257 |
* |
16 | 258 |
* @global WP_Rewrite $wp_rewrite WordPress rewrite component. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
259 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
260 |
* @return bool|null True on write success, false on failure. Null in multisite. |
0 | 261 |
*/ |
262 |
function save_mod_rewrite_rules() { |
|
19 | 263 |
global $wp_rewrite; |
264 |
||
9 | 265 |
if ( is_multisite() ) { |
0 | 266 |
return; |
9 | 267 |
} |
0 | 268 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
269 |
// Ensure get_home_path() is declared. |
16 | 270 |
require_once ABSPATH . 'wp-admin/includes/file.php'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
271 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
272 |
$home_path = get_home_path(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
273 |
$htaccess_file = $home_path . '.htaccess'; |
0 | 274 |
|
5 | 275 |
/* |
276 |
* If the file doesn't already exist check for write access to the directory |
|
277 |
* and whether we have some rules. Else check for write access to the file. |
|
278 |
*/ |
|
19 | 279 |
if ( ! file_exists( $htaccess_file ) && is_writable( $home_path ) && $wp_rewrite->using_mod_rewrite_permalinks() |
280 |
|| is_writable( $htaccess_file ) |
|
281 |
) { |
|
0 | 282 |
if ( got_mod_rewrite() ) { |
283 |
$rules = explode( "\n", $wp_rewrite->mod_rewrite_rules() ); |
|
19 | 284 |
|
0 | 285 |
return insert_with_markers( $htaccess_file, 'WordPress', $rules ); |
286 |
} |
|
287 |
} |
|
288 |
||
289 |
return false; |
|
290 |
} |
|
291 |
||
292 |
/** |
|
293 |
* Updates the IIS web.config file with the current rules if it is writable. |
|
294 |
* If the permalinks do not require rewrite rules then the rules are deleted from the web.config file. |
|
295 |
* |
|
296 |
* @since 2.8.0 |
|
297 |
* |
|
16 | 298 |
* @global WP_Rewrite $wp_rewrite WordPress rewrite component. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
299 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
300 |
* @return bool|null True on write success, false on failure. Null in multisite. |
0 | 301 |
*/ |
9 | 302 |
function iis7_save_url_rewrite_rules() { |
19 | 303 |
global $wp_rewrite; |
304 |
||
9 | 305 |
if ( is_multisite() ) { |
0 | 306 |
return; |
9 | 307 |
} |
0 | 308 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
309 |
// Ensure get_home_path() is declared. |
16 | 310 |
require_once ABSPATH . 'wp-admin/includes/file.php'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
311 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
312 |
$home_path = get_home_path(); |
0 | 313 |
$web_config_file = $home_path . 'web.config'; |
314 |
||
16 | 315 |
// Using win_is_writable() instead of is_writable() because of a bug in Windows PHP. |
19 | 316 |
if ( iis7_supports_permalinks() |
317 |
&& ( ! file_exists( $web_config_file ) && win_is_writable( $home_path ) && $wp_rewrite->using_mod_rewrite_permalinks() |
|
318 |
|| win_is_writable( $web_config_file ) ) |
|
319 |
) { |
|
9 | 320 |
$rule = $wp_rewrite->iis7_url_rewrite_rules( false ); |
19 | 321 |
|
9 | 322 |
if ( ! empty( $rule ) ) { |
323 |
return iis7_add_rewrite_rule( $web_config_file, $rule ); |
|
0 | 324 |
} else { |
9 | 325 |
return iis7_delete_rewrite_rule( $web_config_file ); |
0 | 326 |
} |
327 |
} |
|
19 | 328 |
|
0 | 329 |
return false; |
330 |
} |
|
331 |
||
332 |
/** |
|
19 | 333 |
* Updates the "recently-edited" file for the plugin or theme file editor. |
0 | 334 |
* |
335 |
* @since 1.5.0 |
|
336 |
* |
|
5 | 337 |
* @param string $file |
0 | 338 |
*/ |
339 |
function update_recently_edited( $file ) { |
|
9 | 340 |
$oldfiles = (array) get_option( 'recently_edited' ); |
19 | 341 |
|
0 | 342 |
if ( $oldfiles ) { |
9 | 343 |
$oldfiles = array_reverse( $oldfiles ); |
0 | 344 |
$oldfiles[] = $file; |
9 | 345 |
$oldfiles = array_reverse( $oldfiles ); |
346 |
$oldfiles = array_unique( $oldfiles ); |
|
19 | 347 |
|
9 | 348 |
if ( 5 < count( $oldfiles ) ) { |
0 | 349 |
array_pop( $oldfiles ); |
9 | 350 |
} |
0 | 351 |
} else { |
352 |
$oldfiles[] = $file; |
|
353 |
} |
|
19 | 354 |
|
0 | 355 |
update_option( 'recently_edited', $oldfiles ); |
356 |
} |
|
357 |
||
358 |
/** |
|
19 | 359 |
* Makes a tree structure for the theme file editor's file list. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
360 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
361 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
362 |
* @access private |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
363 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
364 |
* @param array $allowed_files List of theme file paths. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
365 |
* @return array Tree structure for listing theme files. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
366 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
367 |
function wp_make_theme_file_tree( $allowed_files ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
368 |
$tree_list = array(); |
19 | 369 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
370 |
foreach ( $allowed_files as $file_name => $absolute_filename ) { |
9 | 371 |
$list = explode( '/', $file_name ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
372 |
$last_dir = &$tree_list; |
19 | 373 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
374 |
foreach ( $list as $dir ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
375 |
$last_dir =& $last_dir[ $dir ]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
376 |
} |
19 | 377 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
378 |
$last_dir = $file_name; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
379 |
} |
19 | 380 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
381 |
return $tree_list; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
382 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
383 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
384 |
/** |
19 | 385 |
* Outputs the formatted file list for the theme file editor. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
386 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
387 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
388 |
* @access private |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
389 |
* |
9 | 390 |
* @global string $relative_file Name of the file being edited relative to the |
391 |
* theme directory. |
|
392 |
* @global string $stylesheet The stylesheet name of the theme being edited. |
|
393 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
394 |
* @param array|string $tree List of file/folder paths, or filename. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
395 |
* @param int $level The aria-level for the current iteration. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
396 |
* @param int $size The aria-setsize for the current iteration. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
397 |
* @param int $index The aria-posinset for the current iteration. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
398 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
399 |
function wp_print_theme_file_tree( $tree, $level = 2, $size = 1, $index = 1 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
400 |
global $relative_file, $stylesheet; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
401 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
402 |
if ( is_array( $tree ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
403 |
$index = 0; |
9 | 404 |
$size = count( $tree ); |
19 | 405 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
406 |
foreach ( $tree as $label => $theme_file ) : |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
407 |
++$index; |
19 | 408 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
409 |
if ( ! is_array( $theme_file ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
410 |
wp_print_theme_file_tree( $theme_file, $level, $index, $size ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
411 |
continue; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
412 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
413 |
?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
414 |
<li role="treeitem" aria-expanded="true" tabindex="-1" |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
415 |
aria-level="<?php echo esc_attr( $level ); ?>" |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
416 |
aria-setsize="<?php echo esc_attr( $size ); ?>" |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
417 |
aria-posinset="<?php echo esc_attr( $index ); ?>"> |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
418 |
<span class="folder-label"><?php echo esc_html( $label ); ?> <span class="screen-reader-text"> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
419 |
<?php |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
420 |
/* translators: Hidden accessibility text. */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
421 |
_e( 'folder' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
422 |
?> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
423 |
</span><span aria-hidden="true" class="icon"></span></span> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
424 |
<ul role="group" class="tree-folder"><?php wp_print_theme_file_tree( $theme_file, $level + 1, $index, $size ); ?></ul> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
425 |
</li> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
426 |
<?php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
427 |
endforeach; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
428 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
429 |
$filename = $tree; |
9 | 430 |
$url = add_query_arg( |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
431 |
array( |
9 | 432 |
'file' => rawurlencode( $tree ), |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
433 |
'theme' => rawurlencode( $stylesheet ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
434 |
), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
435 |
self_admin_url( 'theme-editor.php' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
436 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
437 |
?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
438 |
<li role="none" class="<?php echo esc_attr( $relative_file === $filename ? 'current-file' : '' ); ?>"> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
439 |
<a role="treeitem" tabindex="<?php echo esc_attr( $relative_file === $filename ? '0' : '-1' ); ?>" |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
440 |
href="<?php echo esc_url( $url ); ?>" |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
441 |
aria-level="<?php echo esc_attr( $level ); ?>" |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
442 |
aria-setsize="<?php echo esc_attr( $size ); ?>" |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
443 |
aria-posinset="<?php echo esc_attr( $index ); ?>"> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
444 |
<?php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
445 |
$file_description = esc_html( get_file_description( $filename ) ); |
19 | 446 |
|
9 | 447 |
if ( $file_description !== $filename && wp_basename( $filename ) !== $file_description ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
448 |
$file_description .= '<br /><span class="nonessential">(' . esc_html( $filename ) . ')</span>'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
449 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
450 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
451 |
if ( $relative_file === $filename ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
452 |
echo '<span class="notice notice-info">' . $file_description . '</span>'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
453 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
454 |
echo $file_description; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
455 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
456 |
?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
457 |
</a> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
458 |
</li> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
459 |
<?php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
460 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
461 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
462 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
463 |
/** |
19 | 464 |
* Makes a tree structure for the plugin file editor's file list. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
465 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
466 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
467 |
* @access private |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
468 |
* |
9 | 469 |
* @param array $plugin_editable_files List of plugin file paths. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
470 |
* @return array Tree structure for listing plugin files. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
471 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
472 |
function wp_make_plugin_file_tree( $plugin_editable_files ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
473 |
$tree_list = array(); |
19 | 474 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
475 |
foreach ( $plugin_editable_files as $plugin_file ) { |
9 | 476 |
$list = explode( '/', preg_replace( '#^.+?/#', '', $plugin_file ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
477 |
$last_dir = &$tree_list; |
19 | 478 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
479 |
foreach ( $list as $dir ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
480 |
$last_dir =& $last_dir[ $dir ]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
481 |
} |
19 | 482 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
483 |
$last_dir = $plugin_file; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
484 |
} |
19 | 485 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
486 |
return $tree_list; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
487 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
488 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
489 |
/** |
19 | 490 |
* Outputs the formatted file list for the plugin file editor. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
491 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
492 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
493 |
* @access private |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
494 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
495 |
* @param array|string $tree List of file/folder paths, or filename. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
496 |
* @param string $label Name of file or folder to print. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
497 |
* @param int $level The aria-level for the current iteration. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
498 |
* @param int $size The aria-setsize for the current iteration. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
499 |
* @param int $index The aria-posinset for the current iteration. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
500 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
501 |
function wp_print_plugin_file_tree( $tree, $label = '', $level = 2, $size = 1, $index = 1 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
502 |
global $file, $plugin; |
19 | 503 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
504 |
if ( is_array( $tree ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
505 |
$index = 0; |
9 | 506 |
$size = count( $tree ); |
19 | 507 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
508 |
foreach ( $tree as $label => $plugin_file ) : |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
509 |
++$index; |
19 | 510 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
511 |
if ( ! is_array( $plugin_file ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
512 |
wp_print_plugin_file_tree( $plugin_file, $label, $level, $index, $size ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
513 |
continue; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
514 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
515 |
?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
516 |
<li role="treeitem" aria-expanded="true" tabindex="-1" |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
517 |
aria-level="<?php echo esc_attr( $level ); ?>" |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
518 |
aria-setsize="<?php echo esc_attr( $size ); ?>" |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
519 |
aria-posinset="<?php echo esc_attr( $index ); ?>"> |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
520 |
<span class="folder-label"><?php echo esc_html( $label ); ?> <span class="screen-reader-text"> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
521 |
<?php |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
522 |
/* translators: Hidden accessibility text. */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
523 |
_e( 'folder' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
524 |
?> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
525 |
</span><span aria-hidden="true" class="icon"></span></span> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
526 |
<ul role="group" class="tree-folder"><?php wp_print_plugin_file_tree( $plugin_file, '', $level + 1, $index, $size ); ?></ul> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
527 |
</li> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
528 |
<?php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
529 |
endforeach; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
530 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
531 |
$url = add_query_arg( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
532 |
array( |
9 | 533 |
'file' => rawurlencode( $tree ), |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
534 |
'plugin' => rawurlencode( $plugin ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
535 |
), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
536 |
self_admin_url( 'plugin-editor.php' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
537 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
538 |
?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
539 |
<li role="none" class="<?php echo esc_attr( $file === $tree ? 'current-file' : '' ); ?>"> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
540 |
<a role="treeitem" tabindex="<?php echo esc_attr( $file === $tree ? '0' : '-1' ); ?>" |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
541 |
href="<?php echo esc_url( $url ); ?>" |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
542 |
aria-level="<?php echo esc_attr( $level ); ?>" |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
543 |
aria-setsize="<?php echo esc_attr( $size ); ?>" |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
544 |
aria-posinset="<?php echo esc_attr( $index ); ?>"> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
545 |
<?php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
546 |
if ( $file === $tree ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
547 |
echo '<span class="notice notice-info">' . esc_html( $label ) . '</span>'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
548 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
549 |
echo esc_html( $label ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
550 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
551 |
?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
552 |
</a> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
553 |
</li> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
554 |
<?php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
555 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
556 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
557 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
558 |
/** |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
559 |
* Flushes rewrite rules if `siteurl`, `home` or `page_on_front` changed. |
0 | 560 |
* |
561 |
* @since 2.1.0 |
|
562 |
* |
|
563 |
* @param string $old_value |
|
564 |
* @param string $value |
|
565 |
*/ |
|
566 |
function update_home_siteurl( $old_value, $value ) { |
|
9 | 567 |
if ( wp_installing() ) { |
0 | 568 |
return; |
9 | 569 |
} |
0 | 570 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
571 |
if ( is_multisite() && ms_is_switched() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
572 |
delete_option( 'rewrite_rules' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
573 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
574 |
flush_rewrite_rules(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
575 |
} |
0 | 576 |
} |
577 |
||
578 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
579 |
* Resets global variables based on `$_GET` and `$_POST`. |
0 | 580 |
* |
581 |
* This function resets global variables based on the names passed |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
582 |
* in the `$vars` array to the value of `$_POST[$var]` or `$_GET[$var]` or an |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
583 |
* empty string if neither is defined. |
0 | 584 |
* |
585 |
* @since 2.0.0 |
|
586 |
* |
|
587 |
* @param array $vars An array of globals to reset. |
|
588 |
*/ |
|
589 |
function wp_reset_vars( $vars ) { |
|
5 | 590 |
foreach ( $vars as $var ) { |
591 |
if ( empty( $_POST[ $var ] ) ) { |
|
592 |
if ( empty( $_GET[ $var ] ) ) { |
|
593 |
$GLOBALS[ $var ] = ''; |
|
594 |
} else { |
|
595 |
$GLOBALS[ $var ] = $_GET[ $var ]; |
|
596 |
} |
|
0 | 597 |
} else { |
5 | 598 |
$GLOBALS[ $var ] = $_POST[ $var ]; |
0 | 599 |
} |
600 |
} |
|
601 |
} |
|
602 |
||
603 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
604 |
* Displays the given administration message. |
0 | 605 |
* |
606 |
* @since 2.1.0 |
|
607 |
* |
|
5 | 608 |
* @param string|WP_Error $message |
0 | 609 |
*/ |
9 | 610 |
function show_message( $message ) { |
611 |
if ( is_wp_error( $message ) ) { |
|
612 |
if ( $message->get_error_data() && is_string( $message->get_error_data() ) ) { |
|
0 | 613 |
$message = $message->get_error_message() . ': ' . $message->get_error_data(); |
9 | 614 |
} else { |
0 | 615 |
$message = $message->get_error_message(); |
9 | 616 |
} |
0 | 617 |
} |
19 | 618 |
|
0 | 619 |
echo "<p>$message</p>\n"; |
620 |
wp_ob_end_flush_all(); |
|
621 |
flush(); |
|
622 |
} |
|
623 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
624 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
625 |
* @since 2.8.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
626 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
627 |
* @param string $content |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
628 |
* @return array |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
629 |
*/ |
0 | 630 |
function wp_doc_link_parse( $content ) { |
9 | 631 |
if ( ! is_string( $content ) || empty( $content ) ) { |
0 | 632 |
return array(); |
9 | 633 |
} |
0 | 634 |
|
9 | 635 |
if ( ! function_exists( 'token_get_all' ) ) { |
0 | 636 |
return array(); |
9 | 637 |
} |
0 | 638 |
|
9 | 639 |
$tokens = token_get_all( $content ); |
640 |
$count = count( $tokens ); |
|
641 |
$functions = array(); |
|
0 | 642 |
$ignore_functions = array(); |
19 | 643 |
|
5 | 644 |
for ( $t = 0; $t < $count - 2; $t++ ) { |
645 |
if ( ! is_array( $tokens[ $t ] ) ) { |
|
646 |
continue; |
|
647 |
} |
|
648 |
||
19 | 649 |
if ( T_STRING === $tokens[ $t ][0] && ( '(' === $tokens[ $t + 1 ] || '(' === $tokens[ $t + 2 ] ) ) { |
16 | 650 |
// If it's a function or class defined locally, there's not going to be any docs available. |
651 |
if ( ( isset( $tokens[ $t - 2 ][1] ) && in_array( $tokens[ $t - 2 ][1], array( 'function', 'class' ), true ) ) |
|
19 | 652 |
|| ( isset( $tokens[ $t - 2 ][0] ) && T_OBJECT_OPERATOR === $tokens[ $t - 1 ][0] ) |
16 | 653 |
) { |
9 | 654 |
$ignore_functions[] = $tokens[ $t ][1]; |
0 | 655 |
} |
19 | 656 |
|
16 | 657 |
// Add this to our stack of unique references. |
9 | 658 |
$functions[] = $tokens[ $t ][1]; |
0 | 659 |
} |
660 |
} |
|
661 |
||
662 |
$functions = array_unique( $functions ); |
|
663 |
sort( $functions ); |
|
5 | 664 |
|
665 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
666 |
* Filters the list of functions and classes to be ignored from the documentation lookup. |
5 | 667 |
* |
668 |
* @since 2.8.0 |
|
669 |
* |
|
9 | 670 |
* @param string[] $ignore_functions Array of names of functions and classes to be ignored. |
5 | 671 |
*/ |
0 | 672 |
$ignore_functions = apply_filters( 'documentation_ignore_functions', $ignore_functions ); |
5 | 673 |
|
0 | 674 |
$ignore_functions = array_unique( $ignore_functions ); |
675 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
676 |
$output = array(); |
19 | 677 |
|
0 | 678 |
foreach ( $functions as $function ) { |
16 | 679 |
if ( in_array( $function, $ignore_functions, true ) ) { |
0 | 680 |
continue; |
9 | 681 |
} |
19 | 682 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
683 |
$output[] = $function; |
0 | 684 |
} |
685 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
686 |
return $output; |
0 | 687 |
} |
688 |
||
689 |
/** |
|
690 |
* Saves option for number of rows when listing posts, pages, comments, etc. |
|
691 |
* |
|
5 | 692 |
* @since 2.8.0 |
693 |
*/ |
|
0 | 694 |
function set_screen_options() { |
19 | 695 |
if ( ! isset( $_POST['wp_screen_options'] ) || ! is_array( $_POST['wp_screen_options'] ) ) { |
696 |
return; |
|
697 |
} |
|
0 | 698 |
|
19 | 699 |
check_admin_referer( 'screen-options-nonce', 'screenoptionnonce' ); |
700 |
||
701 |
$user = wp_get_current_user(); |
|
0 | 702 |
|
19 | 703 |
if ( ! $user ) { |
704 |
return; |
|
705 |
} |
|
706 |
||
707 |
$option = $_POST['wp_screen_options']['option']; |
|
708 |
$value = $_POST['wp_screen_options']['value']; |
|
0 | 709 |
|
19 | 710 |
if ( sanitize_key( $option ) !== $option ) { |
711 |
return; |
|
712 |
} |
|
713 |
||
714 |
$map_option = $option; |
|
715 |
$type = str_replace( 'edit_', '', $map_option ); |
|
716 |
$type = str_replace( '_per_page', '', $type ); |
|
0 | 717 |
|
19 | 718 |
if ( in_array( $type, get_taxonomies(), true ) ) { |
719 |
$map_option = 'edit_tags_per_page'; |
|
720 |
} elseif ( in_array( $type, get_post_types(), true ) ) { |
|
721 |
$map_option = 'edit_per_page'; |
|
722 |
} else { |
|
723 |
$option = str_replace( '-', '_', $option ); |
|
724 |
} |
|
16 | 725 |
|
19 | 726 |
switch ( $map_option ) { |
727 |
case 'edit_per_page': |
|
728 |
case 'users_per_page': |
|
729 |
case 'edit_comments_per_page': |
|
730 |
case 'upload_per_page': |
|
731 |
case 'edit_tags_per_page': |
|
732 |
case 'plugins_per_page': |
|
733 |
case 'export_personal_data_requests_per_page': |
|
734 |
case 'remove_personal_data_requests_per_page': |
|
735 |
// Network admin. |
|
736 |
case 'sites_network_per_page': |
|
737 |
case 'users_network_per_page': |
|
738 |
case 'site_users_network_per_page': |
|
739 |
case 'plugins_network_per_page': |
|
740 |
case 'themes_network_per_page': |
|
741 |
case 'site_themes_network_per_page': |
|
742 |
$value = (int) $value; |
|
16 | 743 |
|
19 | 744 |
if ( $value < 1 || $value > 999 ) { |
745 |
return; |
|
746 |
} |
|
747 |
||
748 |
break; |
|
749 |
||
750 |
default: |
|
751 |
$screen_option = false; |
|
752 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
753 |
if ( str_ends_with( $option, '_page' ) || 'layout_columns' === $option ) { |
5 | 754 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
755 |
* Filters a screen option value before it is set. |
5 | 756 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
757 |
* The filter can also be used to modify non-standard `[items]_per_page` |
19 | 758 |
* settings. See the parent function for a full list of standard options. |
5 | 759 |
* |
16 | 760 |
* Returning false from the filter will skip saving the current option. |
5 | 761 |
* |
19 | 762 |
* @since 2.8.0 |
763 |
* @since 5.4.2 Only applied to options ending with '_page', |
|
764 |
* or the 'layout_columns' option. |
|
5 | 765 |
* |
766 |
* @see set_screen_options() |
|
767 |
* |
|
19 | 768 |
* @param mixed $screen_option The value to save instead of the option value. |
769 |
* Default false (to skip saving the current option). |
|
770 |
* @param string $option The option name. |
|
771 |
* @param int $value The option value. |
|
5 | 772 |
*/ |
19 | 773 |
$screen_option = apply_filters( 'set-screen-option', $screen_option, $option, $value ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
774 |
} |
|
5 | 775 |
|
19 | 776 |
/** |
777 |
* Filters a screen option value before it is set. |
|
778 |
* |
|
779 |
* The dynamic portion of the hook name, `$option`, refers to the option name. |
|
780 |
* |
|
781 |
* Returning false from the filter will skip saving the current option. |
|
782 |
* |
|
783 |
* @since 5.4.2 |
|
784 |
* |
|
785 |
* @see set_screen_options() |
|
786 |
* |
|
787 |
* @param mixed $screen_option The value to save instead of the option value. |
|
788 |
* Default false (to skip saving the current option). |
|
789 |
* @param string $option The option name. |
|
790 |
* @param int $value The option value. |
|
791 |
*/ |
|
792 |
$value = apply_filters( "set_screen_option_{$option}", $screen_option, $option, $value ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
793 |
|
19 | 794 |
if ( false === $value ) { |
795 |
return; |
|
796 |
} |
|
797 |
||
798 |
break; |
|
799 |
} |
|
800 |
||
801 |
update_user_meta( $user->ID, $option, $value ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
802 |
|
19 | 803 |
$url = remove_query_arg( array( 'pagenum', 'apage', 'paged' ), wp_get_referer() ); |
804 |
||
805 |
if ( isset( $_POST['mode'] ) ) { |
|
806 |
$url = add_query_arg( array( 'mode' => $_POST['mode'] ), $url ); |
|
0 | 807 |
} |
19 | 808 |
|
809 |
wp_safe_redirect( $url ); |
|
810 |
exit; |
|
0 | 811 |
} |
812 |
||
813 |
/** |
|
19 | 814 |
* Checks if rewrite rule for WordPress already exists in the IIS 7+ configuration file. |
0 | 815 |
* |
816 |
* @since 2.8.0 |
|
817 |
* |
|
19 | 818 |
* @param string $filename The file path to the configuration file. |
0 | 819 |
* @return bool |
820 |
*/ |
|
9 | 821 |
function iis7_rewrite_rule_exists( $filename ) { |
822 |
if ( ! file_exists( $filename ) ) { |
|
0 | 823 |
return false; |
9 | 824 |
} |
19 | 825 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
826 |
if ( ! class_exists( 'DOMDocument', false ) ) { |
0 | 827 |
return false; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
828 |
} |
0 | 829 |
|
830 |
$doc = new DOMDocument(); |
|
19 | 831 |
|
9 | 832 |
if ( $doc->load( $filename ) === false ) { |
0 | 833 |
return false; |
9 | 834 |
} |
19 | 835 |
|
9 | 836 |
$xpath = new DOMXPath( $doc ); |
837 |
$rules = $xpath->query( '/configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'wordpress\')] | /configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'WordPress\')]' ); |
|
19 | 838 |
|
839 |
if ( 0 === $rules->length ) { |
|
0 | 840 |
return false; |
9 | 841 |
} |
19 | 842 |
|
843 |
return true; |
|
0 | 844 |
} |
845 |
||
846 |
/** |
|
19 | 847 |
* Deletes WordPress rewrite rule from web.config file if it exists there. |
0 | 848 |
* |
849 |
* @since 2.8.0 |
|
850 |
* |
|
19 | 851 |
* @param string $filename Name of the configuration file. |
0 | 852 |
* @return bool |
853 |
*/ |
|
9 | 854 |
function iis7_delete_rewrite_rule( $filename ) { |
16 | 855 |
// If configuration file does not exist then rules also do not exist, so there is nothing to delete. |
9 | 856 |
if ( ! file_exists( $filename ) ) { |
0 | 857 |
return true; |
9 | 858 |
} |
0 | 859 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
860 |
if ( ! class_exists( 'DOMDocument', false ) ) { |
0 | 861 |
return false; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
862 |
} |
0 | 863 |
|
9 | 864 |
$doc = new DOMDocument(); |
0 | 865 |
$doc->preserveWhiteSpace = false; |
866 |
||
9 | 867 |
if ( $doc->load( $filename ) === false ) { |
0 | 868 |
return false; |
9 | 869 |
} |
19 | 870 |
|
9 | 871 |
$xpath = new DOMXPath( $doc ); |
872 |
$rules = $xpath->query( '/configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'wordpress\')] | /configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'WordPress\')]' ); |
|
19 | 873 |
|
0 | 874 |
if ( $rules->length > 0 ) { |
9 | 875 |
$child = $rules->item( 0 ); |
0 | 876 |
$parent = $child->parentNode; |
9 | 877 |
$parent->removeChild( $child ); |
0 | 878 |
$doc->formatOutput = true; |
9 | 879 |
saveDomDocument( $doc, $filename ); |
0 | 880 |
} |
19 | 881 |
|
0 | 882 |
return true; |
883 |
} |
|
884 |
||
885 |
/** |
|
19 | 886 |
* Adds WordPress rewrite rule to the IIS 7+ configuration file. |
0 | 887 |
* |
888 |
* @since 2.8.0 |
|
889 |
* |
|
19 | 890 |
* @param string $filename The file path to the configuration file. |
891 |
* @param string $rewrite_rule The XML fragment with URL Rewrite rule. |
|
0 | 892 |
* @return bool |
893 |
*/ |
|
9 | 894 |
function iis7_add_rewrite_rule( $filename, $rewrite_rule ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
895 |
if ( ! class_exists( 'DOMDocument', false ) ) { |
0 | 896 |
return false; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
897 |
} |
0 | 898 |
|
899 |
// If configuration file does not exist then we create one. |
|
9 | 900 |
if ( ! file_exists( $filename ) ) { |
901 |
$fp = fopen( $filename, 'w' ); |
|
902 |
fwrite( $fp, '<configuration/>' ); |
|
903 |
fclose( $fp ); |
|
0 | 904 |
} |
905 |
||
9 | 906 |
$doc = new DOMDocument(); |
0 | 907 |
$doc->preserveWhiteSpace = false; |
908 |
||
9 | 909 |
if ( $doc->load( $filename ) === false ) { |
0 | 910 |
return false; |
9 | 911 |
} |
0 | 912 |
|
9 | 913 |
$xpath = new DOMXPath( $doc ); |
0 | 914 |
|
16 | 915 |
// First check if the rule already exists as in that case there is no need to re-add it. |
9 | 916 |
$wordpress_rules = $xpath->query( '/configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'wordpress\')] | /configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'WordPress\')]' ); |
19 | 917 |
|
9 | 918 |
if ( $wordpress_rules->length > 0 ) { |
0 | 919 |
return true; |
9 | 920 |
} |
0 | 921 |
|
16 | 922 |
// Check the XPath to the rewrite rule and create XML nodes if they do not exist. |
19 | 923 |
$xml_nodes = $xpath->query( '/configuration/system.webServer/rewrite/rules' ); |
924 |
||
925 |
if ( $xml_nodes->length > 0 ) { |
|
926 |
$rules_node = $xml_nodes->item( 0 ); |
|
0 | 927 |
} else { |
9 | 928 |
$rules_node = $doc->createElement( 'rules' ); |
0 | 929 |
|
19 | 930 |
$xml_nodes = $xpath->query( '/configuration/system.webServer/rewrite' ); |
931 |
||
932 |
if ( $xml_nodes->length > 0 ) { |
|
933 |
$rewrite_node = $xml_nodes->item( 0 ); |
|
9 | 934 |
$rewrite_node->appendChild( $rules_node ); |
0 | 935 |
} else { |
9 | 936 |
$rewrite_node = $doc->createElement( 'rewrite' ); |
937 |
$rewrite_node->appendChild( $rules_node ); |
|
0 | 938 |
|
19 | 939 |
$xml_nodes = $xpath->query( '/configuration/system.webServer' ); |
940 |
||
941 |
if ( $xml_nodes->length > 0 ) { |
|
942 |
$system_web_server_node = $xml_nodes->item( 0 ); |
|
943 |
$system_web_server_node->appendChild( $rewrite_node ); |
|
0 | 944 |
} else { |
19 | 945 |
$system_web_server_node = $doc->createElement( 'system.webServer' ); |
946 |
$system_web_server_node->appendChild( $rewrite_node ); |
|
0 | 947 |
|
19 | 948 |
$xml_nodes = $xpath->query( '/configuration' ); |
949 |
||
950 |
if ( $xml_nodes->length > 0 ) { |
|
951 |
$config_node = $xml_nodes->item( 0 ); |
|
952 |
$config_node->appendChild( $system_web_server_node ); |
|
0 | 953 |
} else { |
9 | 954 |
$config_node = $doc->createElement( 'configuration' ); |
955 |
$doc->appendChild( $config_node ); |
|
19 | 956 |
$config_node->appendChild( $system_web_server_node ); |
0 | 957 |
} |
958 |
} |
|
959 |
} |
|
960 |
} |
|
961 |
||
962 |
$rule_fragment = $doc->createDocumentFragment(); |
|
9 | 963 |
$rule_fragment->appendXML( $rewrite_rule ); |
964 |
$rules_node->appendChild( $rule_fragment ); |
|
0 | 965 |
|
9 | 966 |
$doc->encoding = 'UTF-8'; |
0 | 967 |
$doc->formatOutput = true; |
9 | 968 |
saveDomDocument( $doc, $filename ); |
0 | 969 |
|
970 |
return true; |
|
971 |
} |
|
972 |
||
973 |
/** |
|
19 | 974 |
* Saves the XML document into a file. |
0 | 975 |
* |
976 |
* @since 2.8.0 |
|
977 |
* |
|
978 |
* @param DOMDocument $doc |
|
16 | 979 |
* @param string $filename |
0 | 980 |
*/ |
16 | 981 |
function saveDomDocument( $doc, $filename ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid |
0 | 982 |
$config = $doc->saveXML(); |
9 | 983 |
$config = preg_replace( "/([^\r])\n/", "$1\r\n", $config ); |
19 | 984 |
|
985 |
$fp = fopen( $filename, 'w' ); |
|
9 | 986 |
fwrite( $fp, $config ); |
987 |
fclose( $fp ); |
|
0 | 988 |
} |
989 |
||
990 |
/** |
|
19 | 991 |
* Displays the default admin color scheme picker (Used in user-edit.php). |
0 | 992 |
* |
993 |
* @since 3.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
994 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
995 |
* @global array $_wp_admin_css_colors |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
996 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
997 |
* @param int $user_id User ID. |
0 | 998 |
*/ |
5 | 999 |
function admin_color_scheme_picker( $user_id ) { |
1000 |
global $_wp_admin_css_colors; |
|
1001 |
||
1002 |
ksort( $_wp_admin_css_colors ); |
|
1003 |
||
1004 |
if ( isset( $_wp_admin_css_colors['fresh'] ) ) { |
|
1005 |
// Set Default ('fresh') and Light should go first. |
|
9 | 1006 |
$_wp_admin_css_colors = array_filter( |
1007 |
array_merge( |
|
1008 |
array( |
|
16 | 1009 |
'fresh' => '', |
1010 |
'light' => '', |
|
1011 |
'modern' => '', |
|
9 | 1012 |
), |
1013 |
$_wp_admin_css_colors |
|
1014 |
) |
|
1015 |
); |
|
5 | 1016 |
} |
1017 |
||
1018 |
$current_color = get_user_option( 'admin_color', $user_id ); |
|
1019 |
||
1020 |
if ( empty( $current_color ) || ! isset( $_wp_admin_css_colors[ $current_color ] ) ) { |
|
1021 |
$current_color = 'fresh'; |
|
1022 |
} |
|
1023 |
?> |
|
1024 |
<fieldset id="color-picker" class="scheme-list"> |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1025 |
<legend class="screen-reader-text"><span> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1026 |
<?php |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1027 |
/* translators: Hidden accessibility text. */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1028 |
_e( 'Admin Color Scheme' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1029 |
?> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1030 |
</span></legend> |
5 | 1031 |
<?php |
1032 |
wp_nonce_field( 'save-color-scheme', 'color-nonce', false ); |
|
1033 |
foreach ( $_wp_admin_css_colors as $color => $color_info ) : |
|
1034 |
||
1035 |
?> |
|
19 | 1036 |
<div class="color-option <?php echo ( $color === $current_color ) ? 'selected' : ''; ?>"> |
5 | 1037 |
<input name="admin_color" id="admin_color_<?php echo esc_attr( $color ); ?>" type="radio" value="<?php echo esc_attr( $color ); ?>" class="tog" <?php checked( $color, $current_color ); ?> /> |
1038 |
<input type="hidden" class="css_url" value="<?php echo esc_url( $color_info->url ); ?>" /> |
|
1039 |
<input type="hidden" class="icon_colors" value="<?php echo esc_attr( wp_json_encode( array( 'icons' => $color_info->icon_colors ) ) ); ?>" /> |
|
1040 |
<label for="admin_color_<?php echo esc_attr( $color ); ?>"><?php echo esc_html( $color_info->name ); ?></label> |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1041 |
<div class="color-palette"> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1042 |
<?php |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1043 |
foreach ( $color_info->colors as $html_color ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1044 |
?> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1045 |
<div class="color-palette-shade" style="background-color: <?php echo esc_attr( $html_color ); ?>"> </div> |
5 | 1046 |
<?php |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1047 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1048 |
?> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1049 |
</div> |
5 | 1050 |
</div> |
1051 |
<?php |
|
1052 |
||
1053 |
endforeach; |
|
9 | 1054 |
?> |
5 | 1055 |
</fieldset> |
1056 |
<?php |
|
0 | 1057 |
} |
1058 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1059 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1060 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1061 |
* @global array $_wp_admin_css_colors |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1062 |
*/ |
5 | 1063 |
function wp_color_scheme_settings() { |
1064 |
global $_wp_admin_css_colors; |
|
1065 |
||
1066 |
$color_scheme = get_user_option( 'admin_color' ); |
|
1067 |
||
1068 |
// It's possible to have a color scheme set that is no longer registered. |
|
1069 |
if ( empty( $_wp_admin_css_colors[ $color_scheme ] ) ) { |
|
1070 |
$color_scheme = 'fresh'; |
|
1071 |
} |
|
1072 |
||
1073 |
if ( ! empty( $_wp_admin_css_colors[ $color_scheme ]->icon_colors ) ) { |
|
1074 |
$icon_colors = $_wp_admin_css_colors[ $color_scheme ]->icon_colors; |
|
1075 |
} elseif ( ! empty( $_wp_admin_css_colors['fresh']->icon_colors ) ) { |
|
1076 |
$icon_colors = $_wp_admin_css_colors['fresh']->icon_colors; |
|
1077 |
} else { |
|
1078 |
// Fall back to the default set of icon colors if the default scheme is missing. |
|
9 | 1079 |
$icon_colors = array( |
18 | 1080 |
'base' => '#a7aaad', |
1081 |
'focus' => '#72aee6', |
|
9 | 1082 |
'current' => '#fff', |
1083 |
); |
|
5 | 1084 |
} |
1085 |
||
1086 |
echo '<script type="text/javascript">var _wpColorScheme = ' . wp_json_encode( array( 'icons' => $icon_colors ) ) . ";</script>\n"; |
|
1087 |
} |
|
1088 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1089 |
/** |
16 | 1090 |
* Displays the viewport meta in the admin. |
1091 |
* |
|
1092 |
* @since 5.5.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1093 |
*/ |
16 | 1094 |
function wp_admin_viewport_meta() { |
1095 |
/** |
|
1096 |
* Filters the viewport meta in the admin. |
|
1097 |
* |
|
1098 |
* @since 5.5.0 |
|
1099 |
* |
|
1100 |
* @param string $viewport_meta The viewport meta. |
|
1101 |
*/ |
|
1102 |
$viewport_meta = apply_filters( 'admin_viewport_meta', 'width=device-width,initial-scale=1.0' ); |
|
1103 |
||
1104 |
if ( empty( $viewport_meta ) ) { |
|
1105 |
return; |
|
0 | 1106 |
} |
16 | 1107 |
|
1108 |
echo '<meta name="viewport" content="' . esc_attr( $viewport_meta ) . '">'; |
|
1109 |
} |
|
1110 |
||
1111 |
/** |
|
1112 |
* Adds viewport meta for mobile in Customizer. |
|
1113 |
* |
|
1114 |
* Hooked to the {@see 'admin_viewport_meta'} filter. |
|
1115 |
* |
|
1116 |
* @since 5.5.0 |
|
1117 |
* |
|
1118 |
* @param string $viewport_meta The viewport meta. |
|
1119 |
* @return string Filtered viewport meta. |
|
1120 |
*/ |
|
1121 |
function _customizer_mobile_viewport_meta( $viewport_meta ) { |
|
1122 |
return trim( $viewport_meta, ',' ) . ',minimum-scale=0.5,maximum-scale=1.2'; |
|
0 | 1123 |
} |
1124 |
||
1125 |
/** |
|
19 | 1126 |
* Checks lock status for posts displayed on the Posts screen. |
0 | 1127 |
* |
5 | 1128 |
* @since 3.6.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1129 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1130 |
* @param array $response The Heartbeat response. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1131 |
* @param array $data The $_POST data sent. |
16 | 1132 |
* @param string $screen_id The screen ID. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1133 |
* @return array The Heartbeat response. |
0 | 1134 |
*/ |
1135 |
function wp_check_locked_posts( $response, $data, $screen_id ) { |
|
1136 |
$checked = array(); |
|
1137 |
||
1138 |
if ( array_key_exists( 'wp-check-locked-posts', $data ) && is_array( $data['wp-check-locked-posts'] ) ) { |
|
1139 |
foreach ( $data['wp-check-locked-posts'] as $key ) { |
|
16 | 1140 |
$post_id = absint( substr( $key, 5 ) ); |
19 | 1141 |
|
16 | 1142 |
if ( ! $post_id ) { |
0 | 1143 |
continue; |
9 | 1144 |
} |
0 | 1145 |
|
16 | 1146 |
$user_id = wp_check_post_lock( $post_id ); |
19 | 1147 |
|
16 | 1148 |
if ( $user_id ) { |
1149 |
$user = get_userdata( $user_id ); |
|
19 | 1150 |
|
16 | 1151 |
if ( $user && current_user_can( 'edit_post', $post_id ) ) { |
1152 |
$send = array( |
|
19 | 1153 |
'name' => $user->display_name, |
16 | 1154 |
/* translators: %s: User's display name. */ |
1155 |
'text' => sprintf( __( '%s is currently editing' ), $user->display_name ), |
|
1156 |
); |
|
0 | 1157 |
|
16 | 1158 |
if ( get_option( 'show_avatars' ) ) { |
1159 |
$send['avatar_src'] = get_avatar_url( $user->ID, array( 'size' => 18 ) ); |
|
1160 |
$send['avatar_src_2x'] = get_avatar_url( $user->ID, array( 'size' => 36 ) ); |
|
1161 |
} |
|
1162 |
||
1163 |
$checked[ $key ] = $send; |
|
9 | 1164 |
} |
0 | 1165 |
} |
1166 |
} |
|
1167 |
} |
|
1168 |
||
9 | 1169 |
if ( ! empty( $checked ) ) { |
0 | 1170 |
$response['wp-check-locked-posts'] = $checked; |
9 | 1171 |
} |
0 | 1172 |
|
1173 |
return $response; |
|
1174 |
} |
|
1175 |
||
1176 |
/** |
|
19 | 1177 |
* Checks lock status on the New/Edit Post screen and refresh the lock. |
0 | 1178 |
* |
5 | 1179 |
* @since 3.6.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1180 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1181 |
* @param array $response The Heartbeat response. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1182 |
* @param array $data The $_POST data sent. |
16 | 1183 |
* @param string $screen_id The screen ID. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1184 |
* @return array The Heartbeat response. |
0 | 1185 |
*/ |
1186 |
function wp_refresh_post_lock( $response, $data, $screen_id ) { |
|
1187 |
if ( array_key_exists( 'wp-refresh-post-lock', $data ) ) { |
|
1188 |
$received = $data['wp-refresh-post-lock']; |
|
9 | 1189 |
$send = array(); |
0 | 1190 |
|
16 | 1191 |
$post_id = absint( $received['post_id'] ); |
19 | 1192 |
|
16 | 1193 |
if ( ! $post_id ) { |
0 | 1194 |
return $response; |
9 | 1195 |
} |
0 | 1196 |
|
9 | 1197 |
if ( ! current_user_can( 'edit_post', $post_id ) ) { |
0 | 1198 |
return $response; |
9 | 1199 |
} |
0 | 1200 |
|
16 | 1201 |
$user_id = wp_check_post_lock( $post_id ); |
1202 |
$user = get_userdata( $user_id ); |
|
19 | 1203 |
|
16 | 1204 |
if ( $user ) { |
0 | 1205 |
$error = array( |
19 | 1206 |
'name' => $user->display_name, |
16 | 1207 |
/* translators: %s: User's display name. */ |
9 | 1208 |
'text' => sprintf( __( '%s has taken over and is currently editing.' ), $user->display_name ), |
0 | 1209 |
); |
1210 |
||
16 | 1211 |
if ( get_option( 'show_avatars' ) ) { |
1212 |
$error['avatar_src'] = get_avatar_url( $user->ID, array( 'size' => 64 ) ); |
|
1213 |
$error['avatar_src_2x'] = get_avatar_url( $user->ID, array( 'size' => 128 ) ); |
|
0 | 1214 |
} |
1215 |
||
1216 |
$send['lock_error'] = $error; |
|
1217 |
} else { |
|
16 | 1218 |
$new_lock = wp_set_post_lock( $post_id ); |
19 | 1219 |
|
16 | 1220 |
if ( $new_lock ) { |
0 | 1221 |
$send['new_lock'] = implode( ':', $new_lock ); |
9 | 1222 |
} |
0 | 1223 |
} |
1224 |
||
1225 |
$response['wp-refresh-post-lock'] = $send; |
|
1226 |
} |
|
1227 |
||
1228 |
return $response; |
|
1229 |
} |
|
1230 |
||
1231 |
/** |
|
19 | 1232 |
* Checks nonce expiration on the New/Edit Post screen and refresh if needed. |
0 | 1233 |
* |
5 | 1234 |
* @since 3.6.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1235 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1236 |
* @param array $response The Heartbeat response. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1237 |
* @param array $data The $_POST data sent. |
16 | 1238 |
* @param string $screen_id The screen ID. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1239 |
* @return array The Heartbeat response. |
0 | 1240 |
*/ |
1241 |
function wp_refresh_post_nonces( $response, $data, $screen_id ) { |
|
1242 |
if ( array_key_exists( 'wp-refresh-post-nonces', $data ) ) { |
|
19 | 1243 |
$received = $data['wp-refresh-post-nonces']; |
1244 |
||
0 | 1245 |
$response['wp-refresh-post-nonces'] = array( 'check' => 1 ); |
1246 |
||
16 | 1247 |
$post_id = absint( $received['post_id'] ); |
19 | 1248 |
|
16 | 1249 |
if ( ! $post_id ) { |
0 | 1250 |
return $response; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1251 |
} |
0 | 1252 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1253 |
if ( ! current_user_can( 'edit_post', $post_id ) ) { |
0 | 1254 |
return $response; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1255 |
} |
0 | 1256 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1257 |
$response['wp-refresh-post-nonces'] = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1258 |
'replace' => array( |
9 | 1259 |
'getpermalinknonce' => wp_create_nonce( 'getpermalink' ), |
1260 |
'samplepermalinknonce' => wp_create_nonce( 'samplepermalink' ), |
|
1261 |
'closedpostboxesnonce' => wp_create_nonce( 'closedpostboxes' ), |
|
1262 |
'_ajax_linking_nonce' => wp_create_nonce( 'internal-linking' ), |
|
1263 |
'_wpnonce' => wp_create_nonce( 'update-post_' . $post_id ), |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1264 |
), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1265 |
); |
0 | 1266 |
} |
1267 |
||
1268 |
return $response; |
|
1269 |
} |
|
5 | 1270 |
|
1271 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1272 |
* Refresh nonces used with meta boxes in the block editor. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1273 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1274 |
* @since 6.1.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1275 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1276 |
* @param array $response The Heartbeat response. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1277 |
* @param array $data The $_POST data sent. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1278 |
* @return array The Heartbeat response. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1279 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1280 |
function wp_refresh_metabox_loader_nonces( $response, $data ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1281 |
if ( empty( $data['wp-refresh-metabox-loader-nonces'] ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1282 |
return $response; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1283 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1284 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1285 |
$received = $data['wp-refresh-metabox-loader-nonces']; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1286 |
$post_id = (int) $received['post_id']; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1287 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1288 |
if ( ! $post_id ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1289 |
return $response; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1290 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1291 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1292 |
if ( ! current_user_can( 'edit_post', $post_id ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1293 |
return $response; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1294 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1295 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1296 |
$response['wp-refresh-metabox-loader-nonces'] = array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1297 |
'replace' => array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1298 |
'metabox_loader_nonce' => wp_create_nonce( 'meta-box-loader' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1299 |
'_wpnonce' => wp_create_nonce( 'update-post_' . $post_id ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1300 |
), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1301 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1302 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1303 |
return $response; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1304 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1305 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1306 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1307 |
* Adds the latest Heartbeat and REST API nonce to the Heartbeat response. |
9 | 1308 |
* |
1309 |
* @since 5.0.0 |
|
1310 |
* |
|
16 | 1311 |
* @param array $response The Heartbeat response. |
9 | 1312 |
* @return array The Heartbeat response. |
1313 |
*/ |
|
1314 |
function wp_refresh_heartbeat_nonces( $response ) { |
|
1315 |
// Refresh the Rest API nonce. |
|
1316 |
$response['rest_nonce'] = wp_create_nonce( 'wp_rest' ); |
|
1317 |
||
1318 |
// Refresh the Heartbeat nonce. |
|
1319 |
$response['heartbeat_nonce'] = wp_create_nonce( 'heartbeat-nonce' ); |
|
19 | 1320 |
|
9 | 1321 |
return $response; |
1322 |
} |
|
1323 |
||
1324 |
/** |
|
19 | 1325 |
* Disables suspension of Heartbeat on the Add/Edit Post screens. |
5 | 1326 |
* |
1327 |
* @since 3.8.0 |
|
1328 |
* |
|
19 | 1329 |
* @global string $pagenow The filename of the current screen. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1330 |
* |
5 | 1331 |
* @param array $settings An array of Heartbeat settings. |
1332 |
* @return array Filtered Heartbeat settings. |
|
1333 |
*/ |
|
1334 |
function wp_heartbeat_set_suspension( $settings ) { |
|
1335 |
global $pagenow; |
|
1336 |
||
1337 |
if ( 'post.php' === $pagenow || 'post-new.php' === $pagenow ) { |
|
1338 |
$settings['suspension'] = 'disable'; |
|
1339 |
} |
|
1340 |
||
1341 |
return $settings; |
|
1342 |
} |
|
1343 |
||
1344 |
/** |
|
19 | 1345 |
* Performs autosave with heartbeat. |
5 | 1346 |
* |
1347 |
* @since 3.9.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1348 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1349 |
* @param array $response The Heartbeat response. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1350 |
* @param array $data The $_POST data sent. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1351 |
* @return array The Heartbeat response. |
5 | 1352 |
*/ |
1353 |
function heartbeat_autosave( $response, $data ) { |
|
1354 |
if ( ! empty( $data['wp_autosave'] ) ) { |
|
1355 |
$saved = wp_autosave( $data['wp_autosave'] ); |
|
1356 |
||
1357 |
if ( is_wp_error( $saved ) ) { |
|
9 | 1358 |
$response['wp_autosave'] = array( |
1359 |
'success' => false, |
|
1360 |
'message' => $saved->get_error_message(), |
|
1361 |
); |
|
5 | 1362 |
} elseif ( empty( $saved ) ) { |
9 | 1363 |
$response['wp_autosave'] = array( |
1364 |
'success' => false, |
|
1365 |
'message' => __( 'Error while saving.' ), |
|
1366 |
); |
|
5 | 1367 |
} else { |
18 | 1368 |
/* translators: Draft saved date format, see https://www.php.net/manual/datetime.format.php */ |
5 | 1369 |
$draft_saved_date_format = __( 'g:i:s a' ); |
9 | 1370 |
$response['wp_autosave'] = array( |
1371 |
'success' => true, |
|
16 | 1372 |
/* translators: %s: Date and time. */ |
9 | 1373 |
'message' => sprintf( __( 'Draft saved at %s.' ), date_i18n( $draft_saved_date_format ) ), |
1374 |
); |
|
5 | 1375 |
} |
1376 |
} |
|
1377 |
||
1378 |
return $response; |
|
1379 |
} |
|
1380 |
||
1381 |
/** |
|
19 | 1382 |
* Removes single-use URL parameters and create canonical link based on new URL. |
5 | 1383 |
* |
19 | 1384 |
* Removes specific query string parameters from a URL, create the canonical link, |
5 | 1385 |
* put it in the admin header, and change the current URL to match. |
1386 |
* |
|
1387 |
* @since 4.2.0 |
|
1388 |
*/ |
|
1389 |
function wp_admin_canonical_url() { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1390 |
$removable_query_args = wp_removable_query_args(); |
5 | 1391 |
|
1392 |
if ( empty( $removable_query_args ) ) { |
|
1393 |
return; |
|
1394 |
} |
|
1395 |
||
1396 |
// Ensure we're using an absolute URL. |
|
1397 |
$current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ); |
|
1398 |
$filtered_url = remove_query_arg( $removable_query_args, $current_url ); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1399 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1400 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1401 |
* Filters the admin canonical URL value. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1402 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1403 |
* @since 6.5.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1404 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1405 |
* @param string $filtered_url The admin canonical URL value. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1406 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1407 |
$filtered_url = apply_filters( 'wp_admin_canonical_url', $filtered_url ); |
5 | 1408 |
?> |
1409 |
<link id="wp-admin-canonical" rel="canonical" href="<?php echo esc_url( $filtered_url ); ?>" /> |
|
1410 |
<script> |
|
1411 |
if ( window.history.replaceState ) { |
|
1412 |
window.history.replaceState( null, null, document.getElementById( 'wp-admin-canonical' ).href + window.location.hash ); |
|
1413 |
} |
|
1414 |
</script> |
|
9 | 1415 |
<?php |
5 | 1416 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1417 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1418 |
/** |
19 | 1419 |
* Sends a referrer policy header so referrers are not sent externally from administration screens. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1420 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1421 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1422 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1423 |
function wp_admin_headers() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1424 |
$policy = 'strict-origin-when-cross-origin'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1425 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1426 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1427 |
* Filters the admin referrer policy header value. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1428 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1429 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1430 |
* @since 4.9.5 The default value was changed to 'strict-origin-when-cross-origin'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1431 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1432 |
* @link https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referrer-Policy |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1433 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1434 |
* @param string $policy The admin referrer policy header value. Default 'strict-origin-when-cross-origin'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1435 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1436 |
$policy = apply_filters( 'admin_referrer_policy', $policy ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1437 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1438 |
header( sprintf( 'Referrer-Policy: %s', $policy ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1439 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1440 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1441 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1442 |
* Outputs JS that reloads the page if the user navigated to it with the Back or Forward button. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1443 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1444 |
* Used on the Edit Post and Add New Post screens. Needed to ensure the page is not loaded from browser cache, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1445 |
* so the post title and editor content are the last saved versions. Ideally this script should run first in the head. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1446 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1447 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1448 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1449 |
function wp_page_reload_on_back_button_js() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1450 |
?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1451 |
<script> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1452 |
if ( typeof performance !== 'undefined' && performance.navigation && performance.navigation.type === 2 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1453 |
document.location.reload( true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1454 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1455 |
</script> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1456 |
<?php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1457 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1458 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1459 |
/** |
19 | 1460 |
* Sends a confirmation request email when a change of site admin email address is attempted. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1461 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1462 |
* The new site admin address will not become active until confirmed. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1463 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1464 |
* @since 3.0.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1465 |
* @since 4.9.0 This function was moved from wp-admin/includes/ms.php so it's no longer Multisite specific. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1466 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1467 |
* @param string $old_value The old site admin email address. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1468 |
* @param string $value The proposed new site admin email address. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1469 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1470 |
function update_option_new_admin_email( $old_value, $value ) { |
16 | 1471 |
if ( get_option( 'admin_email' ) === $value || ! is_email( $value ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1472 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1473 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1474 |
|
9 | 1475 |
$hash = md5( $value . time() . wp_rand() ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1476 |
$new_admin_email = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1477 |
'hash' => $hash, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1478 |
'newemail' => $value, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1479 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1480 |
update_option( 'adminhash', $new_admin_email ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1481 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1482 |
$switched_locale = switch_to_user_locale( get_current_user_id() ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1483 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1484 |
/* translators: Do not translate USERNAME, ADMIN_URL, EMAIL, SITENAME, SITEURL: those are placeholders. */ |
9 | 1485 |
$email_text = __( |
1486 |
'Howdy ###USERNAME###, |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1487 |
|
19 | 1488 |
Someone with administrator capabilities recently requested to have the |
1489 |
administration email address changed on this site: |
|
1490 |
###SITEURL### |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1491 |
|
19 | 1492 |
To confirm this change, please click on the following link: |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1493 |
###ADMIN_URL### |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1494 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1495 |
You can safely ignore and delete this email if you do not want to |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1496 |
take this action. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1497 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1498 |
This email has been sent to ###EMAIL### |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1499 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1500 |
Regards, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1501 |
All at ###SITENAME### |
9 | 1502 |
###SITEURL###' |
1503 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1504 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1505 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1506 |
* Filters the text of the email sent when a change of site admin email address is attempted. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1507 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1508 |
* The following strings have a special meaning and will get replaced dynamically: |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1509 |
* - ###USERNAME### The current user's username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1510 |
* - ###ADMIN_URL### The link to click on to confirm the email change. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1511 |
* - ###EMAIL### The proposed new site admin email address. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1512 |
* - ###SITENAME### The name of the site. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1513 |
* - ###SITEURL### The URL to the site. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1514 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1515 |
* @since MU (3.0.0) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1516 |
* @since 4.9.0 This filter is no longer Multisite specific. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1517 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1518 |
* @param string $email_text Text in the email. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1519 |
* @param array $new_admin_email { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1520 |
* Data relating to the new site admin email address. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1521 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1522 |
* @type string $hash The secure hash used in the confirmation link URL. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1523 |
* @type string $newemail The proposed new site admin email address. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1524 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1525 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1526 |
$content = apply_filters( 'new_admin_email_content', $email_text, $new_admin_email ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1527 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1528 |
$current_user = wp_get_current_user(); |
9 | 1529 |
$content = str_replace( '###USERNAME###', $current_user->user_login, $content ); |
1530 |
$content = str_replace( '###ADMIN_URL###', esc_url( self_admin_url( 'options.php?adminhash=' . $hash ) ), $content ); |
|
1531 |
$content = str_replace( '###EMAIL###', $value, $content ); |
|
1532 |
$content = str_replace( '###SITENAME###', wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ), $content ); |
|
1533 |
$content = str_replace( '###SITEURL###', home_url(), $content ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1534 |
|
19 | 1535 |
if ( '' !== get_option( 'blogname' ) ) { |
1536 |
$site_title = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); |
|
1537 |
} else { |
|
1538 |
$site_title = parse_url( home_url(), PHP_URL_HOST ); |
|
1539 |
} |
|
1540 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1541 |
$subject = sprintf( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1542 |
/* translators: New admin email address notification email subject. %s: Site title. */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1543 |
__( '[%s] New Admin Email Address' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1544 |
$site_title |
16 | 1545 |
); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1546 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1547 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1548 |
* Filters the subject of the email sent when a change of site admin email address is attempted. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1549 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1550 |
* @since 6.5.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1551 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1552 |
* @param string $subject Subject of the email. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1553 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1554 |
$subject = apply_filters( 'new_admin_email_subject', $subject ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1555 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1556 |
wp_mail( $value, $subject, $content ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1557 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1558 |
if ( $switched_locale ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1559 |
restore_previous_locale(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1560 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1561 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1562 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1563 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1564 |
* Appends '(Draft)' to draft page titles in the privacy page dropdown |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1565 |
* so that unpublished content is obvious. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1566 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1567 |
* @since 4.9.8 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1568 |
* @access private |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1569 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1570 |
* @param string $title Page title. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1571 |
* @param WP_Post $page Page data object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1572 |
* @return string Page title. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1573 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1574 |
function _wp_privacy_settings_filter_draft_page_titles( $title, $page ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1575 |
if ( 'draft' === $page->post_status && 'privacy' === get_current_screen()->id ) { |
16 | 1576 |
/* translators: %s: Page title. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1577 |
$title = sprintf( __( '%s (Draft)' ), $title ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1578 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1579 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1580 |
return $title; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1581 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1582 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1583 |
/** |
9 | 1584 |
* Checks if the user needs to update PHP. |
1585 |
* |
|
1586 |
* @since 5.1.0 |
|
1587 |
* @since 5.1.1 Added the {@see 'wp_is_php_version_acceptable'} filter. |
|
1588 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1589 |
* @return array|false { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1590 |
* Array of PHP version data. False on failure. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1591 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1592 |
* @type string $recommended_version The PHP version recommended by WordPress. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1593 |
* @type string $minimum_version The minimum required PHP version. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1594 |
* @type bool $is_supported Whether the PHP version is actively supported. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1595 |
* @type bool $is_secure Whether the PHP version receives security updates. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1596 |
* @type bool $is_acceptable Whether the PHP version is still acceptable or warnings |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1597 |
* should be shown and an update recommended. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1598 |
* } |
9 | 1599 |
*/ |
1600 |
function wp_check_php_version() { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1601 |
$version = PHP_VERSION; |
9 | 1602 |
$key = md5( $version ); |
1603 |
||
1604 |
$response = get_site_transient( 'php_check_' . $key ); |
|
19 | 1605 |
|
9 | 1606 |
if ( false === $response ) { |
1607 |
$url = 'http://api.wordpress.org/core/serve-happy/1.0/'; |
|
19 | 1608 |
|
9 | 1609 |
if ( wp_http_supports( array( 'ssl' ) ) ) { |
1610 |
$url = set_url_scheme( $url, 'https' ); |
|
1611 |
} |
|
1612 |
||
1613 |
$url = add_query_arg( 'php_version', $version, $url ); |
|
1614 |
||
1615 |
$response = wp_remote_get( $url ); |
|
1616 |
||
1617 |
if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) { |
|
1618 |
return false; |
|
1619 |
} |
|
1620 |
||
1621 |
$response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
1622 |
||
1623 |
if ( ! is_array( $response ) ) { |
|
1624 |
return false; |
|
1625 |
} |
|
1626 |
||
1627 |
set_site_transient( 'php_check_' . $key, $response, WEEK_IN_SECONDS ); |
|
1628 |
} |
|
1629 |
||
1630 |
if ( isset( $response['is_acceptable'] ) && $response['is_acceptable'] ) { |
|
1631 |
/** |
|
1632 |
* Filters whether the active PHP version is considered acceptable by WordPress. |
|
1633 |
* |
|
1634 |
* Returning false will trigger a PHP version warning to show up in the admin dashboard to administrators. |
|
1635 |
* |
|
1636 |
* This filter is only run if the wordpress.org Serve Happy API considers the PHP version acceptable, ensuring |
|
1637 |
* that this filter can only make this check stricter, but not loosen it. |
|
1638 |
* |
|
1639 |
* @since 5.1.1 |
|
1640 |
* |
|
1641 |
* @param bool $is_acceptable Whether the PHP version is considered acceptable. Default true. |
|
1642 |
* @param string $version PHP version checked. |
|
1643 |
*/ |
|
1644 |
$response['is_acceptable'] = (bool) apply_filters( 'wp_is_php_version_acceptable', true, $version ); |
|
1645 |
} |
|
1646 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1647 |
$response['is_lower_than_future_minimum'] = false; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1648 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1649 |
// The minimum supported PHP version will be updated to 7.4 in the future. Check if the current version is lower. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1650 |
if ( version_compare( $version, '7.4', '<' ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1651 |
$response['is_lower_than_future_minimum'] = true; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1652 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1653 |
// Force showing of warnings. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1654 |
$response['is_acceptable'] = false; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1655 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1656 |
|
9 | 1657 |
return $response; |
1658 |
} |