3 * Misc WordPress Administration API.
6 * @subpackage Administration
10 * Returns whether the server is running Apache with the mod_rewrite module loaded.
16 function got_mod_rewrite() {
17 $got_rewrite = apache_mod_loaded('mod_rewrite', true);
20 * Filter whether Apache and mod_rewrite are present.
22 * This filter was previously used to force URL rewriting for other servers,
23 * like nginx. Use the got_url_rewrite filter in got_url_rewrite() instead.
27 * @see got_url_rewrite()
29 * @param bool $got_rewrite Whether Apache and mod_rewrite are present.
31 return apply_filters( 'got_rewrite', $got_rewrite );
35 * Returns whether the server supports URL rewriting.
37 * Detects Apache's mod_rewrite, IIS 7.0+ permalink support, and nginx.
41 * @global bool $is_nginx
43 * @return bool Whether the server supports URL rewriting.
45 function got_url_rewrite() {
46 $got_url_rewrite = ( got_mod_rewrite() || $GLOBALS['is_nginx'] || iis7_supports_permalinks() );
49 * Filter whether URL rewriting is available.
53 * @param bool $got_url_rewrite Whether URL rewriting is available.
55 return apply_filters( 'got_url_rewrite', $got_url_rewrite );
59 * Extracts strings from between the BEGIN and END markers in the .htaccess file.
63 * @param string $filename
64 * @param string $marker
65 * @return array An array of strings from a file (.htaccess ) from between BEGIN and END markers.
67 function extract_from_markers( $filename, $marker ) {
70 if (!file_exists( $filename ) ) {
74 if ( $markerdata = explode( "\n", implode( '', file( $filename ) ) ));
77 foreach ( $markerdata as $markerline ) {
78 if (strpos($markerline, '# END ' . $marker) !== false)
81 $result[] = $markerline;
82 if (strpos($markerline, '# BEGIN ' . $marker) !== false)
91 * Inserts an array of strings into a file (.htaccess ), placing it between
92 * BEGIN and END markers.
94 * Replaces existing marked info. Retains surrounding
95 * data. Creates file if none exists.
99 * @param string $filename Filename to alter.
100 * @param string $marker The marker to alter.
101 * @param array|string $insertion The new content to insert.
102 * @return bool True on write success, false on failure.
104 function insert_with_markers( $filename, $marker, $insertion ) {
105 if ( ! file_exists( $filename ) ) {
106 if ( ! is_writable( dirname( $filename ) ) ) {
109 if ( ! touch( $filename ) ) {
112 } elseif ( ! is_writeable( $filename ) ) {
116 if ( ! is_array( $insertion ) ) {
117 $insertion = explode( "\n", $insertion );
120 $start_marker = "# BEGIN {$marker}";
121 $end_marker = "# END {$marker}";
123 $fp = fopen( $filename, 'r+' );
128 // Attempt to get a lock. If the filesystem supports locking, this will block until the lock is acquired.
129 flock( $fp, LOCK_EX );
132 while ( ! feof( $fp ) ) {
133 $lines[] = rtrim( fgets( $fp ), "\r\n" );
136 // Split out the existing file into the preceeding lines, and those that appear after the marker
137 $pre_lines = $post_lines = $existing_lines = array();
138 $found_marker = $found_end_marker = false;
139 foreach ( $lines as $line ) {
140 if ( ! $found_marker && false !== strpos( $line, $start_marker ) ) {
141 $found_marker = true;
143 } elseif ( ! $found_end_marker && false !== strpos( $line, $end_marker ) ) {
144 $found_end_marker = true;
147 if ( ! $found_marker ) {
148 $pre_lines[] = $line;
149 } elseif ( $found_marker && $found_end_marker ) {
150 $post_lines[] = $line;
152 $existing_lines[] = $line;
156 // Check to see if there was a change
157 if ( $existing_lines === $insertion ) {
158 flock( $fp, LOCK_UN );
164 // Generate the new file data
165 $new_file_data = implode( "\n", array_merge(
167 array( $start_marker ),
169 array( $end_marker ),
173 // Write to the start of the file, and truncate it to that length
175 $bytes = fwrite( $fp, $new_file_data );
177 ftruncate( $fp, ftell( $fp ) );
180 flock( $fp, LOCK_UN );
183 return (bool) $bytes;
187 * Updates the htaccess file with the current rules if it is writable.
189 * Always writes to the file if it exists and is writable to ensure that we
190 * blank out old rules.
194 * @global WP_Rewrite $wp_rewrite
196 function save_mod_rewrite_rules() {
197 if ( is_multisite() )
202 $home_path = get_home_path();
203 $htaccess_file = $home_path.'.htaccess';
206 * If the file doesn't already exist check for write access to the directory
207 * and whether we have some rules. Else check for write access to the file.
209 if ((!file_exists($htaccess_file) && is_writable($home_path) && $wp_rewrite->using_mod_rewrite_permalinks()) || is_writable($htaccess_file)) {
210 if ( got_mod_rewrite() ) {
211 $rules = explode( "\n", $wp_rewrite->mod_rewrite_rules() );
212 return insert_with_markers( $htaccess_file, 'WordPress', $rules );
220 * Updates the IIS web.config file with the current rules if it is writable.
221 * If the permalinks do not require rewrite rules then the rules are deleted from the web.config file.
225 * @global WP_Rewrite $wp_rewrite
227 * @return bool True if web.config was updated successfully
229 function iis7_save_url_rewrite_rules(){
230 if ( is_multisite() )
235 $home_path = get_home_path();
236 $web_config_file = $home_path . 'web.config';
238 // Using win_is_writable() instead of is_writable() because of a bug in Windows PHP
239 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) ) ) {
240 $rule = $wp_rewrite->iis7_url_rewrite_rules(false, '', '');
241 if ( ! empty($rule) ) {
242 return iis7_add_rewrite_rule($web_config_file, $rule);
244 return iis7_delete_rewrite_rule($web_config_file);
251 * Update the "recently-edited" file for the plugin or theme editor.
255 * @param string $file
257 function update_recently_edited( $file ) {
258 $oldfiles = (array ) get_option( 'recently_edited' );
260 $oldfiles = array_reverse( $oldfiles );
262 $oldfiles = array_reverse( $oldfiles );
263 $oldfiles = array_unique( $oldfiles );
264 if ( 5 < count( $oldfiles ))
265 array_pop( $oldfiles );
269 update_option( 'recently_edited', $oldfiles );
273 * Flushes rewrite rules if siteurl, home or page_on_front changed.
277 * @param string $old_value
278 * @param string $value
280 function update_home_siteurl( $old_value, $value ) {
281 if ( wp_installing() )
284 if ( is_multisite() && ms_is_switched() ) {
285 delete_option( 'rewrite_rules' );
287 flush_rewrite_rules();
293 * Resets global variables based on $_GET and $_POST
295 * This function resets global variables based on the names passed
296 * in the $vars array to the value of $_POST[$var] or $_GET[$var] or ''
297 * if neither is defined.
301 * @param array $vars An array of globals to reset.
303 function wp_reset_vars( $vars ) {
304 foreach ( $vars as $var ) {
305 if ( empty( $_POST[ $var ] ) ) {
306 if ( empty( $_GET[ $var ] ) ) {
307 $GLOBALS[ $var ] = '';
309 $GLOBALS[ $var ] = $_GET[ $var ];
312 $GLOBALS[ $var ] = $_POST[ $var ];
318 * Displays the given administration message.
322 * @param string|WP_Error $message
324 function show_message($message) {
325 if ( is_wp_error($message) ){
326 if ( $message->get_error_data() && is_string( $message->get_error_data() ) )
327 $message = $message->get_error_message() . ': ' . $message->get_error_data();
329 $message = $message->get_error_message();
331 echo "<p>$message</p>\n";
332 wp_ob_end_flush_all();
339 * @param string $content
342 function wp_doc_link_parse( $content ) {
343 if ( !is_string( $content ) || empty( $content ) )
346 if ( !function_exists('token_get_all') )
349 $tokens = token_get_all( $content );
350 $count = count( $tokens );
351 $functions = array();
352 $ignore_functions = array();
353 for ( $t = 0; $t < $count - 2; $t++ ) {
354 if ( ! is_array( $tokens[ $t ] ) ) {
358 if ( T_STRING == $tokens[ $t ][0] && ( '(' == $tokens[ $t + 1 ] || '(' == $tokens[ $t + 2 ] ) ) {
359 // If it's a function or class defined locally, there's not going to be any docs available
360 if ( ( isset( $tokens[ $t - 2 ][1] ) && in_array( $tokens[ $t - 2 ][1], array( 'function', 'class' ) ) ) || ( isset( $tokens[ $t - 2 ][0] ) && T_OBJECT_OPERATOR == $tokens[ $t - 1 ][0] ) ) {
361 $ignore_functions[] = $tokens[$t][1];
363 // Add this to our stack of unique references
364 $functions[] = $tokens[$t][1];
368 $functions = array_unique( $functions );
372 * Filter the list of functions and classes to be ignored from the documentation lookup.
376 * @param array $ignore_functions Functions and classes to be ignored.
378 $ignore_functions = apply_filters( 'documentation_ignore_functions', $ignore_functions );
380 $ignore_functions = array_unique( $ignore_functions );
383 foreach ( $functions as $function ) {
384 if ( in_array( $function, $ignore_functions ) )
393 * Saves option for number of rows when listing posts, pages, comments, etc.
397 function set_screen_options() {
399 if ( isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options']) ) {
400 check_admin_referer( 'screen-options-nonce', 'screenoptionnonce' );
402 if ( !$user = wp_get_current_user() )
404 $option = $_POST['wp_screen_options']['option'];
405 $value = $_POST['wp_screen_options']['value'];
407 if ( $option != sanitize_key( $option ) )
410 $map_option = $option;
411 $type = str_replace('edit_', '', $map_option);
412 $type = str_replace('_per_page', '', $type);
413 if ( in_array( $type, get_taxonomies() ) )
414 $map_option = 'edit_tags_per_page';
415 elseif ( in_array( $type, get_post_types() ) )
416 $map_option = 'edit_per_page';
418 $option = str_replace('-', '_', $option);
420 switch ( $map_option ) {
421 case 'edit_per_page':
422 case 'users_per_page':
423 case 'edit_comments_per_page':
424 case 'upload_per_page':
425 case 'edit_tags_per_page':
426 case 'plugins_per_page':
428 case 'sites_network_per_page':
429 case 'users_network_per_page':
430 case 'site_users_network_per_page':
431 case 'plugins_network_per_page':
432 case 'themes_network_per_page':
433 case 'site_themes_network_per_page':
434 $value = (int) $value;
435 if ( $value < 1 || $value > 999 )
441 * Filter a screen option value before it is set.
443 * The filter can also be used to modify non-standard [items]_per_page
444 * settings. See the parent function for a full list of standard options.
446 * Returning false to the filter will skip saving the current option.
450 * @see set_screen_options()
452 * @param bool|int $value Screen option value. Default false to skip.
453 * @param string $option The option name.
454 * @param int $value The number of rows to use.
456 $value = apply_filters( 'set-screen-option', false, $option, $value );
458 if ( false === $value )
463 update_user_meta($user->ID, $option, $value);
465 $url = remove_query_arg( array( 'pagenum', 'apage', 'paged' ), wp_get_referer() );
466 if ( isset( $_POST['mode'] ) ) {
467 $url = add_query_arg( array( 'mode' => $_POST['mode'] ), $url );
470 wp_safe_redirect( $url );
476 * Check if rewrite rule for WordPress already exists in the IIS 7+ configuration file
481 * @param string $filename The file path to the configuration file
483 function iis7_rewrite_rule_exists($filename) {
484 if ( ! file_exists($filename) )
486 if ( ! class_exists( 'DOMDocument', false ) ) {
490 $doc = new DOMDocument();
491 if ( $doc->load($filename) === false )
493 $xpath = new DOMXPath($doc);
494 $rules = $xpath->query('/configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'wordpress\')] | /configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'WordPress\')]');
495 if ( $rules->length == 0 )
502 * Delete WordPress rewrite rule from web.config file if it exists there
506 * @param string $filename Name of the configuration file
509 function iis7_delete_rewrite_rule($filename) {
510 // If configuration file does not exist then rules also do not exist so there is nothing to delete
511 if ( ! file_exists($filename) )
514 if ( ! class_exists( 'DOMDocument', false ) ) {
518 $doc = new DOMDocument();
519 $doc->preserveWhiteSpace = false;
521 if ( $doc -> load($filename) === false )
523 $xpath = new DOMXPath($doc);
524 $rules = $xpath->query('/configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'wordpress\')] | /configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'WordPress\')]');
525 if ( $rules->length > 0 ) {
526 $child = $rules->item(0);
527 $parent = $child->parentNode;
528 $parent->removeChild($child);
529 $doc->formatOutput = true;
530 saveDomDocument($doc, $filename);
536 * Add WordPress rewrite rule to the IIS 7+ configuration file.
540 * @param string $filename The file path to the configuration file
541 * @param string $rewrite_rule The XML fragment with URL Rewrite rule
544 function iis7_add_rewrite_rule($filename, $rewrite_rule) {
545 if ( ! class_exists( 'DOMDocument', false ) ) {
549 // If configuration file does not exist then we create one.
550 if ( ! file_exists($filename) ) {
551 $fp = fopen( $filename, 'w');
552 fwrite($fp, '<configuration/>');
556 $doc = new DOMDocument();
557 $doc->preserveWhiteSpace = false;
559 if ( $doc->load($filename) === false )
562 $xpath = new DOMXPath($doc);
564 // First check if the rule already exists as in that case there is no need to re-add it
565 $wordpress_rules = $xpath->query('/configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'wordpress\')] | /configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'WordPress\')]');
566 if ( $wordpress_rules->length > 0 )
569 // Check the XPath to the rewrite rule and create XML nodes if they do not exist
570 $xmlnodes = $xpath->query('/configuration/system.webServer/rewrite/rules');
571 if ( $xmlnodes->length > 0 ) {
572 $rules_node = $xmlnodes->item(0);
574 $rules_node = $doc->createElement('rules');
576 $xmlnodes = $xpath->query('/configuration/system.webServer/rewrite');
577 if ( $xmlnodes->length > 0 ) {
578 $rewrite_node = $xmlnodes->item(0);
579 $rewrite_node->appendChild($rules_node);
581 $rewrite_node = $doc->createElement('rewrite');
582 $rewrite_node->appendChild($rules_node);
584 $xmlnodes = $xpath->query('/configuration/system.webServer');
585 if ( $xmlnodes->length > 0 ) {
586 $system_webServer_node = $xmlnodes->item(0);
587 $system_webServer_node->appendChild($rewrite_node);
589 $system_webServer_node = $doc->createElement('system.webServer');
590 $system_webServer_node->appendChild($rewrite_node);
592 $xmlnodes = $xpath->query('/configuration');
593 if ( $xmlnodes->length > 0 ) {
594 $config_node = $xmlnodes->item(0);
595 $config_node->appendChild($system_webServer_node);
597 $config_node = $doc->createElement('configuration');
598 $doc->appendChild($config_node);
599 $config_node->appendChild($system_webServer_node);
605 $rule_fragment = $doc->createDocumentFragment();
606 $rule_fragment->appendXML($rewrite_rule);
607 $rules_node->appendChild($rule_fragment);
609 $doc->encoding = "UTF-8";
610 $doc->formatOutput = true;
611 saveDomDocument($doc, $filename);
617 * Saves the XML document into a file
621 * @param DOMDocument $doc
622 * @param string $filename
624 function saveDomDocument($doc, $filename) {
625 $config = $doc->saveXML();
626 $config = preg_replace("/([^\r])\n/", "$1\r\n", $config);
627 $fp = fopen($filename, 'w');
628 fwrite($fp, $config);
633 * Display the default admin color scheme picker (Used in user-edit.php)
637 * @global array $_wp_admin_css_colors
639 * @param int $user_id User ID.
641 function admin_color_scheme_picker( $user_id ) {
642 global $_wp_admin_css_colors;
644 ksort( $_wp_admin_css_colors );
646 if ( isset( $_wp_admin_css_colors['fresh'] ) ) {
647 // Set Default ('fresh') and Light should go first.
648 $_wp_admin_css_colors = array_filter( array_merge( array( 'fresh' => '', 'light' => '' ), $_wp_admin_css_colors ) );
651 $current_color = get_user_option( 'admin_color', $user_id );
653 if ( empty( $current_color ) || ! isset( $_wp_admin_css_colors[ $current_color ] ) ) {
654 $current_color = 'fresh';
658 <fieldset id="color-picker" class="scheme-list">
659 <legend class="screen-reader-text"><span><?php _e( 'Admin Color Scheme' ); ?></span></legend>
661 wp_nonce_field( 'save-color-scheme', 'color-nonce', false );
662 foreach ( $_wp_admin_css_colors as $color => $color_info ) :
665 <div class="color-option <?php echo ( $color == $current_color ) ? 'selected' : ''; ?>">
666 <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 ); ?> />
667 <input type="hidden" class="css_url" value="<?php echo esc_url( $color_info->url ); ?>" />
668 <input type="hidden" class="icon_colors" value="<?php echo esc_attr( wp_json_encode( array( 'icons' => $color_info->icon_colors ) ) ); ?>" />
669 <label for="admin_color_<?php echo esc_attr( $color ); ?>"><?php echo esc_html( $color_info->name ); ?></label>
670 <table class="color-palette">
674 foreach ( $color_info->colors as $html_color ) {
676 <td style="background-color: <?php echo esc_attr( $html_color ); ?>"> </td>
695 * @global array $_wp_admin_css_colors
697 function wp_color_scheme_settings() {
698 global $_wp_admin_css_colors;
700 $color_scheme = get_user_option( 'admin_color' );
702 // It's possible to have a color scheme set that is no longer registered.
703 if ( empty( $_wp_admin_css_colors[ $color_scheme ] ) ) {
704 $color_scheme = 'fresh';
707 if ( ! empty( $_wp_admin_css_colors[ $color_scheme ]->icon_colors ) ) {
708 $icon_colors = $_wp_admin_css_colors[ $color_scheme ]->icon_colors;
709 } elseif ( ! empty( $_wp_admin_css_colors['fresh']->icon_colors ) ) {
710 $icon_colors = $_wp_admin_css_colors['fresh']->icon_colors;
712 // Fall back to the default set of icon colors if the default scheme is missing.
713 $icon_colors = array( 'base' => '#82878c', 'focus' => '#00a0d2', 'current' => '#fff' );
716 echo '<script type="text/javascript">var _wpColorScheme = ' . wp_json_encode( array( 'icons' => $icon_colors ) ) . ";</script>\n";
722 function _ipad_meta() {
723 if ( wp_is_mobile() ) {
725 <meta name="viewport" id="viewport-meta" content="width=device-width, initial-scale=1">
731 * Check lock status for posts displayed on the Posts screen
735 * @param array $response The Heartbeat response.
736 * @param array $data The $_POST data sent.
737 * @param string $screen_id The screen id.
738 * @return array The Heartbeat response.
740 function wp_check_locked_posts( $response, $data, $screen_id ) {
743 if ( array_key_exists( 'wp-check-locked-posts', $data ) && is_array( $data['wp-check-locked-posts'] ) ) {
744 foreach ( $data['wp-check-locked-posts'] as $key ) {
745 if ( ! $post_id = absint( substr( $key, 5 ) ) )
748 if ( ( $user_id = wp_check_post_lock( $post_id ) ) && ( $user = get_userdata( $user_id ) ) && current_user_can( 'edit_post', $post_id ) ) {
749 $send = array( 'text' => sprintf( __( '%s is currently editing' ), $user->display_name ) );
751 if ( ( $avatar = get_avatar( $user->ID, 18 ) ) && preg_match( "|src='([^']+)'|", $avatar, $matches ) )
752 $send['avatar_src'] = $matches[1];
754 $checked[$key] = $send;
759 if ( ! empty( $checked ) )
760 $response['wp-check-locked-posts'] = $checked;
766 * Check lock status on the New/Edit Post screen and refresh the lock
770 * @param array $response The Heartbeat response.
771 * @param array $data The $_POST data sent.
772 * @param string $screen_id The screen id.
773 * @return array The Heartbeat response.
775 function wp_refresh_post_lock( $response, $data, $screen_id ) {
776 if ( array_key_exists( 'wp-refresh-post-lock', $data ) ) {
777 $received = $data['wp-refresh-post-lock'];
780 if ( ! $post_id = absint( $received['post_id'] ) )
783 if ( ! current_user_can('edit_post', $post_id) )
786 if ( ( $user_id = wp_check_post_lock( $post_id ) ) && ( $user = get_userdata( $user_id ) ) ) {
788 'text' => sprintf( __( '%s has taken over and is currently editing.' ), $user->display_name )
791 if ( $avatar = get_avatar( $user->ID, 64 ) ) {
792 if ( preg_match( "|src='([^']+)'|", $avatar, $matches ) )
793 $error['avatar_src'] = $matches[1];
796 $send['lock_error'] = $error;
798 if ( $new_lock = wp_set_post_lock( $post_id ) )
799 $send['new_lock'] = implode( ':', $new_lock );
802 $response['wp-refresh-post-lock'] = $send;
809 * Check nonce expiration on the New/Edit Post screen and refresh if needed
813 * @param array $response The Heartbeat response.
814 * @param array $data The $_POST data sent.
815 * @param string $screen_id The screen id.
816 * @return array The Heartbeat response.
818 function wp_refresh_post_nonces( $response, $data, $screen_id ) {
819 if ( array_key_exists( 'wp-refresh-post-nonces', $data ) ) {
820 $received = $data['wp-refresh-post-nonces'];
821 $response['wp-refresh-post-nonces'] = array( 'check' => 1 );
823 if ( ! $post_id = absint( $received['post_id'] ) ) {
827 if ( ! current_user_can( 'edit_post', $post_id ) ) {
831 $response['wp-refresh-post-nonces'] = array(
833 'getpermalinknonce' => wp_create_nonce('getpermalink'),
834 'samplepermalinknonce' => wp_create_nonce('samplepermalink'),
835 'closedpostboxesnonce' => wp_create_nonce('closedpostboxes'),
836 '_ajax_linking_nonce' => wp_create_nonce( 'internal-linking' ),
837 '_wpnonce' => wp_create_nonce( 'update-post_' . $post_id ),
839 'heartbeatNonce' => wp_create_nonce( 'heartbeat-nonce' ),
847 * Disable suspension of Heartbeat on the Add/Edit Post screens.
851 * @global string $pagenow
853 * @param array $settings An array of Heartbeat settings.
854 * @return array Filtered Heartbeat settings.
856 function wp_heartbeat_set_suspension( $settings ) {
859 if ( 'post.php' === $pagenow || 'post-new.php' === $pagenow ) {
860 $settings['suspension'] = 'disable';
867 * Autosave with heartbeat
871 * @param array $response The Heartbeat response.
872 * @param array $data The $_POST data sent.
873 * @return array The Heartbeat response.
875 function heartbeat_autosave( $response, $data ) {
876 if ( ! empty( $data['wp_autosave'] ) ) {
877 $saved = wp_autosave( $data['wp_autosave'] );
879 if ( is_wp_error( $saved ) ) {
880 $response['wp_autosave'] = array( 'success' => false, 'message' => $saved->get_error_message() );
881 } elseif ( empty( $saved ) ) {
882 $response['wp_autosave'] = array( 'success' => false, 'message' => __( 'Error while saving.' ) );
884 /* translators: draft saved date format, see http://php.net/date */
885 $draft_saved_date_format = __( 'g:i:s a' );
886 /* translators: %s: date and time */
887 $response['wp_autosave'] = array( 'success' => true, 'message' => sprintf( __( 'Draft saved at %s.' ), date_i18n( $draft_saved_date_format ) ) );
895 * Disables autocomplete on the 'post' form (Add/Edit Post screens) for WebKit browsers,
896 * as they disregard the autocomplete setting on the editor textarea. That can break the editor
897 * when the user navigates to it with the browser's Back button. See #28037
901 * @global bool $is_safari
902 * @global bool $is_chrome
904 function post_form_autocomplete_off() {
905 global $is_safari, $is_chrome;
907 if ( $is_safari || $is_chrome ) {
908 echo ' autocomplete="off"';
913 * Remove single-use URL parameters and create canonical link based on new URL.
915 * Remove specific query string parameters from a URL, create the canonical link,
916 * put it in the admin header, and change the current URL to match.
920 function wp_admin_canonical_url() {
921 $removable_query_args = wp_removable_query_args();
923 if ( empty( $removable_query_args ) ) {
927 // Ensure we're using an absolute URL.
928 $current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
929 $filtered_url = remove_query_arg( $removable_query_args, $current_url );
931 <link id="wp-admin-canonical" rel="canonical" href="<?php echo esc_url( $filtered_url ); ?>" />
933 if ( window.history.replaceState ) {
934 window.history.replaceState( null, null, document.getElementById( 'wp-admin-canonical' ).href + window.location.hash );