<子>Updated plugin version available at GitHub.
我第一次看到你的问题是在[wp-hackers] list, 并且,在实施解决方案后,即将发布一个Q&;这是我的荣幸。嗯,它已经在这里了,上面有悬赏金:)
像Daniel Bachhuber 在线程中指出:
WordPress。com将主题放在子目录中
/wp-content/themes/public
/wp-content/themes/premium
我提出此解决方案是为了在后端显示:
在多站点中,我们可以在主题屏幕中添加一列,并使用manage_themes_custom_column
和manage_themes-network_columns
.
在单站点安装中,我找到的唯一入口是theme_action_links
.
<?php
/**
* Plugin Name: Theme Folders Categories
* Plugin URI: http://wordpress.stackexchange.com/q/96361/12615
* Version: 1.0
* Author: Rodolfo Buaiz
* Author URI: http://wordpress.stackexchange.com/users/12615/brasofilo
* License: GPLv2 or later
*/
class WPhackersSE_Theme_Folders
{
public function __construct()
{
add_action( \'plugins_loaded\', array( $this, \'start_up\' ) );
}
/**
* Hooks for Network themes and Single Site themes
* Nothing happens on sub-sites of a Network
*/
public function start_up()
{
if( is_network_admin() )
{
add_filter( \'manage_themes-network_columns\', array( $this, \'column_register\' ) );
add_action( \'manage_themes_custom_column\', array( $this, \'column_display\' ), 10, 3 );
add_action( \'admin_head-themes.php\', array( $this, \'network_theme_category_css\' ) );
}
elseif( !is_multisite() )
{
add_filter( \'theme_action_links\', array( $this, \'theme_folder_single_site\' ), 10, 2 );
add_action( \'admin_head-themes.php\', array( $this, \'theme_category_css\' ) );
}
}
/**
* Add custom category (folder) column in network themes
*
* @param array $columns
* @return array
*/
public function column_register( $columns )
{
$columns[\'theme_folder\'] = \'Category\';
return $columns;
}
/**
* Display custom row in network themes
* $stylesheet contains a string "folder/theme_name"
* $theme is a WP_Theme object
*
* @param string $column_name
* @param string $stylesheet
* @param object $theme
* @return string
*/
public function column_display( $column_name, $stylesheet, $theme )
{
if( \'theme_folder\' != $column_name )
return;
echo $this->make_button( $stylesheet );
}
/**
* Adjust column width and button style in Multisite screen
*/
public function network_theme_category_css()
{
echo "<style type=\'text/css\'>
#theme_folder { width: 10% }
{$this->button_style()}
</style>";
}
/**
* Show theme category (folder) in single site theme action row
* $theme is a WP_Theme object
*
* @param array $actions
* @param object $theme
* @return array
*/
public function theme_folder_single_site( $actions, $theme )
{
array_unshift( $actions, $this->make_button( $theme->stylesheet ) );
return $actions;
}
/**
* Adjust button style in Single site screen
*/
public function theme_category_css()
{
echo "<style type=\'text/css\'>{$this->button_style()}</style>";
}
/**
* Common button for Multi and Single sites
* The category name is extracted from a string "folder/themefolder"
*
* @param object $theme
* @return string
*/
private function make_button( $stylesheet )
{
$button_category = sprintf(
\'<a href="javascript:void(0)" class="button-secondary theme-folder" title="%1$s">%1$s</a>\',
dirname( $stylesheet )
);
return $button_category;
}
/**
* Common style for Multi and Single sites
*
* @return string
*/
private function button_style()
{
return \'.theme-folder {
cursor: default !important;
line-height: 15px !important;
height: 17px !important;
background-image: -webkit-gradient(linear, left top, left bottom, from(#DCFEDE), to(#CBEBCD)) !important;
background-image: -webkit-linear-gradient(top, #DCFEDE, #CBEBCD) !important;
background-image: -moz-linear-gradient(top, #DCFEDE, #CBEBCD) !important;
background-image: -o-linear-gradient(top, #DCFEDE, #CBEBCD) !important;
background-image: linear-gradient(to bottom, #DCFEDE, #CBEBCD) !important;
}\';
}
}
new WPhackersSE_Theme_Folders;
<小时/>
Result in Multisite:
文件夹
/themes/clientes/
和
/themes/brasofilo/
). 网络的子站点中没有输出。
很可能在这里添加一个过滤器。
<小时/>Result in a single site:
未启用多站点。文件夹/themes/defaults/
和/themes/others/
.
这个屏幕在定制方面确实有限。我同意@Ralf912分析。
Important note:将活动主题移动到子文件夹后,所有网站都会丢失其主题配置,
each site theme has to be set again。