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