さあ、プラグインの形で行きましょう:)
ノート
プラグイン
<?php
/*
Plugin Name: List Files in Custom Folder
Plugin URI: https://stackoverflow.com/q/13416177/1287812
Description: Add a Media page where the contents of a custom folder are listed as "<a>Filename</a> - Size"
Author: Rodolfo Buaiz
Author URI: http://wordpress.stackexchange.com/users/12615/brasofilo
Version: 1.0
License: GPL
*/
add_action( 'admin_menu', 'so_13416177_folder_menu' );
function so_13416177_folder_menu()
{
add_media_page(
'Custom Folder Media',
'Custom Folder',
'delete_plugins',
'so-13416177',
'so_13416177_display_page'
);
}
function so_13416177_display_page()
{
$baseDir = WP_CONTENT_DIR . '/custom';
$baseUrl = WP_CONTENT_URL . '/custom/';
$files = array();
if ( $dir = opendir( $baseDir ) )
{
while ( $file = readdir( $dir ) )
{
if ( $file != "." && $file != '..' )
{
if ( !is_dir( $baseDir . "/" . $file ) )
{
// Hide files that start with a dot
if( !so_834303_starts_with( $file, '.' ) )
{
$size = so_13416177_file_size(
filesize( $baseDir . "/" . $file )
);
$files[] = array( $file, $size );
}
}
}
}
closedir($dir);
}
?><div id="icon-upload" class="icon32"></div><h2>Custom Folder</h2><?php
if ( empty( $files ) )
{
echo '<p>No files!</p>';
break;
}
?>
<table class="widefat">
<thead>
<tr>
<th>File</th>
<th>Size</th>
</tr>
</thead>
<tfoot>
<tr>
<th>File</th>
<th>Size</th>
</tr>
</tfoot>
<tbody>
<?php
foreach ($files as $file)
{
?>
<tr>
<td>
<a href="<?php echo $baseUrl.$file[0]; ?>">
<?php echo $file[0]; ?>
</a>
</td>
<td><b><?php echo $file[1]; ?></b></td>
</tr>
<?php
}
?>
</tbody>
</table>
<?php
}
// https://stackoverflow.com/q/834303
function so_834303_starts_with( $haystack, $needle )
{
return !strncmp( $haystack, $needle, strlen( $needle ) );
}
// http://www.php.net/manual/en/function.filesize.php#110739
function so_13416177_file_size( $o, $depth=0 )
{
if( $o > 1024 )
return so_13416177_file_size( $o/1024, $depth+1 );
$unit = array( 'B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'PB', 'ZB', 'YB' );
return sprintf( '%.01f %s', $o, $unit[$depth] );
}
PS。
ユーザーに読み取り専用権限を付与するには、役割を に設定しSubscriber
ます。