* Flushes rewrite rules if siteurl, home or page_on_front changed.
* @param string $old_value
function update_home_siteurl( $old_value, $value ) {
if ( is_multisite() && ms_is_switched() ) {
delete_option( 'rewrite_rules' );
* Resets global variables based on $_GET and $_POST
* This function resets global variables based on the names passed
* in the $vars array to the value of $_POST[$var] or $_GET[$var] or ''
* @param array $vars An array of globals to reset.
function wp_reset_vars( $vars ) {
foreach ( $vars as $var ) {
if ( empty( $_POST[ $var ] ) ) {
if ( empty( $_GET[ $var ] ) ) {
$GLOBALS[ $var ] = $_GET[ $var ];
$GLOBALS[ $var ] = $_POST[ $var ];
* Displays the given administration message.
* @param string|WP_Error $message
function show_message( $message ) {
if ( is_wp_error( $message ) ) {
if ( $message->get_error_data() && is_string( $message->get_error_data() ) ) {
$message = $message->get_error_message() . ': ' . $message->get_error_data();
$message = $message->get_error_message();
echo "<p>$message</p>\n";
function wp_doc_link_parse( $content ) {
if ( ! is_string( $content ) || empty( $content ) ) {
if ( ! function_exists( 'token_get_all' ) ) {
$tokens = token_get_all( $content );
$count = count( $tokens );
$ignore_functions = array();
for ( $t = 0; $t < $count - 2; $t++ ) {
if ( ! is_array( $tokens[ $t ] ) ) {
if ( T_STRING == $tokens[ $t ][0] && ( '(' === $tokens[ $t + 1 ] || '(' === $tokens[ $t + 2 ] ) ) {
// If it's a function or class defined locally, there's not going to be any docs available.
if ( ( isset( $tokens[ $t - 2 ][1] ) && in_array( $tokens[ $t - 2 ][1], array( 'function', 'class' ), true ) )
|| ( isset( $tokens[ $t - 2 ][0] ) && T_OBJECT_OPERATOR == $tokens[ $t - 1 ][0] )
$ignore_functions[] = $tokens[ $t ][1];
// Add this to our stack of unique references.
$functions[] = $tokens[ $t ][1];
$functions = array_unique( $functions );
* Filters the list of functions and classes to be ignored from the documentation lookup.
* @param string[] $ignore_functions Array of names of functions and classes to be ignored.
$ignore_functions = apply_filters( 'documentation_ignore_functions', $ignore_functions );
$ignore_functions = array_unique( $ignore_functions );
foreach ( $functions as $function ) {
if ( in_array( $function, $ignore_functions, true ) ) {
* Saves option for number of rows when listing posts, pages, comments, etc.
function set_screen_options() {
if ( isset( $_POST['wp_screen_options'] ) && is_array( $_POST['wp_screen_options'] ) ) {
check_admin_referer( 'screen-options-nonce', 'screenoptionnonce' );
$user = wp_get_current_user();
$option = $_POST['wp_screen_options']['option'];
$value = $_POST['wp_screen_options']['value'];
if ( sanitize_key( $option ) != $option ) {
$type = str_replace( 'edit_', '', $map_option );
$type = str_replace( '_per_page', '', $type );
if ( in_array( $type, get_taxonomies(), true ) ) {
$map_option = 'edit_tags_per_page';
} elseif ( in_array( $type, get_post_types(), true ) ) {
$map_option = 'edit_per_page';
$option = str_replace( '-', '_', $option );
case 'edit_comments_per_page':
case 'edit_tags_per_page':
case 'export_personal_data_requests_per_page':
case 'remove_personal_data_requests_per_page':
case 'sites_network_per_page':
case 'users_network_per_page':
case 'site_users_network_per_page':
case 'plugins_network_per_page':
case 'themes_network_per_page':
case 'site_themes_network_per_page':
if ( $value < 1 || $value > 999 ) {
if ( '_page' === substr( $option, -5 ) || 'layout_columns' === $option ) {
* Filters a screen option value before it is set.
* The filter can also be used to modify non-standard [items]_per_page
* settings. See the parent function for a full list of standard options.
* Returning false from the filter will skip saving the current option.
* @since 5.4.2 Only applied to options ending with '_page',
* or the 'layout_columns' option.
* @see set_screen_options()
* @param mixed $screen_option The value to save instead of the option value.
* Default false (to skip saving the current option).
* @param string $option The option name.
* @param int $value The option value.
$screen_option = apply_filters( 'set-screen-option', $screen_option, $option, $value ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
* Filters a screen option value before it is set.
* The dynamic portion of the hook, `$option`, refers to the option name.
* Returning false from the filter will skip saving the current option.
* @see set_screen_options()
* @param mixed $screen_option The value to save instead of the option value.
* Default false (to skip saving the current option).
* @param string $option The option name.
* @param int $value The option value.
$value = apply_filters( "set_screen_option_{$option}", $screen_option, $option, $value );
if ( false === $value ) {
update_user_meta( $user->ID, $option, $value );
$url = remove_query_arg( array( 'pagenum', 'apage', 'paged' ), wp_get_referer() );
if ( isset( $_POST['mode'] ) ) {
$url = add_query_arg( array( 'mode' => $_POST['mode'] ), $url );
wp_safe_redirect( $url );
* Check if rewrite rule for WordPress already exists in the IIS 7+ configuration file
* @param string $filename The file path to the configuration file
function iis7_rewrite_rule_exists( $filename ) {
if ( ! file_exists( $filename ) ) {
if ( ! class_exists( 'DOMDocument', false ) ) {
$doc = new DOMDocument();
if ( $doc->load( $filename ) === false ) {
$xpath = new DOMXPath( $doc );
$rules = $xpath->query( '/configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'wordpress\')] | /configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'WordPress\')]' );
if ( 0 == $rules->length ) {
* Delete WordPress rewrite rule from web.config file if it exists there
* @param string $filename Name of the configuration file
function iis7_delete_rewrite_rule( $filename ) {
// If configuration file does not exist then rules also do not exist, so there is nothing to delete.
if ( ! file_exists( $filename ) ) {
if ( ! class_exists( 'DOMDocument', false ) ) {
$doc = new DOMDocument();
$doc->preserveWhiteSpace = false;
if ( $doc->load( $filename ) === false ) {
$xpath = new DOMXPath( $doc );
$rules = $xpath->query( '/configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'wordpress\')] | /configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'WordPress\')]' );
if ( $rules->length > 0 ) {
$child = $rules->item( 0 );
$parent = $child->parentNode;
$parent->removeChild( $child );
$doc->formatOutput = true;
saveDomDocument( $doc, $filename );
* Add WordPress rewrite rule to the IIS 7+ configuration file.
* @param string $filename The file path to the configuration file
* @param string $rewrite_rule The XML fragment with URL Rewrite rule
function iis7_add_rewrite_rule( $filename, $rewrite_rule ) {
if ( ! class_exists( 'DOMDocument', false ) ) {
// If configuration file does not exist then we create one.
if ( ! file_exists( $filename ) ) {
$fp = fopen( $filename, 'w' );
fwrite( $fp, '<configuration/>' );
$doc = new DOMDocument();
$doc->preserveWhiteSpace = false;
if ( $doc->load( $filename ) === false ) {
$xpath = new DOMXPath( $doc );
// First check if the rule already exists as in that case there is no need to re-add it.
$wordpress_rules = $xpath->query( '/configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'wordpress\')] | /configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'WordPress\')]' );
if ( $wordpress_rules->length > 0 ) {
// Check the XPath to the rewrite rule and create XML nodes if they do not exist.
$xmlnodes = $xpath->query( '/configuration/system.webServer/rewrite/rules' );
if ( $xmlnodes->length > 0 ) {
$rules_node = $xmlnodes->item( 0 );
$rules_node = $doc->createElement( 'rules' );
$xmlnodes = $xpath->query( '/configuration/system.webServer/rewrite' );
if ( $xmlnodes->length > 0 ) {
$rewrite_node = $xmlnodes->item( 0 );
$rewrite_node->appendChild( $rules_node );
$rewrite_node = $doc->createElement( 'rewrite' );
$rewrite_node->appendChild( $rules_node );
$xmlnodes = $xpath->query( '/configuration/system.webServer' );
if ( $xmlnodes->length > 0 ) {
$system_webServer_node = $xmlnodes->item( 0 );
$system_webServer_node->appendChild( $rewrite_node );
$system_webServer_node = $doc->createElement( 'system.webServer' );
$system_webServer_node->appendChild( $rewrite_node );
$xmlnodes = $xpath->query( '/configuration' );
if ( $xmlnodes->length > 0 ) {
$config_node = $xmlnodes->item( 0 );
$config_node->appendChild( $system_webServer_node );
$config_node = $doc->createElement( 'configuration' );
$doc->appendChild( $config_node );
$config_node->appendChild( $system_webServer_node );
$rule_fragment = $doc->createDocumentFragment();
$rule_fragment->appendXML( $rewrite_rule );
$rules_node->appendChild( $rule_fragment );
$doc->encoding = 'UTF-8';
$doc->formatOutput = true;
saveDomDocument( $doc, $filename );
* Saves the XML document into a file
* @param DOMDocument $doc
* @param string $filename
function saveDomDocument( $doc, $filename ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
$config = $doc->saveXML();
$config = preg_replace( "/([^\r])\n/", "$1\r\n", $config );
$fp = fopen( $filename, 'w' );
* Display the default admin color scheme picker (Used in user-edit.php)
* @global array $_wp_admin_css_colors
* @param int $user_id User ID.
function admin_color_scheme_picker( $user_id ) {
global $_wp_admin_css_colors;
ksort( $_wp_admin_css_colors );
if ( isset( $_wp_admin_css_colors['fresh'] ) ) {
// Set Default ('fresh') and Light should go first.
$_wp_admin_css_colors = array_filter(
$current_color = get_user_option( 'admin_color', $user_id );
if ( empty( $current_color ) || ! isset( $_wp_admin_css_colors[ $current_color ] ) ) {
$current_color = 'fresh';
<fieldset id="color-picker" class="scheme-list">
<legend class="screen-reader-text"><span><?php _e( 'Admin Color Scheme' ); ?></span></legend>
wp_nonce_field( 'save-color-scheme', 'color-nonce', false );
foreach ( $_wp_admin_css_colors as $color => $color_info ) :
<div class="color-option <?php echo ( $color == $current_color ) ? 'selected' : ''; ?>">
<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 ); ?> />
<input type="hidden" class="css_url" value="<?php echo esc_url( $color_info->url ); ?>" />
<input type="hidden" class="icon_colors" value="<?php echo esc_attr( wp_json_encode( array( 'icons' => $color_info->icon_colors ) ) ); ?>" />
<label for="admin_color_<?php echo esc_attr( $color ); ?>"><?php echo esc_html( $color_info->name ); ?></label>
<table class="color-palette">
foreach ( $color_info->colors as $html_color ) {
<td style="background-color: <?php echo esc_attr( $html_color ); ?>"> </td>
* @global array $_wp_admin_css_colors
function wp_color_scheme_settings() {
global $_wp_admin_css_colors;
$color_scheme = get_user_option( 'admin_color' );
// It's possible to have a color scheme set that is no longer registered.
if ( empty( $_wp_admin_css_colors[ $color_scheme ] ) ) {
if ( ! empty( $_wp_admin_css_colors[ $color_scheme ]->icon_colors ) ) {