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