X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/8ab4a4532479e8db471032b51042ec8c4716d091..b925718b4bf2dd47a8429f844d0a255ca6e35bd1:/wp-admin/theme-editor.php diff --git a/wp-admin/theme-editor.php b/wp-admin/theme-editor.php index e0ca475b..6fae2b75 100644 --- a/wp-admin/theme-editor.php +++ b/wp-admin/theme-editor.php @@ -25,7 +25,7 @@ get_current_screen()->add_help_tab( array( 'title' => __('Overview'), 'content' => '

' . __('You can use the Theme Editor to edit the individual CSS and PHP files which make up your theme.') . '

-

' . __('Begin by choosing a theme to edit from the dropdown menu and clicking Select. A list then appears of all the template files. Clicking once on any file name causes the file to appear in the large Editor box.') . '

+

' . __("Begin by choosing a theme to edit from the dropdown menu and clicking Select. A list then appears of the theme's template files. Clicking once on any file name causes the file to appear in the large Editor box.") . '

' . __('For PHP files, you can use the Documentation dropdown to select from functions recognized in that file. Look Up takes you to a web page with reference material about that particular function.') . '

' . __( 'In the editing area the Tab key enters a tab character. To move below this area by pressing Tab, press the Esc key followed by the Tab key. In some cases the Esc key will need to be pressed twice before the Tab key will allow you to continue.' ) . '

' . __('After typing in your edits, click Update File.') . '

@@ -45,24 +45,55 @@ get_current_screen()->set_help_sidebar( wp_reset_vars( array( 'action', 'error', 'file', 'theme' ) ); -if ( $theme ) +if ( $theme ) { $stylesheet = $theme; -else +} else { $stylesheet = get_stylesheet(); +} $theme = wp_get_theme( $stylesheet ); -if ( ! $theme->exists() ) +if ( ! $theme->exists() ) { wp_die( __( 'The requested theme does not exist.' ) ); +} -if ( $theme->errors() && 'theme_no_stylesheet' == $theme->errors()->get_error_code() ) +if ( $theme->errors() && 'theme_no_stylesheet' == $theme->errors()->get_error_code() ) { wp_die( __( 'The requested theme does not exist.' ) . ' ' . $theme->errors()->get_error_message() ); +} + +$allowed_files = $style_files = array(); +$has_templates = false; +$default_types = array( 'php', 'css' ); -$allowed_files = $theme->get_files( 'php', 1 ); -$has_templates = ! empty( $allowed_files ); -$style_files = $theme->get_files( 'css' ); -$allowed_files['style.css'] = $style_files['style.css']; -$allowed_files += $style_files; +/** + * Filter the list of file types allowed for editing in the Theme editor. + * + * @since 4.4.0 + * + * @param array $default_types List of file types. Default types include 'php' and 'css'. + * @param WP_Theme $theme The current Theme object. + */ +$file_types = apply_filters( 'wp_theme_editor_filetypes', $default_types, $theme ); + +// Ensure that default types are still there. +$file_types = array_unique( array_merge( $file_types, $default_types ) ); + +foreach ( $file_types as $type ) { + switch ( $type ) { + case 'php': + $allowed_files += $theme->get_files( 'php', 1 ); + $has_templates = ! empty( $allowed_files ); + break; + case 'css': + $style_files = $theme->get_files( 'css' ); + $allowed_files['style.css'] = $style_files['style.css']; + $allowed_files += $style_files; + break; + default: + $allowed_files += $theme->get_files( $type ); + break; + } +} if ( empty( $file ) ) { $relative_file = 'style.css'; @@ -125,17 +156,17 @@ default:

(' . $file_show . ')'; ?>
-

+

-

display('Name'); if ( $description ) echo ': ' . $description; ?>

+

display( 'Name' ); if ( $description ) echo ': ' . $description; ?>

@@ -163,26 +194,52 @@ if ( $theme->errors() )
parent() ) : -?> -

- parent() ) : ?> -

get_template() ) ) . '">' . $theme->parent()->display('Name') . '' ); ?>

- -
    - $absolute_filename ) : - if ( 'style.css' == $filename ) - echo "\t
\n\t

" . _x( 'Styles', 'Theme stylesheets in theme editor' ) . "

\n\t
    \n"; + $file_type = substr( $filename, strrpos( $filename, '.' ) ); - $file_description = get_file_description( $absolute_filename ); - if ( $file_description != basename( $filename ) ) + if ( $file_type !== $previous_file_type ) { + if ( '' !== $previous_file_type ) { + echo "\t
\n"; + } + + switch ( $file_type ) { + case '.php': + if ( $has_templates || $theme->parent() ) : + echo "\t

" . __( 'Templates' ) . "

\n"; + if ( $theme->parent() ) { + echo '

' . sprintf( __( 'This child theme inherits templates from a parent theme, %s.' ), + sprintf( '%s', + self_admin_url( 'theme-editor.php?theme=' . urlencode( $theme->get_template() ) ), + $theme->parent()->display( 'Name' ) + ) + ) . "

\n"; + } + endif; + break; + case '.css': + echo "\t

" . _x( 'Styles', 'Theme stylesheets in theme editor' ) . "

\n"; + break; + default: + /* translators: %s: file extension */ + echo "\t

" . sprintf( __( '%s files' ), $file_type ) . "

\n"; + break; + } + + echo "\t
    \n"; + } + + $file_description = get_file_description( $filename ); + if ( $filename !== basename( $absolute_filename ) || $file_description !== $filename ) { $file_description .= '
    (' . $filename . ')'; + } - if ( $absolute_filename == $file ) + if ( $absolute_filename === $file ) { $file_description = '' . $file_description . ''; + } + + $previous_file_type = $file_type; ?>
  • - +