Code cleanup: wp-includes/theme.php
git-svn-id: http://svn.automattic.com/wordpress/trunk@4392 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
a4b132aeba
commit
cd5cb736ec
|
@ -88,8 +88,7 @@ function get_theme_data($theme_file) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_themes() {
|
function get_themes() {
|
||||||
global $wp_themes;
|
global $wp_themes, $wp_broken_themes;
|
||||||
global $wp_broken_themes;
|
|
||||||
|
|
||||||
if ( isset($wp_themes) )
|
if ( isset($wp_themes) )
|
||||||
return $wp_themes;
|
return $wp_themes;
|
||||||
|
@ -104,9 +103,8 @@ function get_themes() {
|
||||||
if ( $themes_dir ) {
|
if ( $themes_dir ) {
|
||||||
while ( ($theme_dir = $themes_dir->read()) !== false ) {
|
while ( ($theme_dir = $themes_dir->read()) !== false ) {
|
||||||
if ( is_dir($theme_root . '/' . $theme_dir) && is_readable($theme_root . '/' . $theme_dir) ) {
|
if ( is_dir($theme_root . '/' . $theme_dir) && is_readable($theme_root . '/' . $theme_dir) ) {
|
||||||
if ( $theme_dir{0} == '.' || $theme_dir == '..' || $theme_dir == 'CVS' ) {
|
if ( $theme_dir{0} == '.' || $theme_dir == '..' || $theme_dir == 'CVS' )
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
$stylish_dir = @ dir($theme_root . '/' . $theme_dir);
|
$stylish_dir = @ dir($theme_root . '/' . $theme_dir);
|
||||||
$found_stylesheet = false;
|
$found_stylesheet = false;
|
||||||
while ( ($theme_file = $stylish_dir->read()) !== false ) {
|
while ( ($theme_file = $stylish_dir->read()) !== false ) {
|
||||||
|
@ -116,20 +114,18 @@ function get_themes() {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( !$found_stylesheet ) {
|
if ( !$found_stylesheet )
|
||||||
$wp_broken_themes[$theme_dir] = array('Name' => $theme_dir, 'Title' => $theme_dir, 'Description' => __('Stylesheet is missing.'));
|
$wp_broken_themes[$theme_dir] = array('Name' => $theme_dir, 'Title' => $theme_dir, 'Description' => __('Stylesheet is missing.'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if ( !$themes_dir || !$theme_files ) {
|
if ( !$themes_dir || !$theme_files )
|
||||||
return $themes;
|
return $themes;
|
||||||
}
|
|
||||||
|
|
||||||
sort($theme_files);
|
sort($theme_files);
|
||||||
|
|
||||||
foreach($theme_files as $theme_file) {
|
foreach ( (array) $theme_files as $theme_file ) {
|
||||||
if ( !is_readable("$theme_root/$theme_file") ) {
|
if ( !is_readable("$theme_root/$theme_file") ) {
|
||||||
$wp_broken_themes[$theme_file] = array('Name' => $theme_file, 'Title' => $theme_file, 'Description' => __('File not readable.'));
|
$wp_broken_themes[$theme_file] = array('Name' => $theme_file, 'Title' => $theme_file, 'Description' => __('File not readable.'));
|
||||||
continue;
|
continue;
|
||||||
|
@ -158,12 +154,11 @@ function get_themes() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( empty($template) ) {
|
if ( empty($template) ) {
|
||||||
if ( file_exists(dirname("$theme_root/$theme_file/index.php")) ) {
|
if ( file_exists(dirname("$theme_root/$theme_file/index.php")) )
|
||||||
$template = dirname($theme_file);
|
$template = dirname($theme_file);
|
||||||
} else {
|
else
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
$template = trim($template);
|
$template = trim($template);
|
||||||
|
|
||||||
|
@ -222,10 +217,10 @@ function get_themes() {
|
||||||
// Resolve theme dependencies.
|
// Resolve theme dependencies.
|
||||||
$theme_names = array_keys($themes);
|
$theme_names = array_keys($themes);
|
||||||
|
|
||||||
foreach ($theme_names as $theme_name) {
|
foreach ( (array) $theme_names as $theme_name ) {
|
||||||
$themes[$theme_name]['Parent Theme'] = '';
|
$themes[$theme_name]['Parent Theme'] = '';
|
||||||
if ( $themes[$theme_name]['Stylesheet'] != $themes[$theme_name]['Template'] ) {
|
if ( $themes[$theme_name]['Stylesheet'] != $themes[$theme_name]['Template'] ) {
|
||||||
foreach ($theme_names as $parent_theme_name) {
|
foreach ( (array) $theme_names as $parent_theme_name ) {
|
||||||
if ( ($themes[$parent_theme_name]['Stylesheet'] == $themes[$parent_theme_name]['Template']) && ($themes[$parent_theme_name]['Template'] == $themes[$theme_name]['Template']) ) {
|
if ( ($themes[$parent_theme_name]['Stylesheet'] == $themes[$parent_theme_name]['Template']) && ($themes[$parent_theme_name]['Template'] == $themes[$theme_name]['Template']) ) {
|
||||||
$themes[$theme_name]['Parent Theme'] = $themes[$parent_theme_name]['Name'];
|
$themes[$theme_name]['Parent Theme'] = $themes[$parent_theme_name]['Name'];
|
||||||
break;
|
break;
|
||||||
|
@ -256,7 +251,7 @@ function get_current_theme() {
|
||||||
$current_theme = 'WordPress Default';
|
$current_theme = 'WordPress Default';
|
||||||
|
|
||||||
if ( $themes ) {
|
if ( $themes ) {
|
||||||
foreach ($theme_names as $theme_name) {
|
foreach ( (array) $theme_names as $theme_name ) {
|
||||||
if ( $themes[$theme_name]['Stylesheet'] == $current_stylesheet &&
|
if ( $themes[$theme_name]['Stylesheet'] == $current_stylesheet &&
|
||||||
$themes[$theme_name]['Template'] == $current_template ) {
|
$themes[$theme_name]['Template'] == $current_template ) {
|
||||||
$current_theme = $themes[$theme_name]['Name'];
|
$current_theme = $themes[$theme_name]['Name'];
|
||||||
|
@ -395,14 +390,14 @@ function validate_current_theme() {
|
||||||
if ( defined('WP_INSTALLING') )
|
if ( defined('WP_INSTALLING') )
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if ((get_template() != 'default') && (!file_exists(get_template_directory() . '/index.php'))) {
|
if ( get_template() != 'default' && !file_exists(get_template_directory() . '/index.php') ) {
|
||||||
update_option('template', 'default');
|
update_option('template', 'default');
|
||||||
update_option('stylesheet', 'default');
|
update_option('stylesheet', 'default');
|
||||||
do_action('switch_theme', 'Default');
|
do_action('switch_theme', 'Default');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((get_stylesheet() != 'default') && (!file_exists(get_template_directory() . '/style.css'))) {
|
if ( get_stylesheet() != 'default' && !file_exists(get_template_directory() . '/style.css') ) {
|
||||||
update_option('template', 'default');
|
update_option('template', 'default');
|
||||||
update_option('stylesheet', 'default');
|
update_option('stylesheet', 'default');
|
||||||
do_action('switch_theme', 'Default');
|
do_action('switch_theme', 'Default');
|
||||||
|
|
Loading…
Reference in New Issue