Changeset 42343 for trunk/src/wp-admin/theme-editor.php
- Timestamp:
- 11/30/2017 11:09:33 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/theme-editor.php
r42247 r42343 15 15 } 16 16 17 if ( !current_user_can('edit_themes') ) 18 wp_die('<p>'.__('Sorry, you are not allowed to edit templates for this site.').'</p>'); 19 20 $title = __("Edit Themes"); 17 if ( ! current_user_can( 'edit_themes' ) ) { 18 wp_die( '<p>' . __( 'Sorry, you are not allowed to edit templates for this site.' ) . '</p>' ); 19 } 20 21 $title = __( 'Edit Themes' ); 21 22 $parent_file = 'themes.php'; 22 23 23 get_current_screen()->add_help_tab( array( 24 'id' => 'overview', 25 'title' => __('Overview'), 26 'content' => 27 '<p>' . __( 'You can use the Theme Editor to edit the individual CSS and PHP files which make up your theme.' ) . '</p>' . 28 '<p>' . __( 'Begin by choosing a theme to edit from the dropdown menu and clicking the Select button. 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.' ) . '</p>' . 29 '<p>' . __( '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.' ) . '</p>' . 30 '<p id="editor-keyboard-trap-help-1">' . __( 'When using a keyboard to navigate:' ) . '</p>' . 31 '<ul>' . 32 '<li id="editor-keyboard-trap-help-2">' . __( 'In the editing area, the Tab key enters a tab character.' ) . '</li>' . 33 '<li id="editor-keyboard-trap-help-3">' . __( 'To move away from this area, press the Esc key followed by the Tab key.' ) . '</li>' . 34 '<li id="editor-keyboard-trap-help-4">' . __( 'Screen reader users: when in forms mode, you may need to press the Esc key twice.' ) . '</li>' . 35 '</ul>' . 36 '<p>' . __( 'After typing in your edits, click Update File.' ) . '</p>' . 37 '<p>' . __( '<strong>Advice:</strong> think very carefully about your site crashing if you are live-editing the theme currently in use.' ) . '</p>' . 38 /* translators: %s: link to codex article about child themes */ 39 '<p>' . sprintf( __( 'Upgrading to a newer version of the same theme will override changes made here. To avoid this, consider creating a <a href="%s">child theme</a> instead.' ), __( 'https://codex.wordpress.org/Child_Themes' ) ) . '</p>' . 40 ( is_network_admin() ? '<p>' . __( 'Any edits to files from this screen will be reflected on all sites in the network.' ) . '</p>' : '' ), 41 ) ); 24 get_current_screen()->add_help_tab( 25 array( 26 'id' => 'overview', 27 'title' => __( 'Overview' ), 28 'content' => 29 '<p>' . __( 'You can use the Theme Editor to edit the individual CSS and PHP files which make up your theme.' ) . '</p>' . 30 '<p>' . __( 'Begin by choosing a theme to edit from the dropdown menu and clicking the Select button. 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.' ) . '</p>' . 31 '<p>' . __( '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.' ) . '</p>' . 32 '<p id="editor-keyboard-trap-help-1">' . __( 'When using a keyboard to navigate:' ) . '</p>' . 33 '<ul>' . 34 '<li id="editor-keyboard-trap-help-2">' . __( 'In the editing area, the Tab key enters a tab character.' ) . '</li>' . 35 '<li id="editor-keyboard-trap-help-3">' . __( 'To move away from this area, press the Esc key followed by the Tab key.' ) . '</li>' . 36 '<li id="editor-keyboard-trap-help-4">' . __( 'Screen reader users: when in forms mode, you may need to press the Esc key twice.' ) . '</li>' . 37 '</ul>' . 38 '<p>' . __( 'After typing in your edits, click Update File.' ) . '</p>' . 39 '<p>' . __( '<strong>Advice:</strong> think very carefully about your site crashing if you are live-editing the theme currently in use.' ) . '</p>' . 40 /* translators: %s: link to codex article about child themes */ 41 '<p>' . sprintf( __( 'Upgrading to a newer version of the same theme will override changes made here. To avoid this, consider creating a <a href="%s">child theme</a> instead.' ), __( 'https://codex.wordpress.org/Child_Themes' ) ) . '</p>' . 42 ( is_network_admin() ? '<p>' . __( 'Any edits to files from this screen will be reflected on all sites in the network.' ) . '</p>' : '' ), 43 ) 44 ); 42 45 43 46 get_current_screen()->set_help_sidebar( 44 '<p><strong>' . __( 'For more information:') . '</strong></p>' .45 '<p>' . __( '<a href="https://codex.wordpress.org/Theme_Development">Documentation on Theme Development</a>') . '</p>' .46 '<p>' . __( '<a href="https://codex.wordpress.org/Using_Themes">Documentation on Using Themes</a>') . '</p>' .47 '<p>' . __( '<a href="https://codex.wordpress.org/Editing_Files">Documentation on Editing Files</a>') . '</p>' .48 '<p>' . __( '<a href="https://codex.wordpress.org/Template_Tags">Documentation on Template Tags</a>') . '</p>' .49 '<p>' . __( '<a href="https://wordpress.org/support/">Support Forums</a>') . '</p>'47 '<p><strong>' . __( 'For more information:' ) . '</strong></p>' . 48 '<p>' . __( '<a href="https://codex.wordpress.org/Theme_Development">Documentation on Theme Development</a>' ) . '</p>' . 49 '<p>' . __( '<a href="https://codex.wordpress.org/Using_Themes">Documentation on Using Themes</a>' ) . '</p>' . 50 '<p>' . __( '<a href="https://codex.wordpress.org/Editing_Files">Documentation on Editing Files</a>' ) . '</p>' . 51 '<p>' . __( '<a href="https://codex.wordpress.org/Template_Tags">Documentation on Template Tags</a>' ) . '</p>' . 52 '<p>' . __( '<a href="https://wordpress.org/support/">Support Forums</a>' ) . '</p>' 50 53 ); 51 54 … … 77 80 case 'php': 78 81 $allowed_files += $theme->get_files( 'php', -1 ); 79 $has_templates = ! empty( $allowed_files );82 $has_templates = ! empty( $allowed_files ); 80 83 break; 81 84 case 'css': 82 $style_files = $theme->get_files( 'css', -1 );85 $style_files = $theme->get_files( 'css', -1 ); 83 86 $allowed_files['style.css'] = $style_files['style.css']; 84 $allowed_files += $style_files;87 $allowed_files += $style_files; 85 88 break; 86 89 default: … … 100 103 if ( empty( $file ) ) { 101 104 $relative_file = 'style.css'; 102 $file = $allowed_files['style.css'];105 $file = $allowed_files['style.css']; 103 106 } else { 104 107 $relative_file = wp_unslash( $file ); 105 $file = $theme->get_stylesheet_directory() . '/' . $relative_file;108 $file = $theme->get_stylesheet_directory() . '/' . $relative_file; 106 109 } 107 110 … … 109 112 110 113 // Handle fallback editing of file when JavaScript is not available. 111 $edit_error = null;114 $edit_error = null; 112 115 $posted_content = null; 113 116 if ( 'POST' === $_SERVER['REQUEST_METHOD'] ) { … … 119 122 } 120 123 } else { 121 wp_redirect( add_query_arg( 122 array( 123 'a' => 1, // This means "success" for some reason. 124 'theme' => $stylesheet, 125 'file' => $relative_file, 126 ), 127 admin_url( 'theme-editor.php' ) 128 ) ); 124 wp_redirect( 125 add_query_arg( 126 array( 127 'a' => 1, // This means "success" for some reason. 128 'theme' => $stylesheet, 129 'file' => $relative_file, 130 ), 131 admin_url( 'theme-editor.php' ) 132 ) 133 ); 129 134 exit; 130 135 } … … 142 147 update_recently_edited( $file ); 143 148 144 if ( ! is_file( $file ) ) 149 if ( ! is_file( $file ) ) { 145 150 $error = true; 151 } 146 152 147 153 $content = ''; … … 149 155 $content = $posted_content; 150 156 } elseif ( ! $error && filesize( $file ) > 0 ) { 151 $f = fopen($file, 'r');152 $content = fread( $f, filesize($file));157 $f = fopen( $file, 'r' ); 158 $content = fread( $f, filesize( $file ) ); 153 159 154 160 if ( '.php' == substr( $file, strrpos( $file, '.' ) ) ) { 155 161 $functions = wp_doc_link_parse( $content ); 156 162 157 $docs_select = '<select name="docs-list" id="docs-list">';163 $docs_select = '<select name="docs-list" id="docs-list">'; 158 164 $docs_select .= '<option value="">' . esc_attr__( 'Function Name…' ) . '</option>'; 159 165 foreach ( $functions as $function ) { … … 166 172 } 167 173 168 $file_description = get_file_description( $relative_file );169 $file_show= array_search( $file, array_filter( $allowed_files ) );170 $description= esc_html( $file_description );171 if ( $file_description != $file_show ) {172 $description .= ' <span>(' . esc_html( $file_show ) . ')</span>';173 }174 $file_description = get_file_description( $relative_file ); 175 $file_show = array_search( $file, array_filter( $allowed_files ) ); 176 $description = esc_html( $file_description ); 177 if ( $file_description != $file_show ) { 178 $description .= ' <span>(' . esc_html( $file_show ) . ')</span>'; 179 } 174 180 ?> 175 181 <div class="wrap"> … … 203 209 <div class="fileedit-sub"> 204 210 <div class="alignleft"> 205 <h2><?php echo $theme->display( 'Name' ); if ( $description ) echo ': ' . $description; ?></h2> 211 <h2> 212 <?php 213 echo $theme->display( 'Name' ); 214 if ( $description ) { 215 echo ': ' . $description;} 216 ?> 217 </h2> 206 218 </div> 207 219 <div class="alignright"> 208 220 <form action="theme-editor.php" method="get"> 209 <strong><label for="theme"><?php _e( 'Select theme to edit:'); ?> </label></strong>221 <strong><label for="theme"><?php _e( 'Select theme to edit:' ); ?> </label></strong> 210 222 <select name="theme" id="theme"> 211 223 <?php 212 224 foreach ( wp_get_themes( array( 'errors' => null ) ) as $a_stylesheet => $a_theme ) { 213 if ( $a_theme->errors() && 'theme_no_stylesheet' == $a_theme->errors()->get_error_code() ) 225 if ( $a_theme->errors() && 'theme_no_stylesheet' == $a_theme->errors()->get_error_code() ) { 214 226 continue; 227 } 215 228 216 229 $selected = $a_stylesheet == $stylesheet ? ' selected="selected"' : ''; 217 echo "\n\t" . '<option value="' . esc_attr( $a_stylesheet ) . '"' . $selected . '>' . $a_theme->display( 'Name') . '</option>';230 echo "\n\t" . '<option value="' . esc_attr( $a_stylesheet ) . '"' . $selected . '>' . $a_theme->display( 'Name' ) . '</option>'; 218 231 } 219 232 ?> … … 225 238 </div> 226 239 <?php 227 if ( $theme->errors() ) 240 if ( $theme->errors() ) { 228 241 echo '<div class="error"><p><strong>' . __( 'This theme is broken.' ) . '</strong> ' . $theme->errors()->get_error_message() . '</p></div>'; 242 } 229 243 ?> 230 244 <div id="templateside"> … … 235 249 <?php 236 250 /* translators: %s: link to edit parent theme */ 237 echo sprintf( __( 'This child theme inherits templates from a parent theme, %s.' ), 238 sprintf( '<a href="%s">%s</a>', 251 echo sprintf( 252 __( 'This child theme inherits templates from a parent theme, %s.' ), 253 sprintf( 254 '<a href="%s">%s</a>', 239 255 self_admin_url( 'theme-editor.php?theme=' . urlencode( $theme->get_template() ) ), 240 256 $theme->parent()->display( 'Name' ) … … 252 268 </div> 253 269 254 <?php if ( $error ) : 255 echo '<div class="error"><p>' . __('Oops, no such file exists! Double check the name and try again, merci.') . '</p></div>'; 256 else : ?> 270 <?php 271 if ( $error ) : 272 echo '<div class="error"><p>' . __( 'Oops, no such file exists! Double check the name and try again, merci.' ) . '</p></div>'; 273 else : 274 ?> 257 275 <form name="template" id="template" action="theme-editor.php" method="post"> 258 276 <?php wp_nonce_field( 'edit-theme_' . $stylesheet . '_' . $relative_file, 'nonce' ); ?> … … 266 284 <?php if ( ! empty( $functions ) ) : ?> 267 285 <div id="documentation" class="hide-if-no-js"> 268 <label for="docs-list"><?php _e( 'Documentation:')?></label>286 <label for="docs-list"><?php _e( 'Documentation:' ); ?></label> 269 287 <?php echo $docs_select; ?> 270 <input type="button" class="button" value="<?php esc_attr_e( 'Look Up' ); ?>" onclick="if ( '' != jQuery('#docs-list').val() ) { window.open( 'https://api.wordpress.org/core/handbook/1.0/?function=' + escape( jQuery( '#docs-list' ).val() ) + '&locale=<?php echo urlencode( get_user_locale() ) ?>&version=<?php echo urlencode( get_bloginfo( 'version' ) )?>&redirect=true'); }" />288 <input type="button" class="button" value="<?php esc_attr_e( 'Look Up' ); ?>" onclick="if ( '' != jQuery('#docs-list').val() ) { window.open( 'https://api.wordpress.org/core/handbook/1.0/?function=' + escape( jQuery( '#docs-list' ).val() ) + '&locale=<?php echo urlencode( get_user_locale() ); ?>&version=<?php echo urlencode( get_bloginfo( 'version' ) ); ?>&redirect=true'); }" /> 271 289 </div> 272 290 <?php endif; ?> … … 277 295 <div class="notice notice-warning inline"> 278 296 <p> 279 <?php if ( is_writeable( $file ) ) { ?><strong><?php _e( 'Caution:' ); ?></strong><?php } ?> 297 <?php 298 if ( is_writeable( $file ) ) { 299 ?> 300 <strong><?php _e( 'Caution:' ); ?></strong><?php } ?> 280 301 <?php _e( 'This is a file in your current parent theme.' ); ?> 281 302 </p> … … 289 310 </p> 290 311 <?php else : ?> 291 <p><em><?php _e( 'You need to make this file writable before you can save your changes. See <a href="https://codex.wordpress.org/Changing_File_Permissions">the Codex</a> for more information.'); ?></em></p>312 <p><em><?php _e( 'You need to make this file writable before you can save your changes. See <a href="https://codex.wordpress.org/Changing_File_Permissions">the Codex</a> for more information.' ); ?></em></p> 292 313 <?php endif; ?> 293 314 </div> … … 303 324 if ( ! in_array( 'theme_editor_notice', $dismissed_pointers, true ) ) : 304 325 // Get a back URL 305 $referer = wp_get_referer();326 $referer = wp_get_referer(); 306 327 $excluded_referer_basenames = array( 'theme-editor.php', 'wp-login.php' ); 307 328 … … 339 360 endif; // editor warning notice 340 361 341 include( ABSPATH . 'wp-admin/admin-footer.php' );362 include( ABSPATH . 'wp-admin/admin-footer.php' );
Note: See TracChangeset
for help on using the changeset viewer.