Changeset 47122 for trunk/src/wp-admin/theme-editor.php
- Timestamp:
- 01/29/2020 12:43:23 AM (6 years ago)
- File:
-
- 1 edited
-
trunk/src/wp-admin/theme-editor.php (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/theme-editor.php
r45932 r47122 118 118 $edit_error = null; 119 119 $posted_content = null; 120 120 121 if ( 'POST' === $_SERVER['REQUEST_METHOD'] ) { 121 122 $r = wp_edit_theme_plugin_file( wp_unslash( $_POST ) ); … … 140 141 } 141 142 142 $settings = array( 143 'codeEditor' => wp_enqueue_code_editor( compact( 'file' ) ), 144 ); 145 wp_enqueue_script( 'wp-theme-plugin-editor' ); 146 wp_add_inline_script( 'wp-theme-plugin-editor', sprintf( 'jQuery( function( $ ) { wp.themePluginEditor.init( $( "#template" ), %s ); } )', wp_json_encode( $settings ) ) ); 147 wp_add_inline_script( 'wp-theme-plugin-editor', 'wp.themePluginEditor.themeOrPlugin = "theme";' ); 148 149 require_once( ABSPATH . 'wp-admin/admin-header.php' ); 150 151 update_recently_edited( $file ); 152 153 if ( ! is_file( $file ) ) { 154 $error = true; 143 $settings = array( 144 'codeEditor' => wp_enqueue_code_editor( compact( 'file' ) ), 145 ); 146 wp_enqueue_script( 'wp-theme-plugin-editor' ); 147 wp_add_inline_script( 'wp-theme-plugin-editor', sprintf( 'jQuery( function( $ ) { wp.themePluginEditor.init( $( "#template" ), %s ); } )', wp_json_encode( $settings ) ) ); 148 wp_add_inline_script( 'wp-theme-plugin-editor', 'wp.themePluginEditor.themeOrPlugin = "theme";' ); 149 150 require_once( ABSPATH . 'wp-admin/admin-header.php' ); 151 152 update_recently_edited( $file ); 153 154 if ( ! is_file( $file ) ) { 155 $error = true; 156 } 157 158 $content = ''; 159 if ( ! empty( $posted_content ) ) { 160 $content = $posted_content; 161 } elseif ( ! $error && filesize( $file ) > 0 ) { 162 $f = fopen( $file, 'r' ); 163 $content = fread( $f, filesize( $file ) ); 164 165 if ( '.php' == substr( $file, strrpos( $file, '.' ) ) ) { 166 $functions = wp_doc_link_parse( $content ); 167 168 $docs_select = '<select name="docs-list" id="docs-list">'; 169 $docs_select .= '<option value="">' . esc_attr__( 'Function Name…' ) . '</option>'; 170 foreach ( $functions as $function ) { 171 $docs_select .= '<option value="' . esc_attr( urlencode( $function ) ) . '">' . htmlspecialchars( $function ) . '()</option>'; 172 } 173 $docs_select .= '</select>'; 155 174 } 156 175 157 $content = ''; 158 if ( ! empty( $posted_content ) ) { 159 $content = $posted_content; 160 } elseif ( ! $error && filesize( $file ) > 0 ) { 161 $f = fopen( $file, 'r' ); 162 $content = fread( $f, filesize( $file ) ); 163 164 if ( '.php' == substr( $file, strrpos( $file, '.' ) ) ) { 165 $functions = wp_doc_link_parse( $content ); 166 167 $docs_select = '<select name="docs-list" id="docs-list">'; 168 $docs_select .= '<option value="">' . esc_attr__( 'Function Name…' ) . '</option>'; 169 foreach ( $functions as $function ) { 170 $docs_select .= '<option value="' . esc_attr( urlencode( $function ) ) . '">' . htmlspecialchars( $function ) . '()</option>'; 171 } 172 $docs_select .= '</select>'; 173 } 174 175 $content = esc_textarea( $content ); 176 } 177 178 $file_description = get_file_description( $relative_file ); 179 $file_show = array_search( $file, array_filter( $allowed_files ) ); 180 $description = esc_html( $file_description ); 181 if ( $file_description != $file_show ) { 182 $description .= ' <span>(' . esc_html( $file_show ) . ')</span>'; 183 } 184 ?> 176 $content = esc_textarea( $content ); 177 } 178 179 $file_description = get_file_description( $relative_file ); 180 $file_show = array_search( $file, array_filter( $allowed_files ) ); 181 $description = esc_html( $file_description ); 182 if ( $file_description != $file_show ) { 183 $description .= ' <span>(' . esc_html( $file_show ) . ')</span>'; 184 } 185 ?> 185 186 <div class="wrap"> 186 187 <h1><?php echo esc_html( $title ); ?></h1> … … 196 197 </div> 197 198 <?php endif; ?> 199 198 200 <?php if ( preg_match( '/\.css$/', $file ) ) : ?> 199 201 <div id="message" class="notice-info notice"> … … 214 216 <div class="alignleft"> 215 217 <h2> 216 <?php217 echo $theme->display( 'Name' );218 if ( $description ) {219 echo ': ' . $description;}220 ?>218 <?php 219 echo $theme->display( 'Name' ); 220 if ( $description ) { 221 echo ': ' . $description;} 222 ?> 221 223 </h2> 222 224 </div> … … 225 227 <strong><label for="theme"><?php _e( 'Select theme to edit:' ); ?> </label></strong> 226 228 <select name="theme" id="theme"> 227 <?php228 foreach ( wp_get_themes( array( 'errors' => null ) ) as $a_stylesheet => $a_theme ) {229 if ( $a_theme->errors() && 'theme_no_stylesheet' == $a_theme->errors()->get_error_code() ) {230 continue;231 }232 233 $selected = $a_stylesheet == $stylesheet ? ' selected="selected"' : '';234 echo "\n\t" . '<option value="' . esc_attr( $a_stylesheet ) . '"' . $selected . '>' . $a_theme->display( 'Name' ) . '</option>';235 }236 ?>229 <?php 230 foreach ( wp_get_themes( array( 'errors' => null ) ) as $a_stylesheet => $a_theme ) { 231 if ( $a_theme->errors() && 'theme_no_stylesheet' == $a_theme->errors()->get_error_code() ) { 232 continue; 233 } 234 235 $selected = $a_stylesheet == $stylesheet ? ' selected="selected"' : ''; 236 echo "\n\t" . '<option value="' . esc_attr( $a_stylesheet ) . '"' . $selected . '>' . $a_theme->display( 'Name' ) . '</option>'; 237 } 238 ?> 237 239 </select> 238 240 <?php submit_button( __( 'Select' ), '', 'Submit', false ); ?> … … 241 243 <br class="clear" /> 242 244 </div> 245 243 246 <?php 244 247 if ( $theme->errors() ) { … … 246 249 } 247 250 ?> 251 248 252 <div id="templateside"> 249 253 <h2 id="theme-files-label"><?php _e( 'Theme Files' ); ?></h2> … … 286 290 <input type="hidden" name="theme" value="<?php echo esc_attr( $theme->get_stylesheet() ); ?>" /> 287 291 </div> 288 <?php if ( ! empty( $functions ) ) : ?> 289 <div id="documentation" class="hide-if-no-js"> 290 <label for="docs-list"><?php _e( 'Documentation:' ); ?></label> 291 <?php echo $docs_select; ?> 292 <input disabled id="docs-lookup" 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'); }" /> 293 </div> 294 <?php endif; ?> 295 296 <div> 297 <div class="editor-notices"> 298 <?php if ( is_child_theme() && $theme->get_stylesheet() == get_template() ) : ?> 299 <div class="notice notice-warning inline"> 300 <p> 301 <?php 302 if ( is_writeable( $file ) ) { 303 ?> 304 <strong><?php _e( 'Caution:' ); ?></strong><?php } ?> 305 <?php _e( 'This is a file in your current parent theme.' ); ?> 306 </p> 307 </div> 292 293 <?php if ( ! empty( $functions ) ) : ?> 294 <div id="documentation" class="hide-if-no-js"> 295 <label for="docs-list"><?php _e( 'Documentation:' ); ?></label> 296 <?php echo $docs_select; ?> 297 <input disabled id="docs-lookup" 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'); }" /> 298 </div> 299 <?php endif; ?> 300 301 <div> 302 <div class="editor-notices"> 303 <?php if ( is_child_theme() && $theme->get_stylesheet() == get_template() ) : ?> 304 <div class="notice notice-warning inline"> 305 <p> 306 <?php if ( is_writeable( $file ) ) : ?> 307 <strong><?php _e( 'Caution:' ); ?></strong> 308 <?php endif; ?> 309 <?php _e( 'This is a file in your current parent theme.' ); ?> 310 </p> 311 </div> 312 <?php endif; ?> 313 </div> 314 <?php if ( is_writeable( $file ) ) : ?> 315 <p class="submit"> 316 <?php submit_button( __( 'Update File' ), 'primary', 'submit', false ); ?> 317 <span class="spinner"></span> 318 </p> 319 <?php else : ?> 320 <p><em> 321 <?php 322 printf( 323 /* translators: %s: Documentation URL. */ 324 __( 'You need to make this file writable before you can save your changes. See <a href="%s">Changing File Permissions</a> for more information.' ), 325 __( 'https://wordpress.org/support/article/changing-file-permissions/' ) 326 ); 327 ?> 328 </em></p> 308 329 <?php endif; ?> 309 330 </div> 310 <?php if ( is_writeable( $file ) ) : ?> 311 <p class="submit"> 312 <?php submit_button( __( 'Update File' ), 'primary', 'submit', false ); ?> 313 <span class="spinner"></span> 314 </p> 315 <?php else : ?> 316 <p><em> 317 <?php 318 printf( 319 /* translators: %s: Documentation URL. */ 320 __( 'You need to make this file writable before you can save your changes. See <a href="%s">Changing File Permissions</a> for more information.' ), 321 __( 'https://wordpress.org/support/article/changing-file-permissions/' ) 322 ); 323 ?> 324 </em></p> 325 <?php endif; ?> 326 </div> 327 <?php wp_print_file_editor_templates(); ?> 331 332 <?php wp_print_file_editor_templates(); ?> 328 333 </form> 329 334 <?php 330 endif; // $error335 endif; // End if $error. 331 336 ?> 332 337 <br class="clear" /> … … 335 340 $dismissed_pointers = explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) ); 336 341 if ( ! in_array( 'theme_editor_notice', $dismissed_pointers, true ) ) : 337 // Get a back URL 338 $referer = wp_get_referer(); 342 // Get a back URL. 343 $referer = wp_get_referer(); 344 339 345 $excluded_referer_basenames = array( 'theme-editor.php', 'wp-login.php' ); 340 346 … … 345 351 } 346 352 ?> 347 <div id="file-editor-warning" class="notification-dialog-wrap file-editor-warning hide-if-no-js hidden"> 348 <div class="notification-dialog-background"></div> 349 <div class="notification-dialog"> 350 <div class="file-editor-warning-content"> 351 <div class="file-editor-warning-message"> 352 <h1><?php _e( 'Heads up!' ); ?></h1> 353 <div id="file-editor-warning" class="notification-dialog-wrap file-editor-warning hide-if-no-js hidden"> 354 <div class="notification-dialog-background"></div> 355 <div class="notification-dialog"> 356 <div class="file-editor-warning-content"> 357 <div class="file-editor-warning-message"> 358 <h1><?php _e( 'Heads up!' ); ?></h1> 359 <p> 360 <?php 361 _e( 'You appear to be making direct edits to your theme in the WordPress dashboard. We recommend that you don’t! Editing your theme directly could break your site and your changes may be lost in future updates.' ); 362 ?> 363 </p> 364 <?php 365 if ( ! $theme->parent() ) { 366 echo '<p>'; 367 echo sprintf( 368 /* translators: %s: Link to documentation on child themes. */ 369 __( 'If you need to tweak more than your theme’s CSS, you might want to try <a href="%s">making a child theme</a>.' ), 370 esc_url( __( 'https://developer.wordpress.org/themes/advanced-topics/child-themes/' ) ) 371 ); 372 echo '</p>'; 373 } 374 ?> 375 <p><?php _e( 'If you decide to go ahead with direct edits anyway, use a file manager to create a copy with a new name and hang on to the original. That way, you can re-enable a functional version if something goes wrong.' ); ?></p> 376 </div> 353 377 <p> 354 <?php 355 _e( 'You appear to be making direct edits to your theme in the WordPress dashboard. We recommend that you don’t! Editing your theme directly could break your site and your changes may be lost in future updates.' ); 356 ?> 378 <a class="button file-editor-warning-go-back" href="<?php echo esc_url( $return_url ); ?>"><?php _e( 'Go back' ); ?></a> 379 <button type="button" class="file-editor-warning-dismiss button button-primary"><?php _e( 'I understand' ); ?></button> 357 380 </p> 358 <?php359 if ( ! $theme->parent() ) {360 echo '<p>';361 echo sprintf(362 /* translators: %s: Link to documentation on child themes. */363 __( 'If you need to tweak more than your theme’s CSS, you might want to try <a href="%s">making a child theme</a>.' ),364 esc_url( __( 'https://developer.wordpress.org/themes/advanced-topics/child-themes/' ) )365 );366 echo '</p>';367 }368 ?>369 <p><?php _e( 'If you decide to go ahead with direct edits anyway, use a file manager to create a copy with a new name and hang on to the original. That way, you can re-enable a functional version if something goes wrong.' ); ?></p>370 381 </div> 371 <p>372 <a class="button file-editor-warning-go-back" href="<?php echo esc_url( $return_url ); ?>"><?php _e( 'Go back' ); ?></a>373 <button type="button" class="file-editor-warning-dismiss button button-primary"><?php _e( 'I understand' ); ?></button>374 </p>375 382 </div> 376 383 </div> 377 </div>378 384 <?php 379 endif; // editor warning notice385 endif; // Editor warning notice. 380 386 381 387 include( ABSPATH . 'wp-admin/admin-footer.php' );
Note: See TracChangeset
for help on using the changeset viewer.