Ticket #22924: 22924.3.diff
File 22924.3.diff, 4.0 KB (added by , 9 years ago) |
---|
-
src/wp-admin/theme-editor.php
61 61 wp_die( __( 'The requested theme does not exist.' ) . ' ' . $theme->errors()->get_error_message() ); 62 62 } 63 63 64 $allowed_files = $theme->get_files( 'php', 1 ); 65 $has_templates = ! empty( $allowed_files ); 66 $style_files = $theme->get_files( 'css' ); 67 $allowed_files['style.css'] = $style_files['style.css']; 64 $allowed_files = $style_files = array(); 65 $has_templates = false; 66 68 67 /** 69 * Filter the allowed files.68 * Filter the list of file types allowed for editing in the Theme editor. 70 69 * 71 70 * @since 4.4.0 72 71 * 73 * @param array $style_files List of style files.72 * @param array $style_files List of file types. Default types include 'php' and 'css'. 74 73 * @param object $theme The current Theme object. 75 74 */ 76 $ allowed_files += apply_filters( 'wp_theme_editor_filetypes', $style_files, $theme );75 $file_types = apply_filters( 'wp_theme_editor_filetypes', array( 'php', 'css', 'txt' ), $theme ); 77 76 77 $file_types = array_merge( $file_types, array( 'php', 'css' ) ); 78 79 foreach ( $file_types as $type ) { 80 switch ( $type ) { 81 case 'php': 82 $allowed_files += $theme->get_files( 'php', 1 ); 83 $has_templates = ! empty( $allowed_files ); 84 break; 85 case 'css': 86 $style_files = $theme->get_files( 'css' ); 87 $allowed_files['style.css'] = $style_files['style.css']; 88 $allowed_files += $style_files; 89 break; 90 default: 91 $allowed_files += $theme->get_files( $type ); 92 break; 93 } 94 } 95 78 96 if ( empty( $file ) ) { 79 97 $relative_file = 'style.css'; 80 98 $file = $allowed_files['style.css']; … … 174 192 <div id="templateside"> 175 193 <?php 176 194 if ( $allowed_files ) : 177 if ( $has_templates || $theme->parent() ) : 178 ?> 179 <h2><?php _e( 'Templates' ); ?></h2> 180 <?php if ( $theme->parent() ) : ?> 181 <p class="howto"><?php printf( __( 'This child theme inherits templates from a parent theme, %s.' ), '<a href="' . self_admin_url('theme-editor.php?theme=' . urlencode( $theme->get_template() ) ) . '">' . $theme->parent()->display('Name') . '</a>' ); ?></p> 182 <?php endif; ?> 183 <ul> 184 <?php 185 endif; 195 $previous_file_type = ''; 186 196 187 197 foreach ( $allowed_files as $filename => $absolute_filename ) : 188 if ( 'style.css' == $filename ) 189 echo "\t</ul>\n\t<h2>" . _x( 'Styles', 'Theme stylesheets in theme editor' ) . "</h2>\n\t<ul>\n"; 198 $file_type = substr( $filename, strrpos( $filename, '.' ) ); 190 199 200 if ( $file_type !== $previous_file_type ) { 201 if ( '' !== $previous_file_type ) { 202 echo "\t</ul>\n"; 203 } 204 205 switch ( $file_type ) { 206 case '.php': 207 if ( $has_templates || $theme->parent() ) : 208 echo "\t<h2>" . __( 'Templates' ) . "</h2>\n"; 209 if ( $theme->parent() ) { 210 echo '<p class="howto">' . sprintf( __( 'This child theme inherits templates from a parent theme, %s.' ), 211 sprintf( '<a href="%s">%s</a>', 212 self_admin_url( 'theme-editor.php?theme=' . urlencode( $theme->get_template() ) ), 213 $theme->parent()->display( 'Name' ) 214 ) 215 ) . "</p>\n"; 216 } 217 endif; 218 break; 219 case '.css': 220 echo "\t<h2>" . _x( 'Styles', 'Theme stylesheets in theme editor' ) . "</h2>\n"; 221 break; 222 default: 223 /* translators: %s: file extension */ 224 echo "\t<h2>" . sprintf( __( '%s files' ), $file_type ) . "</h2>\n"; 225 break; 226 } 227 228 echo "\t<ul>\n"; 229 } 230 191 231 $file_description = get_file_description( $filename ); 192 232 if ( $filename !== basename( $absolute_filename ) || $file_description !== $filename ) { 193 233 $file_description .= '<br /><span class="nonessential">(' . $filename . ')</span>'; … … 196 236 if ( $absolute_filename === $file ) { 197 237 $file_description = '<span class="highlight">' . $file_description . '</span>'; 198 238 } 239 240 $previous_file_type = $file_type; 199 241 ?> 200 242 <li><a href="theme-editor.php?file=<?php echo urlencode( $filename ) ?>&theme=<?php echo urlencode( $stylesheet ) ?>"><?php echo $file_description; ?></a></li> 201 243 <?php