wp/wp-admin/theme-editor.php
changeset 19 3d72ae0968f4
parent 18 be944660c56a
child 21 48c4eec2b7e6
equal deleted inserted replaced
18:be944660c56a 19:3d72ae0968f4
     1 <?php
     1 <?php
     2 /**
     2 /**
     3  * Theme editor administration panel.
     3  * Theme file editor administration panel.
     4  *
     4  *
     5  * @package WordPress
     5  * @package WordPress
     6  * @subpackage Administration
     6  * @subpackage Administration
     7  */
     7  */
     8 
     8 
    16 
    16 
    17 if ( ! current_user_can( '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>' );
    18 	wp_die( '<p>' . __( 'Sorry, you are not allowed to edit templates for this site.' ) . '</p>' );
    19 }
    19 }
    20 
    20 
       
    21 // Used in the HTML title tag.
    21 $title       = __( 'Edit Themes' );
    22 $title       = __( 'Edit Themes' );
    22 $parent_file = 'themes.php';
    23 $parent_file = 'themes.php';
    23 
    24 
    24 get_current_screen()->add_help_tab(
    25 get_current_screen()->add_help_tab(
    25 	array(
    26 	array(
    26 		'id'      => 'overview',
    27 		'id'      => 'overview',
    27 		'title'   => __( 'Overview' ),
    28 		'title'   => __( 'Overview' ),
    28 		'content' =>
    29 		'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>' . __( 'You can use the theme file 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&#8217;s template files. Clicking once on any file name causes the file to appear in the large Editor box.' ) . '</p>' .
    31 				'<p>' . __( 'Begin by choosing a theme to edit from the dropdown menu and clicking the Select button. A list then appears of the theme&#8217;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>' . __( '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 				'<p id="editor-keyboard-trap-help-1">' . __( 'When using a keyboard to navigate:' ) . '</p>' .
    33 				'<ul>' .
    34 				'<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-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-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 				'<li id="editor-keyboard-trap-help-4">' . __( 'Screen reader users: when in forms mode, you may need to press the Esc key twice.' ) . '</li>' .
    47 );
    48 );
    48 
    49 
    49 get_current_screen()->set_help_sidebar(
    50 get_current_screen()->set_help_sidebar(
    50 	'<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
    51 	'<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
    51 	'<p>' . __( '<a href="https://developer.wordpress.org/themes/">Documentation on Theme Development</a>' ) . '</p>' .
    52 	'<p>' . __( '<a href="https://developer.wordpress.org/themes/">Documentation on Theme Development</a>' ) . '</p>' .
    52 	'<p>' . __( '<a href="https://wordpress.org/support/article/using-themes/">Documentation on Using Themes</a>' ) . '</p>' .
    53 	'<p>' . __( '<a href="https://wordpress.org/support/article/appearance-editor-screen/">Documentation on Editing Themes</a>' ) . '</p>' .
    53 	'<p>' . __( '<a href="https://wordpress.org/support/article/editing-files/">Documentation on Editing Files</a>' ) . '</p>' .
    54 	'<p>' . __( '<a href="https://wordpress.org/support/article/editing-files/">Documentation on Editing Files</a>' ) . '</p>' .
    54 	'<p>' . __( '<a href="https://developer.wordpress.org/themes/basics/template-tags/">Documentation on Template Tags</a>' ) . '</p>' .
    55 	'<p>' . __( '<a href="https://developer.wordpress.org/themes/basics/template-tags/">Documentation on Template Tags</a>' ) . '</p>' .
    55 	'<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>'
    56 	'<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>'
    56 );
    57 );
    57 
    58 
   193 		<p><?php _e( 'There was an error while trying to update the file. You may need to fix something and try updating again.' ); ?></p>
   194 		<p><?php _e( 'There was an error while trying to update the file. You may need to fix something and try updating again.' ); ?></p>
   194 		<pre><?php echo esc_html( $edit_error->get_error_message() ? $edit_error->get_error_message() : $edit_error->get_error_code() ); ?></pre>
   195 		<pre><?php echo esc_html( $edit_error->get_error_message() ? $edit_error->get_error_message() : $edit_error->get_error_code() ); ?></pre>
   195 	</div>
   196 	</div>
   196 <?php endif; ?>
   197 <?php endif; ?>
   197 
   198 
   198 <?php if ( preg_match( '/\.css$/', $file ) ) : ?>
   199 <?php if ( preg_match( '/\.css$/', $file ) && ! wp_is_block_theme() && current_user_can( 'customize' ) ) : ?>
   199 	<div id="message" class="notice-info notice">
   200 	<div id="message" class="notice-info notice">
   200 		<p><strong><?php _e( 'Did you know?' ); ?></strong></p>
   201 		<p><strong><?php _e( 'Did you know?' ); ?></strong></p>
   201 		<p>
   202 		<p>
   202 			<?php
   203 			<?php
   203 			printf(
   204 			printf(
   204 				/* translators: %s: Link to Custom CSS section in the Customizer. */
   205 				/* translators: %s: Link to Custom CSS section in the Customizer. */
   205 				__( 'There&#8217;s no need to change your CSS here &mdash; you can edit and live preview CSS changes in the <a href="%s">built-in CSS editor</a>.' ),
   206 				__( 'There is no need to change your CSS here &mdash; you can edit and live preview CSS changes in the <a href="%s">built-in CSS editor</a>.' ),
   206 				esc_url( add_query_arg( 'autofocus[section]', 'custom_css', admin_url( 'customize.php' ) ) )
   207 				esc_url( add_query_arg( 'autofocus[section]', 'custom_css', admin_url( 'customize.php' ) ) )
   207 			);
   208 			);
   208 			?>
   209 			?>
   209 		</p>
   210 		</p>
   210 	</div>
   211 	</div>
   340 	// Get a back URL.
   341 	// Get a back URL.
   341 	$referer = wp_get_referer();
   342 	$referer = wp_get_referer();
   342 
   343 
   343 	$excluded_referer_basenames = array( 'theme-editor.php', 'wp-login.php' );
   344 	$excluded_referer_basenames = array( 'theme-editor.php', 'wp-login.php' );
   344 
   345 
   345 	if ( $referer && ! in_array( basename( parse_url( $referer, PHP_URL_PATH ) ), $excluded_referer_basenames, true ) ) {
   346 	$return_url = admin_url( '/' );
   346 		$return_url = $referer;
   347 	if ( $referer ) {
   347 	} else {
   348 		$referer_path = parse_url( $referer, PHP_URL_PATH );
   348 		$return_url = admin_url( '/' );
   349 		if ( is_string( $referer_path ) && ! in_array( basename( $referer_path ), $excluded_referer_basenames, true ) ) {
       
   350 			$return_url = $referer;
       
   351 		}
   349 	}
   352 	}
   350 	?>
   353 	?>
   351 	<div id="file-editor-warning" class="notification-dialog-wrap file-editor-warning hide-if-no-js hidden">
   354 	<div id="file-editor-warning" class="notification-dialog-wrap file-editor-warning hide-if-no-js hidden">
   352 		<div class="notification-dialog-background"></div>
   355 		<div class="notification-dialog-background"></div>
   353 		<div class="notification-dialog">
   356 		<div class="notification-dialog">
   354 			<div class="file-editor-warning-content">
   357 			<div class="file-editor-warning-content">
   355 				<div class="file-editor-warning-message">
   358 				<div class="file-editor-warning-message">
   356 					<h1><?php _e( 'Heads up!' ); ?></h1>
   359 					<h1><?php _e( 'Heads up!' ); ?></h1>
   357 					<p>
   360 					<p>
   358 						<?php
   361 						<?php
   359 						_e( 'You appear to be making direct edits to your theme in the WordPress dashboard. We recommend that you don&#8217;t! Editing your theme directly could break your site and your changes may be lost in future updates.' );
   362 						_e( 'You appear to be making direct edits to your theme in the WordPress dashboard. It is not recommended! Editing your theme directly could break your site and your changes may be lost in future updates.' );
   360 						?>
   363 						?>
   361 					</p>
   364 					</p>
   362 						<?php
   365 						<?php
   363 						if ( ! $theme->parent() ) {
   366 						if ( ! $theme->parent() ) {
   364 							echo '<p>';
   367 							echo '<p>';