changeset 19 | 3d72ae0968f4 |
parent 18 | be944660c56a |
child 21 | 48c4eec2b7e6 |
18:be944660c56a | 19:3d72ae0968f4 |
---|---|
72 } |
72 } |
73 |
73 |
74 $markerdata = explode( "\n", implode( '', file( $filename ) ) ); |
74 $markerdata = explode( "\n", implode( '', file( $filename ) ) ); |
75 |
75 |
76 $state = false; |
76 $state = false; |
77 |
|
77 foreach ( $markerdata as $markerline ) { |
78 foreach ( $markerdata as $markerline ) { |
78 if ( false !== strpos( $markerline, '# END ' . $marker ) ) { |
79 if ( false !== strpos( $markerline, '# END ' . $marker ) ) { |
79 $state = false; |
80 $state = false; |
80 } |
81 } |
82 |
|
81 if ( $state ) { |
83 if ( $state ) { |
82 if ( '#' === substr( $markerline, 0, 1 ) ) { |
84 if ( '#' === substr( $markerline, 0, 1 ) ) { |
83 continue; |
85 continue; |
84 } |
86 } |
87 |
|
85 $result[] = $markerline; |
88 $result[] = $markerline; |
86 } |
89 } |
90 |
|
87 if ( false !== strpos( $markerline, '# BEGIN ' . $marker ) ) { |
91 if ( false !== strpos( $markerline, '# BEGIN ' . $marker ) ) { |
88 $state = true; |
92 $state = true; |
89 } |
93 } |
90 } |
94 } |
91 |
95 |
116 return false; |
120 return false; |
117 } |
121 } |
118 |
122 |
119 // Make sure the file is created with a minimum set of permissions. |
123 // Make sure the file is created with a minimum set of permissions. |
120 $perms = fileperms( $filename ); |
124 $perms = fileperms( $filename ); |
125 |
|
121 if ( $perms ) { |
126 if ( $perms ) { |
122 chmod( $filename, $perms | 0644 ); |
127 chmod( $filename, $perms | 0644 ); |
123 } |
128 } |
124 } elseif ( ! is_writable( $filename ) ) { |
129 } elseif ( ! is_writable( $filename ) ) { |
125 return false; |
130 return false; |
140 ), |
145 ), |
141 $marker |
146 $marker |
142 ); |
147 ); |
143 |
148 |
144 $instructions = explode( "\n", $instructions ); |
149 $instructions = explode( "\n", $instructions ); |
150 |
|
145 foreach ( $instructions as $line => $text ) { |
151 foreach ( $instructions as $line => $text ) { |
146 $instructions[ $line ] = '# ' . $text; |
152 $instructions[ $line ] = '# ' . $text; |
147 } |
153 } |
148 |
154 |
149 /** |
155 /** |
164 |
170 |
165 $start_marker = "# BEGIN {$marker}"; |
171 $start_marker = "# BEGIN {$marker}"; |
166 $end_marker = "# END {$marker}"; |
172 $end_marker = "# END {$marker}"; |
167 |
173 |
168 $fp = fopen( $filename, 'r+' ); |
174 $fp = fopen( $filename, 'r+' ); |
175 |
|
169 if ( ! $fp ) { |
176 if ( ! $fp ) { |
170 return false; |
177 return false; |
171 } |
178 } |
172 |
179 |
173 // Attempt to get a lock. If the filesystem supports locking, this will block until the lock is acquired. |
180 // Attempt to get a lock. If the filesystem supports locking, this will block until the lock is acquired. |
174 flock( $fp, LOCK_EX ); |
181 flock( $fp, LOCK_EX ); |
175 |
182 |
176 $lines = array(); |
183 $lines = array(); |
184 |
|
177 while ( ! feof( $fp ) ) { |
185 while ( ! feof( $fp ) ) { |
178 $lines[] = rtrim( fgets( $fp ), "\r\n" ); |
186 $lines[] = rtrim( fgets( $fp ), "\r\n" ); |
179 } |
187 } |
180 |
188 |
181 // Split out the existing file into the preceding lines, and those that appear after the marker. |
189 // Split out the existing file into the preceding lines, and those that appear after the marker. |
182 $pre_lines = array(); |
190 $pre_lines = array(); |
183 $post_lines = array(); |
191 $post_lines = array(); |
184 $existing_lines = array(); |
192 $existing_lines = array(); |
185 $found_marker = false; |
193 $found_marker = false; |
186 $found_end_marker = false; |
194 $found_end_marker = false; |
195 |
|
187 foreach ( $lines as $line ) { |
196 foreach ( $lines as $line ) { |
188 if ( ! $found_marker && false !== strpos( $line, $start_marker ) ) { |
197 if ( ! $found_marker && false !== strpos( $line, $start_marker ) ) { |
189 $found_marker = true; |
198 $found_marker = true; |
190 continue; |
199 continue; |
191 } elseif ( ! $found_end_marker && false !== strpos( $line, $end_marker ) ) { |
200 } elseif ( ! $found_end_marker && false !== strpos( $line, $end_marker ) ) { |
192 $found_end_marker = true; |
201 $found_end_marker = true; |
193 continue; |
202 continue; |
194 } |
203 } |
204 |
|
195 if ( ! $found_marker ) { |
205 if ( ! $found_marker ) { |
196 $pre_lines[] = $line; |
206 $pre_lines[] = $line; |
197 } elseif ( $found_marker && $found_end_marker ) { |
207 } elseif ( $found_marker && $found_end_marker ) { |
198 $post_lines[] = $line; |
208 $post_lines[] = $line; |
199 } else { |
209 } else { |
222 ); |
232 ); |
223 |
233 |
224 // Write to the start of the file, and truncate it to that length. |
234 // Write to the start of the file, and truncate it to that length. |
225 fseek( $fp, 0 ); |
235 fseek( $fp, 0 ); |
226 $bytes = fwrite( $fp, $new_file_data ); |
236 $bytes = fwrite( $fp, $new_file_data ); |
237 |
|
227 if ( $bytes ) { |
238 if ( $bytes ) { |
228 ftruncate( $fp, ftell( $fp ) ); |
239 ftruncate( $fp, ftell( $fp ) ); |
229 } |
240 } |
241 |
|
230 fflush( $fp ); |
242 fflush( $fp ); |
231 flock( $fp, LOCK_UN ); |
243 flock( $fp, LOCK_UN ); |
232 fclose( $fp ); |
244 fclose( $fp ); |
233 |
245 |
234 return (bool) $bytes; |
246 return (bool) $bytes; |
245 * @global WP_Rewrite $wp_rewrite WordPress rewrite component. |
257 * @global WP_Rewrite $wp_rewrite WordPress rewrite component. |
246 * |
258 * |
247 * @return bool|null True on write success, false on failure. Null in multisite. |
259 * @return bool|null True on write success, false on failure. Null in multisite. |
248 */ |
260 */ |
249 function save_mod_rewrite_rules() { |
261 function save_mod_rewrite_rules() { |
262 global $wp_rewrite; |
|
263 |
|
250 if ( is_multisite() ) { |
264 if ( is_multisite() ) { |
251 return; |
265 return; |
252 } |
266 } |
253 |
|
254 global $wp_rewrite; |
|
255 |
267 |
256 // Ensure get_home_path() is declared. |
268 // Ensure get_home_path() is declared. |
257 require_once ABSPATH . 'wp-admin/includes/file.php'; |
269 require_once ABSPATH . 'wp-admin/includes/file.php'; |
258 |
270 |
259 $home_path = get_home_path(); |
271 $home_path = get_home_path(); |
261 |
273 |
262 /* |
274 /* |
263 * If the file doesn't already exist check for write access to the directory |
275 * 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. |
276 * and whether we have some rules. Else check for write access to the file. |
265 */ |
277 */ |
266 if ( ( ! file_exists( $htaccess_file ) && is_writable( $home_path ) && $wp_rewrite->using_mod_rewrite_permalinks() ) || is_writable( $htaccess_file ) ) { |
278 if ( ! file_exists( $htaccess_file ) && is_writable( $home_path ) && $wp_rewrite->using_mod_rewrite_permalinks() |
279 || is_writable( $htaccess_file ) |
|
280 ) { |
|
267 if ( got_mod_rewrite() ) { |
281 if ( got_mod_rewrite() ) { |
268 $rules = explode( "\n", $wp_rewrite->mod_rewrite_rules() ); |
282 $rules = explode( "\n", $wp_rewrite->mod_rewrite_rules() ); |
283 |
|
269 return insert_with_markers( $htaccess_file, 'WordPress', $rules ); |
284 return insert_with_markers( $htaccess_file, 'WordPress', $rules ); |
270 } |
285 } |
271 } |
286 } |
272 |
287 |
273 return false; |
288 return false; |
282 * @global WP_Rewrite $wp_rewrite WordPress rewrite component. |
297 * @global WP_Rewrite $wp_rewrite WordPress rewrite component. |
283 * |
298 * |
284 * @return bool|null True on write success, false on failure. Null in multisite. |
299 * @return bool|null True on write success, false on failure. Null in multisite. |
285 */ |
300 */ |
286 function iis7_save_url_rewrite_rules() { |
301 function iis7_save_url_rewrite_rules() { |
302 global $wp_rewrite; |
|
303 |
|
287 if ( is_multisite() ) { |
304 if ( is_multisite() ) { |
288 return; |
305 return; |
289 } |
306 } |
290 |
307 |
291 global $wp_rewrite; |
|
292 |
|
293 // Ensure get_home_path() is declared. |
308 // Ensure get_home_path() is declared. |
294 require_once ABSPATH . 'wp-admin/includes/file.php'; |
309 require_once ABSPATH . 'wp-admin/includes/file.php'; |
295 |
310 |
296 $home_path = get_home_path(); |
311 $home_path = get_home_path(); |
297 $web_config_file = $home_path . 'web.config'; |
312 $web_config_file = $home_path . 'web.config'; |
298 |
313 |
299 // Using win_is_writable() instead of is_writable() because of a bug in Windows PHP. |
314 // Using win_is_writable() instead of is_writable() because of a bug in Windows PHP. |
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 ) ) ) { |
315 if ( iis7_supports_permalinks() |
316 && ( ! file_exists( $web_config_file ) && win_is_writable( $home_path ) && $wp_rewrite->using_mod_rewrite_permalinks() |
|
317 || win_is_writable( $web_config_file ) ) |
|
318 ) { |
|
301 $rule = $wp_rewrite->iis7_url_rewrite_rules( false ); |
319 $rule = $wp_rewrite->iis7_url_rewrite_rules( false ); |
320 |
|
302 if ( ! empty( $rule ) ) { |
321 if ( ! empty( $rule ) ) { |
303 return iis7_add_rewrite_rule( $web_config_file, $rule ); |
322 return iis7_add_rewrite_rule( $web_config_file, $rule ); |
304 } else { |
323 } else { |
305 return iis7_delete_rewrite_rule( $web_config_file ); |
324 return iis7_delete_rewrite_rule( $web_config_file ); |
306 } |
325 } |
307 } |
326 } |
327 |
|
308 return false; |
328 return false; |
309 } |
329 } |
310 |
330 |
311 /** |
331 /** |
312 * Update the "recently-edited" file for the plugin or theme editor. |
332 * Updates the "recently-edited" file for the plugin or theme file editor. |
313 * |
333 * |
314 * @since 1.5.0 |
334 * @since 1.5.0 |
315 * |
335 * |
316 * @param string $file |
336 * @param string $file |
317 */ |
337 */ |
318 function update_recently_edited( $file ) { |
338 function update_recently_edited( $file ) { |
319 $oldfiles = (array) get_option( 'recently_edited' ); |
339 $oldfiles = (array) get_option( 'recently_edited' ); |
340 |
|
320 if ( $oldfiles ) { |
341 if ( $oldfiles ) { |
321 $oldfiles = array_reverse( $oldfiles ); |
342 $oldfiles = array_reverse( $oldfiles ); |
322 $oldfiles[] = $file; |
343 $oldfiles[] = $file; |
323 $oldfiles = array_reverse( $oldfiles ); |
344 $oldfiles = array_reverse( $oldfiles ); |
324 $oldfiles = array_unique( $oldfiles ); |
345 $oldfiles = array_unique( $oldfiles ); |
346 |
|
325 if ( 5 < count( $oldfiles ) ) { |
347 if ( 5 < count( $oldfiles ) ) { |
326 array_pop( $oldfiles ); |
348 array_pop( $oldfiles ); |
327 } |
349 } |
328 } else { |
350 } else { |
329 $oldfiles[] = $file; |
351 $oldfiles[] = $file; |
330 } |
352 } |
353 |
|
331 update_option( 'recently_edited', $oldfiles ); |
354 update_option( 'recently_edited', $oldfiles ); |
332 } |
355 } |
333 |
356 |
334 /** |
357 /** |
335 * Makes a tree structure for the theme editor's file list. |
358 * Makes a tree structure for the theme file editor's file list. |
336 * |
359 * |
337 * @since 4.9.0 |
360 * @since 4.9.0 |
338 * @access private |
361 * @access private |
339 * |
362 * |
340 * @param array $allowed_files List of theme file paths. |
363 * @param array $allowed_files List of theme file paths. |
341 * @return array Tree structure for listing theme files. |
364 * @return array Tree structure for listing theme files. |
342 */ |
365 */ |
343 function wp_make_theme_file_tree( $allowed_files ) { |
366 function wp_make_theme_file_tree( $allowed_files ) { |
344 $tree_list = array(); |
367 $tree_list = array(); |
368 |
|
345 foreach ( $allowed_files as $file_name => $absolute_filename ) { |
369 foreach ( $allowed_files as $file_name => $absolute_filename ) { |
346 $list = explode( '/', $file_name ); |
370 $list = explode( '/', $file_name ); |
347 $last_dir = &$tree_list; |
371 $last_dir = &$tree_list; |
372 |
|
348 foreach ( $list as $dir ) { |
373 foreach ( $list as $dir ) { |
349 $last_dir =& $last_dir[ $dir ]; |
374 $last_dir =& $last_dir[ $dir ]; |
350 } |
375 } |
376 |
|
351 $last_dir = $file_name; |
377 $last_dir = $file_name; |
352 } |
378 } |
379 |
|
353 return $tree_list; |
380 return $tree_list; |
354 } |
381 } |
355 |
382 |
356 /** |
383 /** |
357 * Outputs the formatted file list for the theme editor. |
384 * Outputs the formatted file list for the theme file editor. |
358 * |
385 * |
359 * @since 4.9.0 |
386 * @since 4.9.0 |
360 * @access private |
387 * @access private |
361 * |
388 * |
362 * @global string $relative_file Name of the file being edited relative to the |
389 * @global string $relative_file Name of the file being edited relative to the |
372 global $relative_file, $stylesheet; |
399 global $relative_file, $stylesheet; |
373 |
400 |
374 if ( is_array( $tree ) ) { |
401 if ( is_array( $tree ) ) { |
375 $index = 0; |
402 $index = 0; |
376 $size = count( $tree ); |
403 $size = count( $tree ); |
404 |
|
377 foreach ( $tree as $label => $theme_file ) : |
405 foreach ( $tree as $label => $theme_file ) : |
378 $index++; |
406 $index++; |
407 |
|
379 if ( ! is_array( $theme_file ) ) { |
408 if ( ! is_array( $theme_file ) ) { |
380 wp_print_theme_file_tree( $theme_file, $level, $index, $size ); |
409 wp_print_theme_file_tree( $theme_file, $level, $index, $size ); |
381 continue; |
410 continue; |
382 } |
411 } |
383 ?> |
412 ?> |
406 aria-level="<?php echo esc_attr( $level ); ?>" |
435 aria-level="<?php echo esc_attr( $level ); ?>" |
407 aria-setsize="<?php echo esc_attr( $size ); ?>" |
436 aria-setsize="<?php echo esc_attr( $size ); ?>" |
408 aria-posinset="<?php echo esc_attr( $index ); ?>"> |
437 aria-posinset="<?php echo esc_attr( $index ); ?>"> |
409 <?php |
438 <?php |
410 $file_description = esc_html( get_file_description( $filename ) ); |
439 $file_description = esc_html( get_file_description( $filename ) ); |
440 |
|
411 if ( $file_description !== $filename && wp_basename( $filename ) !== $file_description ) { |
441 if ( $file_description !== $filename && wp_basename( $filename ) !== $file_description ) { |
412 $file_description .= '<br /><span class="nonessential">(' . esc_html( $filename ) . ')</span>'; |
442 $file_description .= '<br /><span class="nonessential">(' . esc_html( $filename ) . ')</span>'; |
413 } |
443 } |
414 |
444 |
415 if ( $relative_file === $filename ) { |
445 if ( $relative_file === $filename ) { |
423 <?php |
453 <?php |
424 } |
454 } |
425 } |
455 } |
426 |
456 |
427 /** |
457 /** |
428 * Makes a tree structure for the plugin editor's file list. |
458 * Makes a tree structure for the plugin file editor's file list. |
429 * |
459 * |
430 * @since 4.9.0 |
460 * @since 4.9.0 |
431 * @access private |
461 * @access private |
432 * |
462 * |
433 * @param array $plugin_editable_files List of plugin file paths. |
463 * @param array $plugin_editable_files List of plugin file paths. |
434 * @return array Tree structure for listing plugin files. |
464 * @return array Tree structure for listing plugin files. |
435 */ |
465 */ |
436 function wp_make_plugin_file_tree( $plugin_editable_files ) { |
466 function wp_make_plugin_file_tree( $plugin_editable_files ) { |
437 $tree_list = array(); |
467 $tree_list = array(); |
468 |
|
438 foreach ( $plugin_editable_files as $plugin_file ) { |
469 foreach ( $plugin_editable_files as $plugin_file ) { |
439 $list = explode( '/', preg_replace( '#^.+?/#', '', $plugin_file ) ); |
470 $list = explode( '/', preg_replace( '#^.+?/#', '', $plugin_file ) ); |
440 $last_dir = &$tree_list; |
471 $last_dir = &$tree_list; |
472 |
|
441 foreach ( $list as $dir ) { |
473 foreach ( $list as $dir ) { |
442 $last_dir =& $last_dir[ $dir ]; |
474 $last_dir =& $last_dir[ $dir ]; |
443 } |
475 } |
476 |
|
444 $last_dir = $plugin_file; |
477 $last_dir = $plugin_file; |
445 } |
478 } |
479 |
|
446 return $tree_list; |
480 return $tree_list; |
447 } |
481 } |
448 |
482 |
449 /** |
483 /** |
450 * Outputs the formatted file list for the plugin editor. |
484 * Outputs the formatted file list for the plugin file editor. |
451 * |
485 * |
452 * @since 4.9.0 |
486 * @since 4.9.0 |
453 * @access private |
487 * @access private |
454 * |
488 * |
455 * @param array|string $tree List of file/folder paths, or filename. |
489 * @param array|string $tree List of file/folder paths, or filename. |
458 * @param int $size The aria-setsize for the current iteration. |
492 * @param int $size The aria-setsize for the current iteration. |
459 * @param int $index The aria-posinset for the current iteration. |
493 * @param int $index The aria-posinset for the current iteration. |
460 */ |
494 */ |
461 function wp_print_plugin_file_tree( $tree, $label = '', $level = 2, $size = 1, $index = 1 ) { |
495 function wp_print_plugin_file_tree( $tree, $label = '', $level = 2, $size = 1, $index = 1 ) { |
462 global $file, $plugin; |
496 global $file, $plugin; |
497 |
|
463 if ( is_array( $tree ) ) { |
498 if ( is_array( $tree ) ) { |
464 $index = 0; |
499 $index = 0; |
465 $size = count( $tree ); |
500 $size = count( $tree ); |
501 |
|
466 foreach ( $tree as $label => $plugin_file ) : |
502 foreach ( $tree as $label => $plugin_file ) : |
467 $index++; |
503 $index++; |
504 |
|
468 if ( ! is_array( $plugin_file ) ) { |
505 if ( ! is_array( $plugin_file ) ) { |
469 wp_print_plugin_file_tree( $plugin_file, $label, $level, $index, $size ); |
506 wp_print_plugin_file_tree( $plugin_file, $label, $level, $index, $size ); |
470 continue; |
507 continue; |
471 } |
508 } |
472 ?> |
509 ?> |
527 } |
564 } |
528 } |
565 } |
529 |
566 |
530 |
567 |
531 /** |
568 /** |
532 * Resets global variables based on $_GET and $_POST |
569 * Resets global variables based on $_GET and $_POST. |
533 * |
570 * |
534 * This function resets global variables based on the names passed |
571 * 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 '' |
572 * in the $vars array to the value of $_POST[$var] or $_GET[$var] or '' |
536 * if neither is defined. |
573 * if neither is defined. |
537 * |
574 * |
566 $message = $message->get_error_message() . ': ' . $message->get_error_data(); |
603 $message = $message->get_error_message() . ': ' . $message->get_error_data(); |
567 } else { |
604 } else { |
568 $message = $message->get_error_message(); |
605 $message = $message->get_error_message(); |
569 } |
606 } |
570 } |
607 } |
608 |
|
571 echo "<p>$message</p>\n"; |
609 echo "<p>$message</p>\n"; |
572 wp_ob_end_flush_all(); |
610 wp_ob_end_flush_all(); |
573 flush(); |
611 flush(); |
574 } |
612 } |
575 |
613 |
590 |
628 |
591 $tokens = token_get_all( $content ); |
629 $tokens = token_get_all( $content ); |
592 $count = count( $tokens ); |
630 $count = count( $tokens ); |
593 $functions = array(); |
631 $functions = array(); |
594 $ignore_functions = array(); |
632 $ignore_functions = array(); |
633 |
|
595 for ( $t = 0; $t < $count - 2; $t++ ) { |
634 for ( $t = 0; $t < $count - 2; $t++ ) { |
596 if ( ! is_array( $tokens[ $t ] ) ) { |
635 if ( ! is_array( $tokens[ $t ] ) ) { |
597 continue; |
636 continue; |
598 } |
637 } |
599 |
638 |
600 if ( T_STRING == $tokens[ $t ][0] && ( '(' === $tokens[ $t + 1 ] || '(' === $tokens[ $t + 2 ] ) ) { |
639 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. |
640 // 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 ) ) |
641 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] ) |
642 || ( isset( $tokens[ $t - 2 ][0] ) && T_OBJECT_OPERATOR === $tokens[ $t - 1 ][0] ) |
604 ) { |
643 ) { |
605 $ignore_functions[] = $tokens[ $t ][1]; |
644 $ignore_functions[] = $tokens[ $t ][1]; |
606 } |
645 } |
646 |
|
607 // Add this to our stack of unique references. |
647 // Add this to our stack of unique references. |
608 $functions[] = $tokens[ $t ][1]; |
648 $functions[] = $tokens[ $t ][1]; |
609 } |
649 } |
610 } |
650 } |
611 |
651 |
622 $ignore_functions = apply_filters( 'documentation_ignore_functions', $ignore_functions ); |
662 $ignore_functions = apply_filters( 'documentation_ignore_functions', $ignore_functions ); |
623 |
663 |
624 $ignore_functions = array_unique( $ignore_functions ); |
664 $ignore_functions = array_unique( $ignore_functions ); |
625 |
665 |
626 $out = array(); |
666 $out = array(); |
667 |
|
627 foreach ( $functions as $function ) { |
668 foreach ( $functions as $function ) { |
628 if ( in_array( $function, $ignore_functions, true ) ) { |
669 if ( in_array( $function, $ignore_functions, true ) ) { |
629 continue; |
670 continue; |
630 } |
671 } |
672 |
|
631 $out[] = $function; |
673 $out[] = $function; |
632 } |
674 } |
633 |
675 |
634 return $out; |
676 return $out; |
635 } |
677 } |
638 * Saves option for number of rows when listing posts, pages, comments, etc. |
680 * Saves option for number of rows when listing posts, pages, comments, etc. |
639 * |
681 * |
640 * @since 2.8.0 |
682 * @since 2.8.0 |
641 */ |
683 */ |
642 function set_screen_options() { |
684 function set_screen_options() { |
643 |
685 if ( ! isset( $_POST['wp_screen_options'] ) || ! is_array( $_POST['wp_screen_options'] ) ) { |
644 if ( isset( $_POST['wp_screen_options'] ) && is_array( $_POST['wp_screen_options'] ) ) { |
686 return; |
645 check_admin_referer( 'screen-options-nonce', 'screenoptionnonce' ); |
687 } |
646 |
688 |
647 $user = wp_get_current_user(); |
689 check_admin_referer( 'screen-options-nonce', 'screenoptionnonce' ); |
648 if ( ! $user ) { |
690 |
649 return; |
691 $user = wp_get_current_user(); |
650 } |
692 |
651 $option = $_POST['wp_screen_options']['option']; |
693 if ( ! $user ) { |
652 $value = $_POST['wp_screen_options']['value']; |
694 return; |
653 |
695 } |
654 if ( sanitize_key( $option ) != $option ) { |
696 |
655 return; |
697 $option = $_POST['wp_screen_options']['option']; |
656 } |
698 $value = $_POST['wp_screen_options']['value']; |
657 |
699 |
658 $map_option = $option; |
700 if ( sanitize_key( $option ) !== $option ) { |
659 $type = str_replace( 'edit_', '', $map_option ); |
701 return; |
660 $type = str_replace( '_per_page', '', $type ); |
702 } |
661 if ( in_array( $type, get_taxonomies(), true ) ) { |
703 |
662 $map_option = 'edit_tags_per_page'; |
704 $map_option = $option; |
663 } elseif ( in_array( $type, get_post_types(), true ) ) { |
705 $type = str_replace( 'edit_', '', $map_option ); |
664 $map_option = 'edit_per_page'; |
706 $type = str_replace( '_per_page', '', $type ); |
665 } else { |
707 |
666 $option = str_replace( '-', '_', $option ); |
708 if ( in_array( $type, get_taxonomies(), true ) ) { |
667 } |
709 $map_option = 'edit_tags_per_page'; |
668 |
710 } elseif ( in_array( $type, get_post_types(), true ) ) { |
669 switch ( $map_option ) { |
711 $map_option = 'edit_per_page'; |
670 case 'edit_per_page': |
712 } else { |
671 case 'users_per_page': |
713 $option = str_replace( '-', '_', $option ); |
672 case 'edit_comments_per_page': |
714 } |
673 case 'upload_per_page': |
715 |
674 case 'edit_tags_per_page': |
716 switch ( $map_option ) { |
675 case 'plugins_per_page': |
717 case 'edit_per_page': |
676 case 'export_personal_data_requests_per_page': |
718 case 'users_per_page': |
677 case 'remove_personal_data_requests_per_page': |
719 case 'edit_comments_per_page': |
678 // Network admin. |
720 case 'upload_per_page': |
679 case 'sites_network_per_page': |
721 case 'edit_tags_per_page': |
680 case 'users_network_per_page': |
722 case 'plugins_per_page': |
681 case 'site_users_network_per_page': |
723 case 'export_personal_data_requests_per_page': |
682 case 'plugins_network_per_page': |
724 case 'remove_personal_data_requests_per_page': |
683 case 'themes_network_per_page': |
725 // Network admin. |
684 case 'site_themes_network_per_page': |
726 case 'sites_network_per_page': |
685 $value = (int) $value; |
727 case 'users_network_per_page': |
686 if ( $value < 1 || $value > 999 ) { |
728 case 'site_users_network_per_page': |
687 return; |
729 case 'plugins_network_per_page': |
688 } |
730 case 'themes_network_per_page': |
689 break; |
731 case 'site_themes_network_per_page': |
690 default: |
732 $value = (int) $value; |
691 $screen_option = false; |
733 |
692 |
734 if ( $value < 1 || $value > 999 ) { |
693 if ( '_page' === substr( $option, -5 ) || 'layout_columns' === $option ) { |
735 return; |
694 /** |
736 } |
695 * Filters a screen option value before it is set. |
737 |
696 * |
738 break; |
697 * The filter can also be used to modify non-standard [items]_per_page |
739 |
698 * settings. See the parent function for a full list of standard options. |
740 default: |
699 * |
741 $screen_option = false; |
700 * Returning false from the filter will skip saving the current option. |
742 |
701 * |
743 if ( '_page' === substr( $option, -5 ) || 'layout_columns' === $option ) { |
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 |
|
716 /** |
744 /** |
717 * Filters a screen option value before it is set. |
745 * Filters a screen option value before it is set. |
718 * |
746 * |
719 * The dynamic portion of the hook, `$option`, refers to the option name. |
747 * The filter can also be used to modify non-standard [items]_per_page |
748 * settings. See the parent function for a full list of standard options. |
|
720 * |
749 * |
721 * Returning false from the filter will skip saving the current option. |
750 * Returning false from the filter will skip saving the current option. |
722 * |
751 * |
723 * @since 5.4.2 |
752 * @since 2.8.0 |
753 * @since 5.4.2 Only applied to options ending with '_page', |
|
754 * or the 'layout_columns' option. |
|
724 * |
755 * |
725 * @see set_screen_options() |
756 * @see set_screen_options() |
726 * |
757 * |
727 * @param mixed $screen_option The value to save instead of the option value. |
758 * @param mixed $screen_option The value to save instead of the option value. |
728 * Default false (to skip saving the current option). |
759 * Default false (to skip saving the current option). |
729 * @param string $option The option name. |
760 * @param string $option The option name. |
730 * @param int $value The option value. |
761 * @param int $value The option value. |
731 */ |
762 */ |
732 $value = apply_filters( "set_screen_option_{$option}", $screen_option, $option, $value ); |
763 $screen_option = apply_filters( 'set-screen-option', $screen_option, $option, $value ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
733 |
764 } |
734 if ( false === $value ) { |
765 |
735 return; |
766 /** |
736 } |
767 * Filters a screen option value before it is set. |
737 break; |
768 * |
738 } |
769 * The dynamic portion of the hook name, `$option`, refers to the option name. |
739 |
770 * |
740 update_user_meta( $user->ID, $option, $value ); |
771 * Returning false from the filter will skip saving the current option. |
741 |
772 * |
742 $url = remove_query_arg( array( 'pagenum', 'apage', 'paged' ), wp_get_referer() ); |
773 * @since 5.4.2 |
743 if ( isset( $_POST['mode'] ) ) { |
774 * |
744 $url = add_query_arg( array( 'mode' => $_POST['mode'] ), $url ); |
775 * @see set_screen_options() |
745 } |
776 * |
746 |
777 * @param mixed $screen_option The value to save instead of the option value. |
747 wp_safe_redirect( $url ); |
778 * Default false (to skip saving the current option). |
748 exit; |
779 * @param string $option The option name. |
749 } |
780 * @param int $value The option value. |
750 } |
781 */ |
751 |
782 $value = apply_filters( "set_screen_option_{$option}", $screen_option, $option, $value ); |
752 /** |
783 |
753 * Check if rewrite rule for WordPress already exists in the IIS 7+ configuration file |
784 if ( false === $value ) { |
785 return; |
|
786 } |
|
787 |
|
788 break; |
|
789 } |
|
790 |
|
791 update_user_meta( $user->ID, $option, $value ); |
|
792 |
|
793 $url = remove_query_arg( array( 'pagenum', 'apage', 'paged' ), wp_get_referer() ); |
|
794 |
|
795 if ( isset( $_POST['mode'] ) ) { |
|
796 $url = add_query_arg( array( 'mode' => $_POST['mode'] ), $url ); |
|
797 } |
|
798 |
|
799 wp_safe_redirect( $url ); |
|
800 exit; |
|
801 } |
|
802 |
|
803 /** |
|
804 * Checks if rewrite rule for WordPress already exists in the IIS 7+ configuration file. |
|
754 * |
805 * |
755 * @since 2.8.0 |
806 * @since 2.8.0 |
756 * |
807 * |
808 * @param string $filename The file path to the configuration file. |
|
757 * @return bool |
809 * @return bool |
758 * @param string $filename The file path to the configuration file |
|
759 */ |
810 */ |
760 function iis7_rewrite_rule_exists( $filename ) { |
811 function iis7_rewrite_rule_exists( $filename ) { |
761 if ( ! file_exists( $filename ) ) { |
812 if ( ! file_exists( $filename ) ) { |
762 return false; |
813 return false; |
763 } |
814 } |
815 |
|
764 if ( ! class_exists( 'DOMDocument', false ) ) { |
816 if ( ! class_exists( 'DOMDocument', false ) ) { |
765 return false; |
817 return false; |
766 } |
818 } |
767 |
819 |
768 $doc = new DOMDocument(); |
820 $doc = new DOMDocument(); |
821 |
|
769 if ( $doc->load( $filename ) === false ) { |
822 if ( $doc->load( $filename ) === false ) { |
770 return false; |
823 return false; |
771 } |
824 } |
825 |
|
772 $xpath = new DOMXPath( $doc ); |
826 $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\')]' ); |
827 $rules = $xpath->query( '/configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'wordpress\')] | /configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'WordPress\')]' ); |
774 if ( 0 == $rules->length ) { |
828 |
829 if ( 0 === $rules->length ) { |
|
775 return false; |
830 return false; |
776 } else { |
831 } |
777 return true; |
832 |
778 } |
833 return true; |
779 } |
834 } |
780 |
835 |
781 /** |
836 /** |
782 * Delete WordPress rewrite rule from web.config file if it exists there |
837 * Deletes WordPress rewrite rule from web.config file if it exists there. |
783 * |
838 * |
784 * @since 2.8.0 |
839 * @since 2.8.0 |
785 * |
840 * |
786 * @param string $filename Name of the configuration file |
841 * @param string $filename Name of the configuration file. |
787 * @return bool |
842 * @return bool |
788 */ |
843 */ |
789 function iis7_delete_rewrite_rule( $filename ) { |
844 function iis7_delete_rewrite_rule( $filename ) { |
790 // If configuration file does not exist then rules also do not exist, so there is nothing to delete. |
845 // If configuration file does not exist then rules also do not exist, so there is nothing to delete. |
791 if ( ! file_exists( $filename ) ) { |
846 if ( ! file_exists( $filename ) ) { |
800 $doc->preserveWhiteSpace = false; |
855 $doc->preserveWhiteSpace = false; |
801 |
856 |
802 if ( $doc->load( $filename ) === false ) { |
857 if ( $doc->load( $filename ) === false ) { |
803 return false; |
858 return false; |
804 } |
859 } |
860 |
|
805 $xpath = new DOMXPath( $doc ); |
861 $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\')]' ); |
862 $rules = $xpath->query( '/configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'wordpress\')] | /configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'WordPress\')]' ); |
863 |
|
807 if ( $rules->length > 0 ) { |
864 if ( $rules->length > 0 ) { |
808 $child = $rules->item( 0 ); |
865 $child = $rules->item( 0 ); |
809 $parent = $child->parentNode; |
866 $parent = $child->parentNode; |
810 $parent->removeChild( $child ); |
867 $parent->removeChild( $child ); |
811 $doc->formatOutput = true; |
868 $doc->formatOutput = true; |
812 saveDomDocument( $doc, $filename ); |
869 saveDomDocument( $doc, $filename ); |
813 } |
870 } |
871 |
|
814 return true; |
872 return true; |
815 } |
873 } |
816 |
874 |
817 /** |
875 /** |
818 * Add WordPress rewrite rule to the IIS 7+ configuration file. |
876 * Adds WordPress rewrite rule to the IIS 7+ configuration file. |
819 * |
877 * |
820 * @since 2.8.0 |
878 * @since 2.8.0 |
821 * |
879 * |
822 * @param string $filename The file path to the configuration file |
880 * @param string $filename The file path to the configuration file. |
823 * @param string $rewrite_rule The XML fragment with URL Rewrite rule |
881 * @param string $rewrite_rule The XML fragment with URL Rewrite rule. |
824 * @return bool |
882 * @return bool |
825 */ |
883 */ |
826 function iis7_add_rewrite_rule( $filename, $rewrite_rule ) { |
884 function iis7_add_rewrite_rule( $filename, $rewrite_rule ) { |
827 if ( ! class_exists( 'DOMDocument', false ) ) { |
885 if ( ! class_exists( 'DOMDocument', false ) ) { |
828 return false; |
886 return false; |
844 |
902 |
845 $xpath = new DOMXPath( $doc ); |
903 $xpath = new DOMXPath( $doc ); |
846 |
904 |
847 // First check if the rule already exists as in that case there is no need to re-add it. |
905 // First check if the rule already exists as in that case there is no need to re-add it. |
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\')]' ); |
906 $wordpress_rules = $xpath->query( '/configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'wordpress\')] | /configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'WordPress\')]' ); |
907 |
|
849 if ( $wordpress_rules->length > 0 ) { |
908 if ( $wordpress_rules->length > 0 ) { |
850 return true; |
909 return true; |
851 } |
910 } |
852 |
911 |
853 // Check the XPath to the rewrite rule and create XML nodes if they do not exist. |
912 // Check the XPath to the rewrite rule and create XML nodes if they do not exist. |
854 $xmlnodes = $xpath->query( '/configuration/system.webServer/rewrite/rules' ); |
913 $xml_nodes = $xpath->query( '/configuration/system.webServer/rewrite/rules' ); |
855 if ( $xmlnodes->length > 0 ) { |
914 |
856 $rules_node = $xmlnodes->item( 0 ); |
915 if ( $xml_nodes->length > 0 ) { |
916 $rules_node = $xml_nodes->item( 0 ); |
|
857 } else { |
917 } else { |
858 $rules_node = $doc->createElement( 'rules' ); |
918 $rules_node = $doc->createElement( 'rules' ); |
859 |
919 |
860 $xmlnodes = $xpath->query( '/configuration/system.webServer/rewrite' ); |
920 $xml_nodes = $xpath->query( '/configuration/system.webServer/rewrite' ); |
861 if ( $xmlnodes->length > 0 ) { |
921 |
862 $rewrite_node = $xmlnodes->item( 0 ); |
922 if ( $xml_nodes->length > 0 ) { |
923 $rewrite_node = $xml_nodes->item( 0 ); |
|
863 $rewrite_node->appendChild( $rules_node ); |
924 $rewrite_node->appendChild( $rules_node ); |
864 } else { |
925 } else { |
865 $rewrite_node = $doc->createElement( 'rewrite' ); |
926 $rewrite_node = $doc->createElement( 'rewrite' ); |
866 $rewrite_node->appendChild( $rules_node ); |
927 $rewrite_node->appendChild( $rules_node ); |
867 |
928 |
868 $xmlnodes = $xpath->query( '/configuration/system.webServer' ); |
929 $xml_nodes = $xpath->query( '/configuration/system.webServer' ); |
869 if ( $xmlnodes->length > 0 ) { |
930 |
870 $system_webServer_node = $xmlnodes->item( 0 ); |
931 if ( $xml_nodes->length > 0 ) { |
871 $system_webServer_node->appendChild( $rewrite_node ); |
932 $system_web_server_node = $xml_nodes->item( 0 ); |
933 $system_web_server_node->appendChild( $rewrite_node ); |
|
872 } else { |
934 } else { |
873 $system_webServer_node = $doc->createElement( 'system.webServer' ); |
935 $system_web_server_node = $doc->createElement( 'system.webServer' ); |
874 $system_webServer_node->appendChild( $rewrite_node ); |
936 $system_web_server_node->appendChild( $rewrite_node ); |
875 |
937 |
876 $xmlnodes = $xpath->query( '/configuration' ); |
938 $xml_nodes = $xpath->query( '/configuration' ); |
877 if ( $xmlnodes->length > 0 ) { |
939 |
878 $config_node = $xmlnodes->item( 0 ); |
940 if ( $xml_nodes->length > 0 ) { |
879 $config_node->appendChild( $system_webServer_node ); |
941 $config_node = $xml_nodes->item( 0 ); |
942 $config_node->appendChild( $system_web_server_node ); |
|
880 } else { |
943 } else { |
881 $config_node = $doc->createElement( 'configuration' ); |
944 $config_node = $doc->createElement( 'configuration' ); |
882 $doc->appendChild( $config_node ); |
945 $doc->appendChild( $config_node ); |
883 $config_node->appendChild( $system_webServer_node ); |
946 $config_node->appendChild( $system_web_server_node ); |
884 } |
947 } |
885 } |
948 } |
886 } |
949 } |
887 } |
950 } |
888 |
951 |
896 |
959 |
897 return true; |
960 return true; |
898 } |
961 } |
899 |
962 |
900 /** |
963 /** |
901 * Saves the XML document into a file |
964 * Saves the XML document into a file. |
902 * |
965 * |
903 * @since 2.8.0 |
966 * @since 2.8.0 |
904 * |
967 * |
905 * @param DOMDocument $doc |
968 * @param DOMDocument $doc |
906 * @param string $filename |
969 * @param string $filename |
907 */ |
970 */ |
908 function saveDomDocument( $doc, $filename ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid |
971 function saveDomDocument( $doc, $filename ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid |
909 $config = $doc->saveXML(); |
972 $config = $doc->saveXML(); |
910 $config = preg_replace( "/([^\r])\n/", "$1\r\n", $config ); |
973 $config = preg_replace( "/([^\r])\n/", "$1\r\n", $config ); |
911 $fp = fopen( $filename, 'w' ); |
974 |
975 $fp = fopen( $filename, 'w' ); |
|
912 fwrite( $fp, $config ); |
976 fwrite( $fp, $config ); |
913 fclose( $fp ); |
977 fclose( $fp ); |
914 } |
978 } |
915 |
979 |
916 /** |
980 /** |
917 * Display the default admin color scheme picker (Used in user-edit.php) |
981 * Displays the default admin color scheme picker (Used in user-edit.php). |
918 * |
982 * |
919 * @since 3.0.0 |
983 * @since 3.0.0 |
920 * |
984 * |
921 * @global array $_wp_admin_css_colors |
985 * @global array $_wp_admin_css_colors |
922 * |
986 * |
944 $current_color = get_user_option( 'admin_color', $user_id ); |
1008 $current_color = get_user_option( 'admin_color', $user_id ); |
945 |
1009 |
946 if ( empty( $current_color ) || ! isset( $_wp_admin_css_colors[ $current_color ] ) ) { |
1010 if ( empty( $current_color ) || ! isset( $_wp_admin_css_colors[ $current_color ] ) ) { |
947 $current_color = 'fresh'; |
1011 $current_color = 'fresh'; |
948 } |
1012 } |
949 |
|
950 ?> |
1013 ?> |
951 <fieldset id="color-picker" class="scheme-list"> |
1014 <fieldset id="color-picker" class="scheme-list"> |
952 <legend class="screen-reader-text"><span><?php _e( 'Admin Color Scheme' ); ?></span></legend> |
1015 <legend class="screen-reader-text"><span><?php _e( 'Admin Color Scheme' ); ?></span></legend> |
953 <?php |
1016 <?php |
954 wp_nonce_field( 'save-color-scheme', 'color-nonce', false ); |
1017 wp_nonce_field( 'save-color-scheme', 'color-nonce', false ); |
955 foreach ( $_wp_admin_css_colors as $color => $color_info ) : |
1018 foreach ( $_wp_admin_css_colors as $color => $color_info ) : |
956 |
1019 |
957 ?> |
1020 ?> |
958 <div class="color-option <?php echo ( $color == $current_color ) ? 'selected' : ''; ?>"> |
1021 <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 ); ?> /> |
1022 <input name="admin_color" id="admin_color_<?php echo esc_attr( $color ); ?>" type="radio" value="<?php echo esc_attr( $color ); ?>" class="tog" <?php checked( $color, $current_color ); ?> /> |
960 <input type="hidden" class="css_url" value="<?php echo esc_url( $color_info->url ); ?>" /> |
1023 <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 ) ) ); ?>" /> |
1024 <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> |
1025 <label for="admin_color_<?php echo esc_attr( $color ); ?>"><?php echo esc_html( $color_info->name ); ?></label> |
963 <table class="color-palette"> |
1026 <table class="color-palette"> |
964 <tr> |
1027 <tr> |
965 <?php |
1028 <?php |
966 |
|
967 foreach ( $color_info->colors as $html_color ) { |
1029 foreach ( $color_info->colors as $html_color ) { |
968 ?> |
1030 ?> |
969 <td style="background-color: <?php echo esc_attr( $html_color ); ?>"> </td> |
1031 <td style="background-color: <?php echo esc_attr( $html_color ); ?>"> </td> |
970 <?php |
1032 <?php |
971 } |
1033 } |
972 |
|
973 ?> |
1034 ?> |
974 </tr> |
1035 </tr> |
975 </table> |
1036 </table> |
976 </div> |
1037 </div> |
977 <?php |
1038 <?php |
978 |
1039 |
979 endforeach; |
1040 endforeach; |
980 |
|
981 ?> |
1041 ?> |
982 </fieldset> |
1042 </fieldset> |
983 <?php |
1043 <?php |
984 } |
1044 } |
985 |
1045 |
1048 function _customizer_mobile_viewport_meta( $viewport_meta ) { |
1108 function _customizer_mobile_viewport_meta( $viewport_meta ) { |
1049 return trim( $viewport_meta, ',' ) . ',minimum-scale=0.5,maximum-scale=1.2'; |
1109 return trim( $viewport_meta, ',' ) . ',minimum-scale=0.5,maximum-scale=1.2'; |
1050 } |
1110 } |
1051 |
1111 |
1052 /** |
1112 /** |
1053 * Check lock status for posts displayed on the Posts screen |
1113 * Checks lock status for posts displayed on the Posts screen. |
1054 * |
1114 * |
1055 * @since 3.6.0 |
1115 * @since 3.6.0 |
1056 * |
1116 * |
1057 * @param array $response The Heartbeat response. |
1117 * @param array $response The Heartbeat response. |
1058 * @param array $data The $_POST data sent. |
1118 * @param array $data The $_POST data sent. |
1063 $checked = array(); |
1123 $checked = array(); |
1064 |
1124 |
1065 if ( array_key_exists( 'wp-check-locked-posts', $data ) && is_array( $data['wp-check-locked-posts'] ) ) { |
1125 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 ) { |
1126 foreach ( $data['wp-check-locked-posts'] as $key ) { |
1067 $post_id = absint( substr( $key, 5 ) ); |
1127 $post_id = absint( substr( $key, 5 ) ); |
1128 |
|
1068 if ( ! $post_id ) { |
1129 if ( ! $post_id ) { |
1069 continue; |
1130 continue; |
1070 } |
1131 } |
1071 |
1132 |
1072 $user_id = wp_check_post_lock( $post_id ); |
1133 $user_id = wp_check_post_lock( $post_id ); |
1134 |
|
1073 if ( $user_id ) { |
1135 if ( $user_id ) { |
1074 $user = get_userdata( $user_id ); |
1136 $user = get_userdata( $user_id ); |
1137 |
|
1075 if ( $user && current_user_can( 'edit_post', $post_id ) ) { |
1138 if ( $user && current_user_can( 'edit_post', $post_id ) ) { |
1076 $send = array( |
1139 $send = array( |
1140 'name' => $user->display_name, |
|
1077 /* translators: %s: User's display name. */ |
1141 /* translators: %s: User's display name. */ |
1078 'text' => sprintf( __( '%s is currently editing' ), $user->display_name ), |
1142 'text' => sprintf( __( '%s is currently editing' ), $user->display_name ), |
1079 ); |
1143 ); |
1080 |
1144 |
1081 if ( get_option( 'show_avatars' ) ) { |
1145 if ( get_option( 'show_avatars' ) ) { |
1095 |
1159 |
1096 return $response; |
1160 return $response; |
1097 } |
1161 } |
1098 |
1162 |
1099 /** |
1163 /** |
1100 * Check lock status on the New/Edit Post screen and refresh the lock |
1164 * Checks lock status on the New/Edit Post screen and refresh the lock. |
1101 * |
1165 * |
1102 * @since 3.6.0 |
1166 * @since 3.6.0 |
1103 * |
1167 * |
1104 * @param array $response The Heartbeat response. |
1168 * @param array $response The Heartbeat response. |
1105 * @param array $data The $_POST data sent. |
1169 * @param array $data The $_POST data sent. |
1110 if ( array_key_exists( 'wp-refresh-post-lock', $data ) ) { |
1174 if ( array_key_exists( 'wp-refresh-post-lock', $data ) ) { |
1111 $received = $data['wp-refresh-post-lock']; |
1175 $received = $data['wp-refresh-post-lock']; |
1112 $send = array(); |
1176 $send = array(); |
1113 |
1177 |
1114 $post_id = absint( $received['post_id'] ); |
1178 $post_id = absint( $received['post_id'] ); |
1179 |
|
1115 if ( ! $post_id ) { |
1180 if ( ! $post_id ) { |
1116 return $response; |
1181 return $response; |
1117 } |
1182 } |
1118 |
1183 |
1119 if ( ! current_user_can( 'edit_post', $post_id ) ) { |
1184 if ( ! current_user_can( 'edit_post', $post_id ) ) { |
1120 return $response; |
1185 return $response; |
1121 } |
1186 } |
1122 |
1187 |
1123 $user_id = wp_check_post_lock( $post_id ); |
1188 $user_id = wp_check_post_lock( $post_id ); |
1124 $user = get_userdata( $user_id ); |
1189 $user = get_userdata( $user_id ); |
1190 |
|
1125 if ( $user ) { |
1191 if ( $user ) { |
1126 $error = array( |
1192 $error = array( |
1193 'name' => $user->display_name, |
|
1127 /* translators: %s: User's display name. */ |
1194 /* translators: %s: User's display name. */ |
1128 'text' => sprintf( __( '%s has taken over and is currently editing.' ), $user->display_name ), |
1195 'text' => sprintf( __( '%s has taken over and is currently editing.' ), $user->display_name ), |
1129 ); |
1196 ); |
1130 |
1197 |
1131 if ( get_option( 'show_avatars' ) ) { |
1198 if ( get_option( 'show_avatars' ) ) { |
1134 } |
1201 } |
1135 |
1202 |
1136 $send['lock_error'] = $error; |
1203 $send['lock_error'] = $error; |
1137 } else { |
1204 } else { |
1138 $new_lock = wp_set_post_lock( $post_id ); |
1205 $new_lock = wp_set_post_lock( $post_id ); |
1206 |
|
1139 if ( $new_lock ) { |
1207 if ( $new_lock ) { |
1140 $send['new_lock'] = implode( ':', $new_lock ); |
1208 $send['new_lock'] = implode( ':', $new_lock ); |
1141 } |
1209 } |
1142 } |
1210 } |
1143 |
1211 |
1146 |
1214 |
1147 return $response; |
1215 return $response; |
1148 } |
1216 } |
1149 |
1217 |
1150 /** |
1218 /** |
1151 * Check nonce expiration on the New/Edit Post screen and refresh if needed |
1219 * Checks nonce expiration on the New/Edit Post screen and refresh if needed. |
1152 * |
1220 * |
1153 * @since 3.6.0 |
1221 * @since 3.6.0 |
1154 * |
1222 * |
1155 * @param array $response The Heartbeat response. |
1223 * @param array $response The Heartbeat response. |
1156 * @param array $data The $_POST data sent. |
1224 * @param array $data The $_POST data sent. |
1157 * @param string $screen_id The screen ID. |
1225 * @param string $screen_id The screen ID. |
1158 * @return array The Heartbeat response. |
1226 * @return array The Heartbeat response. |
1159 */ |
1227 */ |
1160 function wp_refresh_post_nonces( $response, $data, $screen_id ) { |
1228 function wp_refresh_post_nonces( $response, $data, $screen_id ) { |
1161 if ( array_key_exists( 'wp-refresh-post-nonces', $data ) ) { |
1229 if ( array_key_exists( 'wp-refresh-post-nonces', $data ) ) { |
1162 $received = $data['wp-refresh-post-nonces']; |
1230 $received = $data['wp-refresh-post-nonces']; |
1231 |
|
1163 $response['wp-refresh-post-nonces'] = array( 'check' => 1 ); |
1232 $response['wp-refresh-post-nonces'] = array( 'check' => 1 ); |
1164 |
1233 |
1165 $post_id = absint( $received['post_id'] ); |
1234 $post_id = absint( $received['post_id'] ); |
1235 |
|
1166 if ( ! $post_id ) { |
1236 if ( ! $post_id ) { |
1167 return $response; |
1237 return $response; |
1168 } |
1238 } |
1169 |
1239 |
1170 if ( ! current_user_can( 'edit_post', $post_id ) ) { |
1240 if ( ! current_user_can( 'edit_post', $post_id ) ) { |
1184 |
1254 |
1185 return $response; |
1255 return $response; |
1186 } |
1256 } |
1187 |
1257 |
1188 /** |
1258 /** |
1189 * Add the latest Heartbeat and REST-API nonce to the Heartbeat response. |
1259 * Adds the latest Heartbeat and REST-API nonce to the Heartbeat response. |
1190 * |
1260 * |
1191 * @since 5.0.0 |
1261 * @since 5.0.0 |
1192 * |
1262 * |
1193 * @param array $response The Heartbeat response. |
1263 * @param array $response The Heartbeat response. |
1194 * @return array The Heartbeat response. |
1264 * @return array The Heartbeat response. |
1197 // Refresh the Rest API nonce. |
1267 // Refresh the Rest API nonce. |
1198 $response['rest_nonce'] = wp_create_nonce( 'wp_rest' ); |
1268 $response['rest_nonce'] = wp_create_nonce( 'wp_rest' ); |
1199 |
1269 |
1200 // Refresh the Heartbeat nonce. |
1270 // Refresh the Heartbeat nonce. |
1201 $response['heartbeat_nonce'] = wp_create_nonce( 'heartbeat-nonce' ); |
1271 $response['heartbeat_nonce'] = wp_create_nonce( 'heartbeat-nonce' ); |
1272 |
|
1202 return $response; |
1273 return $response; |
1203 } |
1274 } |
1204 |
1275 |
1205 /** |
1276 /** |
1206 * Disable suspension of Heartbeat on the Add/Edit Post screens. |
1277 * Disables suspension of Heartbeat on the Add/Edit Post screens. |
1207 * |
1278 * |
1208 * @since 3.8.0 |
1279 * @since 3.8.0 |
1209 * |
1280 * |
1210 * @global string $pagenow |
1281 * @global string $pagenow The filename of the current screen. |
1211 * |
1282 * |
1212 * @param array $settings An array of Heartbeat settings. |
1283 * @param array $settings An array of Heartbeat settings. |
1213 * @return array Filtered Heartbeat settings. |
1284 * @return array Filtered Heartbeat settings. |
1214 */ |
1285 */ |
1215 function wp_heartbeat_set_suspension( $settings ) { |
1286 function wp_heartbeat_set_suspension( $settings ) { |
1221 |
1292 |
1222 return $settings; |
1293 return $settings; |
1223 } |
1294 } |
1224 |
1295 |
1225 /** |
1296 /** |
1226 * Autosave with heartbeat |
1297 * Performs autosave with heartbeat. |
1227 * |
1298 * |
1228 * @since 3.9.0 |
1299 * @since 3.9.0 |
1229 * |
1300 * |
1230 * @param array $response The Heartbeat response. |
1301 * @param array $response The Heartbeat response. |
1231 * @param array $data The $_POST data sent. |
1302 * @param array $data The $_POST data sent. |
1258 |
1329 |
1259 return $response; |
1330 return $response; |
1260 } |
1331 } |
1261 |
1332 |
1262 /** |
1333 /** |
1263 * Remove single-use URL parameters and create canonical link based on new URL. |
1334 * Removes single-use URL parameters and create canonical link based on new URL. |
1264 * |
1335 * |
1265 * Remove specific query string parameters from a URL, create the canonical link, |
1336 * Removes 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. |
1337 * put it in the admin header, and change the current URL to match. |
1267 * |
1338 * |
1268 * @since 4.2.0 |
1339 * @since 4.2.0 |
1269 */ |
1340 */ |
1270 function wp_admin_canonical_url() { |
1341 function wp_admin_canonical_url() { |
1286 </script> |
1357 </script> |
1287 <?php |
1358 <?php |
1288 } |
1359 } |
1289 |
1360 |
1290 /** |
1361 /** |
1291 * Send a referrer policy header so referrers are not sent externally from administration screens. |
1362 * Sends a referrer policy header so referrers are not sent externally from administration screens. |
1292 * |
1363 * |
1293 * @since 4.9.0 |
1364 * @since 4.9.0 |
1294 */ |
1365 */ |
1295 function wp_admin_headers() { |
1366 function wp_admin_headers() { |
1296 $policy = 'strict-origin-when-cross-origin'; |
1367 $policy = 'strict-origin-when-cross-origin'; |
1327 </script> |
1398 </script> |
1328 <?php |
1399 <?php |
1329 } |
1400 } |
1330 |
1401 |
1331 /** |
1402 /** |
1332 * Send a confirmation request email when a change of site admin email address is attempted. |
1403 * Sends a confirmation request email when a change of site admin email address is attempted. |
1333 * |
1404 * |
1334 * The new site admin address will not become active until confirmed. |
1405 * The new site admin address will not become active until confirmed. |
1335 * |
1406 * |
1336 * @since 3.0.0 |
1407 * @since 3.0.0 |
1337 * @since 4.9.0 This function was moved from wp-admin/includes/ms.php so it's no longer Multisite specific. |
1408 * @since 4.9.0 This function was moved from wp-admin/includes/ms.php so it's no longer Multisite specific. |
1355 |
1426 |
1356 /* translators: Do not translate USERNAME, ADMIN_URL, EMAIL, SITENAME, SITEURL: those are placeholders. */ |
1427 /* translators: Do not translate USERNAME, ADMIN_URL, EMAIL, SITENAME, SITEURL: those are placeholders. */ |
1357 $email_text = __( |
1428 $email_text = __( |
1358 'Howdy ###USERNAME###, |
1429 'Howdy ###USERNAME###, |
1359 |
1430 |
1360 You recently requested to have the administration email address on |
1431 Someone with administrator capabilities recently requested to have the |
1361 your site changed. |
1432 administration email address changed on this site: |
1362 |
1433 ###SITEURL### |
1363 If this is correct, please click on the following link to change it: |
1434 |
1435 To confirm this change, please click on the following link: |
|
1364 ###ADMIN_URL### |
1436 ###ADMIN_URL### |
1365 |
1437 |
1366 You can safely ignore and delete this email if you do not want to |
1438 You can safely ignore and delete this email if you do not want to |
1367 take this action. |
1439 take this action. |
1368 |
1440 |
1401 $content = str_replace( '###ADMIN_URL###', esc_url( self_admin_url( 'options.php?adminhash=' . $hash ) ), $content ); |
1473 $content = str_replace( '###ADMIN_URL###', esc_url( self_admin_url( 'options.php?adminhash=' . $hash ) ), $content ); |
1402 $content = str_replace( '###EMAIL###', $value, $content ); |
1474 $content = str_replace( '###EMAIL###', $value, $content ); |
1403 $content = str_replace( '###SITENAME###', wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ), $content ); |
1475 $content = str_replace( '###SITENAME###', wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ), $content ); |
1404 $content = str_replace( '###SITEURL###', home_url(), $content ); |
1476 $content = str_replace( '###SITEURL###', home_url(), $content ); |
1405 |
1477 |
1478 if ( '' !== get_option( 'blogname' ) ) { |
|
1479 $site_title = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); |
|
1480 } else { |
|
1481 $site_title = parse_url( home_url(), PHP_URL_HOST ); |
|
1482 } |
|
1483 |
|
1406 wp_mail( |
1484 wp_mail( |
1407 $value, |
1485 $value, |
1408 sprintf( |
1486 sprintf( |
1409 /* translators: New admin email address notification email subject. %s: Site title. */ |
1487 /* translators: New admin email address notification email subject. %s: Site title. */ |
1410 __( '[%s] New Admin Email Address' ), |
1488 __( '[%s] New Admin Email Address' ), |
1411 wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ) |
1489 $site_title |
1412 ), |
1490 ), |
1413 $content |
1491 $content |
1414 ); |
1492 ); |
1415 |
1493 |
1416 if ( $switched_locale ) { |
1494 if ( $switched_locale ) { |
1449 function wp_check_php_version() { |
1527 function wp_check_php_version() { |
1450 $version = phpversion(); |
1528 $version = phpversion(); |
1451 $key = md5( $version ); |
1529 $key = md5( $version ); |
1452 |
1530 |
1453 $response = get_site_transient( 'php_check_' . $key ); |
1531 $response = get_site_transient( 'php_check_' . $key ); |
1532 |
|
1454 if ( false === $response ) { |
1533 if ( false === $response ) { |
1455 $url = 'http://api.wordpress.org/core/serve-happy/1.0/'; |
1534 $url = 'http://api.wordpress.org/core/serve-happy/1.0/'; |
1535 |
|
1456 if ( wp_http_supports( array( 'ssl' ) ) ) { |
1536 if ( wp_http_supports( array( 'ssl' ) ) ) { |
1457 $url = set_url_scheme( $url, 'https' ); |
1537 $url = set_url_scheme( $url, 'https' ); |
1458 } |
1538 } |
1459 |
1539 |
1460 $url = add_query_arg( 'php_version', $version, $url ); |
1540 $url = add_query_arg( 'php_version', $version, $url ); |