wp_make_theme_file_tree()
云策文档标注
概述
wp_make_theme_file_tree() 函数用于为主题文件编辑器生成文件列表的树形结构。它接收一个允许的文件路径数组,并返回一个嵌套数组表示的树结构。
关键要点
- 参数 $allowed_files 是一个必需数组,包含主题文件路径列表。
- 返回一个数组,表示用于列出主题文件的树形结构。
- 该函数从 WordPress 4.9.0 版本开始引入。
代码示例
function wp_make_theme_file_tree( $allowed_files ) {
$tree_list = array();
foreach ( $allowed_files as $file_name => $absolute_filename ) {
$list = explode( '/', $file_name );
$last_dir = &$tree_list;
foreach ( $list as $dir ) {
$last_dir =& $last_dir[ $dir ];
}
$last_dir = $file_name;
}
return $tree_list;
}
原文内容
Makes a tree structure for the theme file editor’s file list.
Parameters
$allowed_filesarrayrequired-
List of theme file paths.
Source
function wp_make_theme_file_tree( $allowed_files ) {
$tree_list = array();
foreach ( $allowed_files as $file_name => $absolute_filename ) {
$list = explode( '/', $file_name );
$last_dir = &$tree_list;
foreach ( $list as $dir ) {
$last_dir =& $last_dir[ $dir ];
}
$last_dir = $file_name;
}
return $tree_list;
}
Changelog
| Version | Description |
|---|---|
| 4.9.0 | Introduced. |