Edit File by line
/home/barbar84/www/wp-admin/includes
File: misc.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Misc WordPress Administration API.
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
* @subpackage Administration
[5] Fix | Delete
*/
[6] Fix | Delete
[7] Fix | Delete
/**
[8] Fix | Delete
* Returns whether the server is running Apache with the mod_rewrite module loaded.
[9] Fix | Delete
*
[10] Fix | Delete
* @since 2.0.0
[11] Fix | Delete
*
[12] Fix | Delete
* @return bool Whether the server is running Apache with the mod_rewrite module loaded.
[13] Fix | Delete
*/
[14] Fix | Delete
function got_mod_rewrite() {
[15] Fix | Delete
$got_rewrite = apache_mod_loaded( 'mod_rewrite', true );
[16] Fix | Delete
[17] Fix | Delete
/**
[18] Fix | Delete
* Filters whether Apache and mod_rewrite are present.
[19] Fix | Delete
*
[20] Fix | Delete
* This filter was previously used to force URL rewriting for other servers,
[21] Fix | Delete
* like nginx. Use the {@see 'got_url_rewrite'} filter in got_url_rewrite() instead.
[22] Fix | Delete
*
[23] Fix | Delete
* @since 2.5.0
[24] Fix | Delete
*
[25] Fix | Delete
* @see got_url_rewrite()
[26] Fix | Delete
*
[27] Fix | Delete
* @param bool $got_rewrite Whether Apache and mod_rewrite are present.
[28] Fix | Delete
*/
[29] Fix | Delete
return apply_filters( 'got_rewrite', $got_rewrite );
[30] Fix | Delete
}
[31] Fix | Delete
[32] Fix | Delete
/**
[33] Fix | Delete
* Returns whether the server supports URL rewriting.
[34] Fix | Delete
*
[35] Fix | Delete
* Detects Apache's mod_rewrite, IIS 7.0+ permalink support, and nginx.
[36] Fix | Delete
*
[37] Fix | Delete
* @since 3.7.0
[38] Fix | Delete
*
[39] Fix | Delete
* @global bool $is_nginx
[40] Fix | Delete
*
[41] Fix | Delete
* @return bool Whether the server supports URL rewriting.
[42] Fix | Delete
*/
[43] Fix | Delete
function got_url_rewrite() {
[44] Fix | Delete
$got_url_rewrite = ( got_mod_rewrite() || $GLOBALS['is_nginx'] || iis7_supports_permalinks() );
[45] Fix | Delete
[46] Fix | Delete
/**
[47] Fix | Delete
* Filters whether URL rewriting is available.
[48] Fix | Delete
*
[49] Fix | Delete
* @since 3.7.0
[50] Fix | Delete
*
[51] Fix | Delete
* @param bool $got_url_rewrite Whether URL rewriting is available.
[52] Fix | Delete
*/
[53] Fix | Delete
return apply_filters( 'got_url_rewrite', $got_url_rewrite );
[54] Fix | Delete
}
[55] Fix | Delete
[56] Fix | Delete
/**
[57] Fix | Delete
* Extracts strings from between the BEGIN and END markers in the .htaccess file.
[58] Fix | Delete
*
[59] Fix | Delete
* @since 1.5.0
[60] Fix | Delete
*
[61] Fix | Delete
* @param string $filename Filename to extract the strings from.
[62] Fix | Delete
* @param string $marker The marker to extract the strings from.
[63] Fix | Delete
* @return string[] An array of strings from a file (.htaccess) from between BEGIN and END markers.
[64] Fix | Delete
*/
[65] Fix | Delete
function extract_from_markers( $filename, $marker ) {
[66] Fix | Delete
$result = array();
[67] Fix | Delete
[68] Fix | Delete
if ( ! file_exists( $filename ) ) {
[69] Fix | Delete
return $result;
[70] Fix | Delete
}
[71] Fix | Delete
[72] Fix | Delete
$markerdata = explode( "\n", implode( '', file( $filename ) ) );
[73] Fix | Delete
[74] Fix | Delete
$state = false;
[75] Fix | Delete
foreach ( $markerdata as $markerline ) {
[76] Fix | Delete
if ( false !== strpos( $markerline, '# END ' . $marker ) ) {
[77] Fix | Delete
$state = false;
[78] Fix | Delete
}
[79] Fix | Delete
if ( $state ) {
[80] Fix | Delete
if ( '#' === substr( $markerline, 0, 1 ) ) {
[81] Fix | Delete
continue;
[82] Fix | Delete
}
[83] Fix | Delete
$result[] = $markerline;
[84] Fix | Delete
}
[85] Fix | Delete
if ( false !== strpos( $markerline, '# BEGIN ' . $marker ) ) {
[86] Fix | Delete
$state = true;
[87] Fix | Delete
}
[88] Fix | Delete
}
[89] Fix | Delete
[90] Fix | Delete
return $result;
[91] Fix | Delete
}
[92] Fix | Delete
[93] Fix | Delete
/**
[94] Fix | Delete
* Inserts an array of strings into a file (.htaccess), placing it between
[95] Fix | Delete
* BEGIN and END markers.
[96] Fix | Delete
*
[97] Fix | Delete
* Replaces existing marked info. Retains surrounding
[98] Fix | Delete
* data. Creates file if none exists.
[99] Fix | Delete
*
[100] Fix | Delete
* @since 1.5.0
[101] Fix | Delete
*
[102] Fix | Delete
* @param string $filename Filename to alter.
[103] Fix | Delete
* @param string $marker The marker to alter.
[104] Fix | Delete
* @param array|string $insertion The new content to insert.
[105] Fix | Delete
* @return bool True on write success, false on failure.
[106] Fix | Delete
*/
[107] Fix | Delete
function insert_with_markers( $filename, $marker, $insertion ) {
[108] Fix | Delete
if ( ! file_exists( $filename ) ) {
[109] Fix | Delete
if ( ! is_writable( dirname( $filename ) ) ) {
[110] Fix | Delete
return false;
[111] Fix | Delete
}
[112] Fix | Delete
[113] Fix | Delete
if ( ! touch( $filename ) ) {
[114] Fix | Delete
return false;
[115] Fix | Delete
}
[116] Fix | Delete
[117] Fix | Delete
// Make sure the file is created with a minimum set of permissions.
[118] Fix | Delete
$perms = fileperms( $filename );
[119] Fix | Delete
if ( $perms ) {
[120] Fix | Delete
chmod( $filename, $perms | 0644 );
[121] Fix | Delete
}
[122] Fix | Delete
} elseif ( ! is_writable( $filename ) ) {
[123] Fix | Delete
return false;
[124] Fix | Delete
}
[125] Fix | Delete
[126] Fix | Delete
if ( ! is_array( $insertion ) ) {
[127] Fix | Delete
$insertion = explode( "\n", $insertion );
[128] Fix | Delete
}
[129] Fix | Delete
[130] Fix | Delete
$switched_locale = switch_to_locale( get_locale() );
[131] Fix | Delete
[132] Fix | Delete
$instructions = sprintf(
[133] Fix | Delete
/* translators: 1: Marker. */
[134] Fix | Delete
__(
[135] Fix | Delete
'The directives (lines) between "BEGIN %1$s" and "END %1$s" are
[136] Fix | Delete
dynamically generated, and should only be modified via WordPress filters.
[137] Fix | Delete
Any changes to the directives between these markers will be overwritten.'
[138] Fix | Delete
),
[139] Fix | Delete
$marker
[140] Fix | Delete
);
[141] Fix | Delete
[142] Fix | Delete
$instructions = explode( "\n", $instructions );
[143] Fix | Delete
foreach ( $instructions as $line => $text ) {
[144] Fix | Delete
$instructions[ $line ] = '# ' . $text;
[145] Fix | Delete
}
[146] Fix | Delete
[147] Fix | Delete
/**
[148] Fix | Delete
* Filters the inline instructions inserted before the dynamically generated content.
[149] Fix | Delete
*
[150] Fix | Delete
* @since 5.3.0
[151] Fix | Delete
*
[152] Fix | Delete
* @param string[] $instructions Array of lines with inline instructions.
[153] Fix | Delete
* @param string $marker The marker being inserted.
[154] Fix | Delete
*/
[155] Fix | Delete
$instructions = apply_filters( 'insert_with_markers_inline_instructions', $instructions, $marker );
[156] Fix | Delete
[157] Fix | Delete
if ( $switched_locale ) {
[158] Fix | Delete
restore_previous_locale();
[159] Fix | Delete
}
[160] Fix | Delete
[161] Fix | Delete
$insertion = array_merge( $instructions, $insertion );
[162] Fix | Delete
[163] Fix | Delete
$start_marker = "# BEGIN {$marker}";
[164] Fix | Delete
$end_marker = "# END {$marker}";
[165] Fix | Delete
[166] Fix | Delete
$fp = fopen( $filename, 'r+' );
[167] Fix | Delete
if ( ! $fp ) {
[168] Fix | Delete
return false;
[169] Fix | Delete
}
[170] Fix | Delete
[171] Fix | Delete
// Attempt to get a lock. If the filesystem supports locking, this will block until the lock is acquired.
[172] Fix | Delete
flock( $fp, LOCK_EX );
[173] Fix | Delete
[174] Fix | Delete
$lines = array();
[175] Fix | Delete
while ( ! feof( $fp ) ) {
[176] Fix | Delete
$lines[] = rtrim( fgets( $fp ), "\r\n" );
[177] Fix | Delete
}
[178] Fix | Delete
[179] Fix | Delete
// Split out the existing file into the preceding lines, and those that appear after the marker.
[180] Fix | Delete
$pre_lines = array();
[181] Fix | Delete
$post_lines = array();
[182] Fix | Delete
$existing_lines = array();
[183] Fix | Delete
$found_marker = false;
[184] Fix | Delete
$found_end_marker = false;
[185] Fix | Delete
foreach ( $lines as $line ) {
[186] Fix | Delete
if ( ! $found_marker && false !== strpos( $line, $start_marker ) ) {
[187] Fix | Delete
$found_marker = true;
[188] Fix | Delete
continue;
[189] Fix | Delete
} elseif ( ! $found_end_marker && false !== strpos( $line, $end_marker ) ) {
[190] Fix | Delete
$found_end_marker = true;
[191] Fix | Delete
continue;
[192] Fix | Delete
}
[193] Fix | Delete
if ( ! $found_marker ) {
[194] Fix | Delete
$pre_lines[] = $line;
[195] Fix | Delete
} elseif ( $found_marker && $found_end_marker ) {
[196] Fix | Delete
$post_lines[] = $line;
[197] Fix | Delete
} else {
[198] Fix | Delete
$existing_lines[] = $line;
[199] Fix | Delete
}
[200] Fix | Delete
}
[201] Fix | Delete
[202] Fix | Delete
// Check to see if there was a change.
[203] Fix | Delete
if ( $existing_lines === $insertion ) {
[204] Fix | Delete
flock( $fp, LOCK_UN );
[205] Fix | Delete
fclose( $fp );
[206] Fix | Delete
[207] Fix | Delete
return true;
[208] Fix | Delete
}
[209] Fix | Delete
[210] Fix | Delete
// Generate the new file data.
[211] Fix | Delete
$new_file_data = implode(
[212] Fix | Delete
"\n",
[213] Fix | Delete
array_merge(
[214] Fix | Delete
$pre_lines,
[215] Fix | Delete
array( $start_marker ),
[216] Fix | Delete
$insertion,
[217] Fix | Delete
array( $end_marker ),
[218] Fix | Delete
$post_lines
[219] Fix | Delete
)
[220] Fix | Delete
);
[221] Fix | Delete
[222] Fix | Delete
// Write to the start of the file, and truncate it to that length.
[223] Fix | Delete
fseek( $fp, 0 );
[224] Fix | Delete
$bytes = fwrite( $fp, $new_file_data );
[225] Fix | Delete
if ( $bytes ) {
[226] Fix | Delete
ftruncate( $fp, ftell( $fp ) );
[227] Fix | Delete
}
[228] Fix | Delete
fflush( $fp );
[229] Fix | Delete
flock( $fp, LOCK_UN );
[230] Fix | Delete
fclose( $fp );
[231] Fix | Delete
[232] Fix | Delete
return (bool) $bytes;
[233] Fix | Delete
}
[234] Fix | Delete
[235] Fix | Delete
/**
[236] Fix | Delete
* Updates the htaccess file with the current rules if it is writable.
[237] Fix | Delete
*
[238] Fix | Delete
* Always writes to the file if it exists and is writable to ensure that we
[239] Fix | Delete
* blank out old rules.
[240] Fix | Delete
*
[241] Fix | Delete
* @since 1.5.0
[242] Fix | Delete
*
[243] Fix | Delete
* @global WP_Rewrite $wp_rewrite WordPress rewrite component.
[244] Fix | Delete
*
[245] Fix | Delete
* @return bool|null True on write success, false on failure. Null in multisite.
[246] Fix | Delete
*/
[247] Fix | Delete
function save_mod_rewrite_rules() {
[248] Fix | Delete
if ( is_multisite() ) {
[249] Fix | Delete
return;
[250] Fix | Delete
}
[251] Fix | Delete
[252] Fix | Delete
global $wp_rewrite;
[253] Fix | Delete
[254] Fix | Delete
// Ensure get_home_path() is declared.
[255] Fix | Delete
require_once ABSPATH . 'wp-admin/includes/file.php';
[256] Fix | Delete
[257] Fix | Delete
$home_path = get_home_path();
[258] Fix | Delete
$htaccess_file = $home_path . '.htaccess';
[259] Fix | Delete
[260] Fix | Delete
/*
[261] Fix | Delete
* If the file doesn't already exist check for write access to the directory
[262] Fix | Delete
* and whether we have some rules. Else check for write access to the file.
[263] Fix | Delete
*/
[264] Fix | Delete
if ( ( ! file_exists( $htaccess_file ) && is_writable( $home_path ) && $wp_rewrite->using_mod_rewrite_permalinks() ) || is_writable( $htaccess_file ) ) {
[265] Fix | Delete
if ( got_mod_rewrite() ) {
[266] Fix | Delete
$rules = explode( "\n", $wp_rewrite->mod_rewrite_rules() );
[267] Fix | Delete
return insert_with_markers( $htaccess_file, 'WordPress', $rules );
[268] Fix | Delete
}
[269] Fix | Delete
}
[270] Fix | Delete
[271] Fix | Delete
return false;
[272] Fix | Delete
}
[273] Fix | Delete
[274] Fix | Delete
/**
[275] Fix | Delete
* Updates the IIS web.config file with the current rules if it is writable.
[276] Fix | Delete
* If the permalinks do not require rewrite rules then the rules are deleted from the web.config file.
[277] Fix | Delete
*
[278] Fix | Delete
* @since 2.8.0
[279] Fix | Delete
*
[280] Fix | Delete
* @global WP_Rewrite $wp_rewrite WordPress rewrite component.
[281] Fix | Delete
*
[282] Fix | Delete
* @return bool|null True on write success, false on failure. Null in multisite.
[283] Fix | Delete
*/
[284] Fix | Delete
function iis7_save_url_rewrite_rules() {
[285] Fix | Delete
if ( is_multisite() ) {
[286] Fix | Delete
return;
[287] Fix | Delete
}
[288] Fix | Delete
[289] Fix | Delete
global $wp_rewrite;
[290] Fix | Delete
[291] Fix | Delete
// Ensure get_home_path() is declared.
[292] Fix | Delete
require_once ABSPATH . 'wp-admin/includes/file.php';
[293] Fix | Delete
[294] Fix | Delete
$home_path = get_home_path();
[295] Fix | Delete
$web_config_file = $home_path . 'web.config';
[296] Fix | Delete
[297] Fix | Delete
// Using win_is_writable() instead of is_writable() because of a bug in Windows PHP.
[298] Fix | Delete
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 ) ) ) {
[299] Fix | Delete
$rule = $wp_rewrite->iis7_url_rewrite_rules( false );
[300] Fix | Delete
if ( ! empty( $rule ) ) {
[301] Fix | Delete
return iis7_add_rewrite_rule( $web_config_file, $rule );
[302] Fix | Delete
} else {
[303] Fix | Delete
return iis7_delete_rewrite_rule( $web_config_file );
[304] Fix | Delete
}
[305] Fix | Delete
}
[306] Fix | Delete
return false;
[307] Fix | Delete
}
[308] Fix | Delete
[309] Fix | Delete
/**
[310] Fix | Delete
* Update the "recently-edited" file for the plugin or theme editor.
[311] Fix | Delete
*
[312] Fix | Delete
* @since 1.5.0
[313] Fix | Delete
*
[314] Fix | Delete
* @param string $file
[315] Fix | Delete
*/
[316] Fix | Delete
function update_recently_edited( $file ) {
[317] Fix | Delete
$oldfiles = (array) get_option( 'recently_edited' );
[318] Fix | Delete
if ( $oldfiles ) {
[319] Fix | Delete
$oldfiles = array_reverse( $oldfiles );
[320] Fix | Delete
$oldfiles[] = $file;
[321] Fix | Delete
$oldfiles = array_reverse( $oldfiles );
[322] Fix | Delete
$oldfiles = array_unique( $oldfiles );
[323] Fix | Delete
if ( 5 < count( $oldfiles ) ) {
[324] Fix | Delete
array_pop( $oldfiles );
[325] Fix | Delete
}
[326] Fix | Delete
} else {
[327] Fix | Delete
$oldfiles[] = $file;
[328] Fix | Delete
}
[329] Fix | Delete
update_option( 'recently_edited', $oldfiles );
[330] Fix | Delete
}
[331] Fix | Delete
[332] Fix | Delete
/**
[333] Fix | Delete
* Makes a tree structure for the theme editor's file list.
[334] Fix | Delete
*
[335] Fix | Delete
* @since 4.9.0
[336] Fix | Delete
* @access private
[337] Fix | Delete
*
[338] Fix | Delete
* @param array $allowed_files List of theme file paths.
[339] Fix | Delete
* @return array Tree structure for listing theme files.
[340] Fix | Delete
*/
[341] Fix | Delete
function wp_make_theme_file_tree( $allowed_files ) {
[342] Fix | Delete
$tree_list = array();
[343] Fix | Delete
foreach ( $allowed_files as $file_name => $absolute_filename ) {
[344] Fix | Delete
$list = explode( '/', $file_name );
[345] Fix | Delete
$last_dir = &$tree_list;
[346] Fix | Delete
foreach ( $list as $dir ) {
[347] Fix | Delete
$last_dir =& $last_dir[ $dir ];
[348] Fix | Delete
}
[349] Fix | Delete
$last_dir = $file_name;
[350] Fix | Delete
}
[351] Fix | Delete
return $tree_list;
[352] Fix | Delete
}
[353] Fix | Delete
[354] Fix | Delete
/**
[355] Fix | Delete
* Outputs the formatted file list for the theme editor.
[356] Fix | Delete
*
[357] Fix | Delete
* @since 4.9.0
[358] Fix | Delete
* @access private
[359] Fix | Delete
*
[360] Fix | Delete
* @global string $relative_file Name of the file being edited relative to the
[361] Fix | Delete
* theme directory.
[362] Fix | Delete
* @global string $stylesheet The stylesheet name of the theme being edited.
[363] Fix | Delete
*
[364] Fix | Delete
* @param array|string $tree List of file/folder paths, or filename.
[365] Fix | Delete
* @param int $level The aria-level for the current iteration.
[366] Fix | Delete
* @param int $size The aria-setsize for the current iteration.
[367] Fix | Delete
* @param int $index The aria-posinset for the current iteration.
[368] Fix | Delete
*/
[369] Fix | Delete
function wp_print_theme_file_tree( $tree, $level = 2, $size = 1, $index = 1 ) {
[370] Fix | Delete
global $relative_file, $stylesheet;
[371] Fix | Delete
[372] Fix | Delete
if ( is_array( $tree ) ) {
[373] Fix | Delete
$index = 0;
[374] Fix | Delete
$size = count( $tree );
[375] Fix | Delete
foreach ( $tree as $label => $theme_file ) :
[376] Fix | Delete
$index++;
[377] Fix | Delete
if ( ! is_array( $theme_file ) ) {
[378] Fix | Delete
wp_print_theme_file_tree( $theme_file, $level, $index, $size );
[379] Fix | Delete
continue;
[380] Fix | Delete
}
[381] Fix | Delete
?>
[382] Fix | Delete
<li role="treeitem" aria-expanded="true" tabindex="-1"
[383] Fix | Delete
aria-level="<?php echo esc_attr( $level ); ?>"
[384] Fix | Delete
aria-setsize="<?php echo esc_attr( $size ); ?>"
[385] Fix | Delete
aria-posinset="<?php echo esc_attr( $index ); ?>">
[386] Fix | Delete
<span class="folder-label"><?php echo esc_html( $label ); ?> <span class="screen-reader-text"><?php _e( 'folder' ); ?></span><span aria-hidden="true" class="icon"></span></span>
[387] Fix | Delete
<ul role="group" class="tree-folder"><?php wp_print_theme_file_tree( $theme_file, $level + 1, $index, $size ); ?></ul>
[388] Fix | Delete
</li>
[389] Fix | Delete
<?php
[390] Fix | Delete
endforeach;
[391] Fix | Delete
} else {
[392] Fix | Delete
$filename = $tree;
[393] Fix | Delete
$url = add_query_arg(
[394] Fix | Delete
array(
[395] Fix | Delete
'file' => rawurlencode( $tree ),
[396] Fix | Delete
'theme' => rawurlencode( $stylesheet ),
[397] Fix | Delete
),
[398] Fix | Delete
self_admin_url( 'theme-editor.php' )
[399] Fix | Delete
);
[400] Fix | Delete
?>
[401] Fix | Delete
<li role="none" class="<?php echo esc_attr( $relative_file === $filename ? 'current-file' : '' ); ?>">
[402] Fix | Delete
<a role="treeitem" tabindex="<?php echo esc_attr( $relative_file === $filename ? '0' : '-1' ); ?>"
[403] Fix | Delete
href="<?php echo esc_url( $url ); ?>"
[404] Fix | Delete
aria-level="<?php echo esc_attr( $level ); ?>"
[405] Fix | Delete
aria-setsize="<?php echo esc_attr( $size ); ?>"
[406] Fix | Delete
aria-posinset="<?php echo esc_attr( $index ); ?>">
[407] Fix | Delete
<?php
[408] Fix | Delete
$file_description = esc_html( get_file_description( $filename ) );
[409] Fix | Delete
if ( $file_description !== $filename && wp_basename( $filename ) !== $file_description ) {
[410] Fix | Delete
$file_description .= '<br /><span class="nonessential">(' . esc_html( $filename ) . ')</span>';
[411] Fix | Delete
}
[412] Fix | Delete
[413] Fix | Delete
if ( $relative_file === $filename ) {
[414] Fix | Delete
echo '<span class="notice notice-info">' . $file_description . '</span>';
[415] Fix | Delete
} else {
[416] Fix | Delete
echo $file_description;
[417] Fix | Delete
}
[418] Fix | Delete
?>
[419] Fix | Delete
</a>
[420] Fix | Delete
</li>
[421] Fix | Delete
<?php
[422] Fix | Delete
}
[423] Fix | Delete
}
[424] Fix | Delete
[425] Fix | Delete
/**
[426] Fix | Delete
* Makes a tree structure for the plugin editor's file list.
[427] Fix | Delete
*
[428] Fix | Delete
* @since 4.9.0
[429] Fix | Delete
* @access private
[430] Fix | Delete
*
[431] Fix | Delete
* @param array $plugin_editable_files List of plugin file paths.
[432] Fix | Delete
* @return array Tree structure for listing plugin files.
[433] Fix | Delete
*/
[434] Fix | Delete
function wp_make_plugin_file_tree( $plugin_editable_files ) {
[435] Fix | Delete
$tree_list = array();
[436] Fix | Delete
foreach ( $plugin_editable_files as $plugin_file ) {
[437] Fix | Delete
$list = explode( '/', preg_replace( '#^.+?/#', '', $plugin_file ) );
[438] Fix | Delete
$last_dir = &$tree_list;
[439] Fix | Delete
foreach ( $list as $dir ) {
[440] Fix | Delete
$last_dir =& $last_dir[ $dir ];
[441] Fix | Delete
}
[442] Fix | Delete
$last_dir = $plugin_file;
[443] Fix | Delete
}
[444] Fix | Delete
return $tree_list;
[445] Fix | Delete
}
[446] Fix | Delete
[447] Fix | Delete
/**
[448] Fix | Delete
* Outputs the formatted file list for the plugin editor.
[449] Fix | Delete
*
[450] Fix | Delete
* @since 4.9.0
[451] Fix | Delete
* @access private
[452] Fix | Delete
*
[453] Fix | Delete
* @param array|string $tree List of file/folder paths, or filename.
[454] Fix | Delete
* @param string $label Name of file or folder to print.
[455] Fix | Delete
* @param int $level The aria-level for the current iteration.
[456] Fix | Delete
* @param int $size The aria-setsize for the current iteration.
[457] Fix | Delete
* @param int $index The aria-posinset for the current iteration.
[458] Fix | Delete
*/
[459] Fix | Delete
function wp_print_plugin_file_tree( $tree, $label = '', $level = 2, $size = 1, $index = 1 ) {
[460] Fix | Delete
global $file, $plugin;
[461] Fix | Delete
if ( is_array( $tree ) ) {
[462] Fix | Delete
$index = 0;
[463] Fix | Delete
$size = count( $tree );
[464] Fix | Delete
foreach ( $tree as $label => $plugin_file ) :
[465] Fix | Delete
$index++;
[466] Fix | Delete
if ( ! is_array( $plugin_file ) ) {
[467] Fix | Delete
wp_print_plugin_file_tree( $plugin_file, $label, $level, $index, $size );
[468] Fix | Delete
continue;
[469] Fix | Delete
}
[470] Fix | Delete
?>
[471] Fix | Delete
<li role="treeitem" aria-expanded="true" tabindex="-1"
[472] Fix | Delete
aria-level="<?php echo esc_attr( $level ); ?>"
[473] Fix | Delete
aria-setsize="<?php echo esc_attr( $size ); ?>"
[474] Fix | Delete
aria-posinset="<?php echo esc_attr( $index ); ?>">
[475] Fix | Delete
<span class="folder-label"><?php echo esc_html( $label ); ?> <span class="screen-reader-text"><?php _e( 'folder' ); ?></span><span aria-hidden="true" class="icon"></span></span>
[476] Fix | Delete
<ul role="group" class="tree-folder"><?php wp_print_plugin_file_tree( $plugin_file, '', $level + 1, $index, $size ); ?></ul>
[477] Fix | Delete
</li>
[478] Fix | Delete
<?php
[479] Fix | Delete
endforeach;
[480] Fix | Delete
} else {
[481] Fix | Delete
$url = add_query_arg(
[482] Fix | Delete
array(
[483] Fix | Delete
'file' => rawurlencode( $tree ),
[484] Fix | Delete
'plugin' => rawurlencode( $plugin ),
[485] Fix | Delete
),
[486] Fix | Delete
self_admin_url( 'plugin-editor.php' )
[487] Fix | Delete
);
[488] Fix | Delete
?>
[489] Fix | Delete
<li role="none" class="<?php echo esc_attr( $file === $tree ? 'current-file' : '' ); ?>">
[490] Fix | Delete
<a role="treeitem" tabindex="<?php echo esc_attr( $file === $tree ? '0' : '-1' ); ?>"
[491] Fix | Delete
href="<?php echo esc_url( $url ); ?>"
[492] Fix | Delete
aria-level="<?php echo esc_attr( $level ); ?>"
[493] Fix | Delete
aria-setsize="<?php echo esc_attr( $size ); ?>"
[494] Fix | Delete
aria-posinset="<?php echo esc_attr( $index ); ?>">
[495] Fix | Delete
<?php
[496] Fix | Delete
if ( $file === $tree ) {
[497] Fix | Delete
echo '<span class="notice notice-info">' . esc_html( $label ) . '</span>';
[498] Fix | Delete
} else {
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function