function wp_print_plugin_file_tree( $tree, $label = '', $level = 2, $size = 1, $index = 1 ) {
if ( is_array( $tree ) ) {
foreach ( $tree as $label => $plugin_file ) :
if ( ! is_array( $plugin_file ) ) {
wp_print_plugin_file_tree( $plugin_file, $label, $level, $index, $size );
<li role="treeitem" aria-expanded="true" tabindex="-1"
aria-level="<?php echo esc_attr( $level ); ?>"
aria-setsize="<?php echo esc_attr( $size ); ?>"
aria-posinset="<?php echo esc_attr( $index ); ?>">
<span class="folder-label"><?php echo esc_html( $label ); ?> <span class="screen-reader-text">
/* translators: Hidden accessibility text. */
</span><span aria-hidden="true" class="icon"></span></span>
<ul role="group" class="tree-folder"><?php wp_print_plugin_file_tree( $plugin_file, '', $level + 1, $index, $size ); ?></ul>
'file' => rawurlencode( $tree ),
'plugin' => rawurlencode( $plugin ),
self_admin_url( 'plugin-editor.php' )
<li role="none" class="<?php echo esc_attr( $file === $tree ? 'current-file' : '' ); ?>">
<a role="treeitem" tabindex="<?php echo esc_attr( $file === $tree ? '0' : '-1' ); ?>"
href="<?php echo esc_url( $url ); ?>"
aria-level="<?php echo esc_attr( $level ); ?>"
aria-setsize="<?php echo esc_attr( $size ); ?>"
aria-posinset="<?php echo esc_attr( $index ); ?>">
echo '<span class="notice notice-info">' . esc_html( $label ) . '</span>';
* 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 an
* empty string if neither is defined.
* @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";
* @return string[] Array of function names.
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 ( str_ends_with( $option, '_page' ) || '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 name, `$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 );
* Checks 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 ) {
* Deletes 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 );
* Adds 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.
$xml_nodes = $xpath->query( '/configuration/system.webServer/rewrite/rules' );
if ( $xml_nodes->length > 0 ) {
$rules_node = $xml_nodes->item( 0 );
$rules_node = $doc->createElement( 'rules' );
$xml_nodes = $xpath->query( '/configuration/system.webServer/rewrite' );
if ( $xml_nodes->length > 0 ) {
$rewrite_node = $xml_nodes->item( 0 );
$rewrite_node->appendChild( $rules_node );
$rewrite_node = $doc->createElement( 'rewrite' );
$rewrite_node->appendChild( $rules_node );
$xml_nodes = $xpath->query( '/configuration/system.webServer' );
if ( $xml_nodes->length > 0 ) {
$system_web_server_node = $xml_nodes->item( 0 );
$system_web_server_node->appendChild( $rewrite_node );
$system_web_server_node = $doc->createElement( 'system.webServer' );
$system_web_server_node->appendChild( $rewrite_node );
$xml_nodes = $xpath->query( '/configuration' );
if ( $xml_nodes->length > 0 ) {
$config_node = $xml_nodes->item( 0 );
$config_node->appendChild( $system_web_server_node );
$config_node = $doc->createElement( 'configuration' );
$doc->appendChild( $config_node );
$config_node->appendChild( $system_web_server_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' );
* Displays the default administration 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;