wp/wp-admin/theme-editor.php
changeset 7 cf61fcea0001
parent 5 5e2f62d02dcd
child 9 177826044cd9
equal deleted inserted replaced
6:490d5cc509ed 7:cf61fcea0001
    13 	wp_redirect( network_admin_url( 'theme-editor.php' ) );
    13 	wp_redirect( network_admin_url( 'theme-editor.php' ) );
    14 	exit();
    14 	exit();
    15 }
    15 }
    16 
    16 
    17 if ( !current_user_can('edit_themes') )
    17 if ( !current_user_can('edit_themes') )
    18 	wp_die('<p>'.__('You do not have sufficient permissions 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 $title = __("Edit Themes");
    20 $title = __("Edit Themes");
    21 $parent_file = 'themes.php';
    21 $parent_file = 'themes.php';
    22 
    22 
    23 get_current_screen()->add_help_tab( array(
    23 get_current_screen()->add_help_tab( array(
    24 'id'		=> 'overview',
    24 'id'		=> 'overview',
    25 'title'		=> __('Overview'),
    25 'title'		=> __('Overview'),
    26 'content'	=>
    26 'content'	=>
    27 	'<p>' . __('You can use the Theme Editor to edit the individual CSS and PHP files which make up your theme.') . '</p>
    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 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.') . '</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&#8217;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>
    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="newcontent-description">' . __( '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.' ) . '</p>
    30 	'<p id="editor-keyboard-trap-help-1">' . __( 'When using a keyboard to navigate:' ) . '</p>' .
    31 	<p>' . __('After typing in your edits, click Update File.') . '</p>
    31 	'<ul>' .
    32 	<p>' . __('<strong>Advice:</strong> think very carefully about your site crashing if you are live-editing the theme currently in use.') . '</p>
    32 	'<li id="editor-keyboard-trap-help-2">' . __( 'In the editing area, the Tab key enters a tab character.' ) . '</li>' .
    33 	<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" target="_blank">child theme</a> instead.'), __('https://codex.wordpress.org/Child_Themes') ) . '</p>' .
    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 	( is_network_admin() ? '<p>' . __('Any edits to files from this screen will be reflected on all sites in the network.') . '</p>' : '' )
    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>' : '' ),
    35 ) );
    41 ) );
    36 
    42 
    37 get_current_screen()->set_help_sidebar(
    43 get_current_screen()->set_help_sidebar(
    38 	'<p><strong>' . __('For more information:') . '</strong></p>' .
    44 	'<p><strong>' . __('For more information:') . '</strong></p>' .
    39 	'<p>' . __('<a href="https://codex.wordpress.org/Theme_Development" target="_blank">Documentation on Theme Development</a>') . '</p>' .
    45 	'<p>' . __('<a href="https://codex.wordpress.org/Theme_Development">Documentation on Theme Development</a>') . '</p>' .
    40 	'<p>' . __('<a href="https://codex.wordpress.org/Using_Themes" target="_blank">Documentation on Using Themes</a>') . '</p>' .
    46 	'<p>' . __('<a href="https://codex.wordpress.org/Using_Themes">Documentation on Using Themes</a>') . '</p>' .
    41 	'<p>' . __('<a href="https://codex.wordpress.org/Editing_Files" target="_blank">Documentation on Editing Files</a>') . '</p>' .
    47 	'<p>' . __('<a href="https://codex.wordpress.org/Editing_Files">Documentation on Editing Files</a>') . '</p>' .
    42 	'<p>' . __('<a href="https://codex.wordpress.org/Template_Tags" target="_blank">Documentation on Template Tags</a>') . '</p>' .
    48 	'<p>' . __('<a href="https://codex.wordpress.org/Template_Tags">Documentation on Template Tags</a>') . '</p>' .
    43 	'<p>' . __('<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
    49 	'<p>' . __('<a href="https://wordpress.org/support/">Support Forums</a>') . '</p>'
    44 );
    50 );
    45 
    51 
    46 wp_reset_vars( array( 'action', 'error', 'file', 'theme' ) );
    52 wp_reset_vars( array( 'action', 'error', 'file', 'theme' ) );
    47 
    53 
    48 if ( $theme )
    54 if ( $theme ) {
    49 	$stylesheet = $theme;
    55 	$stylesheet = $theme;
    50 else
    56 } else {
    51 	$stylesheet = get_stylesheet();
    57 	$stylesheet = get_stylesheet();
       
    58 }
    52 
    59 
    53 $theme = wp_get_theme( $stylesheet );
    60 $theme = wp_get_theme( $stylesheet );
    54 
    61 
    55 if ( ! $theme->exists() )
    62 if ( ! $theme->exists() ) {
    56 	wp_die( __( 'The requested theme does not exist.' ) );
    63 	wp_die( __( 'The requested theme does not exist.' ) );
    57 
    64 }
    58 if ( $theme->errors() && 'theme_no_stylesheet' == $theme->errors()->get_error_code() )
    65 
       
    66 if ( $theme->errors() && 'theme_no_stylesheet' == $theme->errors()->get_error_code() ) {
    59 	wp_die( __( 'The requested theme does not exist.' ) . ' ' . $theme->errors()->get_error_message() );
    67 	wp_die( __( 'The requested theme does not exist.' ) . ' ' . $theme->errors()->get_error_message() );
    60 
    68 }
    61 $allowed_files = $theme->get_files( 'php', 1 );
    69 
    62 $has_templates = ! empty( $allowed_files );
    70 $allowed_files = $style_files = array();
    63 $style_files = $theme->get_files( 'css' );
    71 $has_templates = false;
    64 $allowed_files['style.css'] = $style_files['style.css'];
    72 
    65 $allowed_files += $style_files;
    73 $file_types = wp_get_theme_file_editable_extensions( $theme );
       
    74 
       
    75 foreach ( $file_types as $type ) {
       
    76 	switch ( $type ) {
       
    77 		case 'php':
       
    78 			$allowed_files += $theme->get_files( 'php', -1 );
       
    79 			$has_templates = ! empty( $allowed_files );
       
    80 			break;
       
    81 		case 'css':
       
    82 			$style_files = $theme->get_files( 'css', -1 );
       
    83 			$allowed_files['style.css'] = $style_files['style.css'];
       
    84 			$allowed_files += $style_files;
       
    85 			break;
       
    86 		default:
       
    87 			$allowed_files += $theme->get_files( $type, -1 );
       
    88 			break;
       
    89 	}
       
    90 }
       
    91 
       
    92 // Move functions.php and style.css to the top.
       
    93 if ( isset( $allowed_files['functions.php'] ) ) {
       
    94 	$allowed_files = array( 'functions.php' => $allowed_files['functions.php'] ) + $allowed_files;
       
    95 }
       
    96 if ( isset( $allowed_files['style.css'] ) ) {
       
    97 	$allowed_files = array( 'style.css' => $allowed_files['style.css'] ) + $allowed_files;
       
    98 }
    66 
    99 
    67 if ( empty( $file ) ) {
   100 if ( empty( $file ) ) {
    68 	$relative_file = 'style.css';
   101 	$relative_file = 'style.css';
    69 	$file = $allowed_files['style.css'];
   102 	$file = $allowed_files['style.css'];
    70 } else {
   103 } else {
    71 	$relative_file = $file;
   104 	$relative_file = wp_unslash( $file );
    72 	$file = $theme->get_stylesheet_directory() . '/' . $relative_file;
   105 	$file = $theme->get_stylesheet_directory() . '/' . $relative_file;
    73 }
   106 }
    74 
   107 
    75 validate_file_to_edit( $file, $allowed_files );
   108 validate_file_to_edit( $file, $allowed_files );
    76 $scrollto = isset( $_REQUEST['scrollto'] ) ? (int) $_REQUEST['scrollto'] : 0;
   109 
    77 
   110 // Handle fallback editing of file when JavaScript is not available.
    78 switch( $action ) {
   111 $edit_error = null;
    79 case 'update':
   112 $posted_content = null;
    80 	check_admin_referer( 'edit-theme_' . $file . $stylesheet );
   113 if ( 'POST' === $_SERVER['REQUEST_METHOD'] ) {
    81 	$newcontent = wp_unslash( $_POST['newcontent'] );
   114 	$r = wp_edit_theme_plugin_file( wp_unslash( $_POST ) );
    82 	$location = 'theme-editor.php?file=' . urlencode( $relative_file ) . '&theme=' . urlencode( $stylesheet ) . '&scrollto=' . $scrollto;
   115 	if ( is_wp_error( $r ) ) {
    83 	if ( is_writeable( $file ) ) {
   116 		$edit_error = $r;
    84 		// is_writable() not always reliable, check return value. see comments @ http://uk.php.net/is_writable
   117 		if ( check_ajax_referer( 'edit-theme_' . $file . $stylesheet, 'nonce', false ) && isset( $_POST['newcontent'] ) ) {
    85 		$f = fopen( $file, 'w+' );
   118 			$posted_content = wp_unslash( $_POST['newcontent'] );
    86 		if ( $f !== false ) {
       
    87 			fwrite( $f, $newcontent );
       
    88 			fclose( $f );
       
    89 			$location .= '&updated=true';
       
    90 			$theme->cache_delete();
       
    91 		}
   119 		}
       
   120 	} 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 		) );
       
   129 		exit;
    92 	}
   130 	}
    93 	wp_redirect( $location );
   131 }
    94 	exit;
   132 
    95 
   133 	$settings = array(
    96 default:
   134 		'codeEditor' => wp_enqueue_code_editor( compact( 'file' ) ),
       
   135 	);
       
   136 	wp_enqueue_script( 'wp-theme-plugin-editor' );
       
   137 	wp_add_inline_script( 'wp-theme-plugin-editor', sprintf( 'jQuery( function( $ ) { wp.themePluginEditor.init( $( "#template" ), %s ); } )', wp_json_encode( $settings ) ) );
       
   138 	wp_add_inline_script( 'wp-theme-plugin-editor', 'wp.themePluginEditor.themeOrPlugin = "theme";' );
    97 
   139 
    98 	require_once( ABSPATH . 'wp-admin/admin-header.php' );
   140 	require_once( ABSPATH . 'wp-admin/admin-header.php' );
    99 
   141 
   100 	update_recently_edited( $file );
   142 	update_recently_edited( $file );
   101 
   143 
   102 	if ( ! is_file( $file ) )
   144 	if ( ! is_file( $file ) )
   103 		$error = true;
   145 		$error = true;
   104 
   146 
   105 	$content = '';
   147 	$content = '';
   106 	if ( ! $error && filesize( $file ) > 0 ) {
   148 	if ( ! empty( $posted_content ) ) {
       
   149 		$content = $posted_content;
       
   150 	} elseif ( ! $error && filesize( $file ) > 0 ) {
   107 		$f = fopen($file, 'r');
   151 		$f = fopen($file, 'r');
   108 		$content = fread($f, filesize($file));
   152 		$content = fread($f, filesize($file));
   109 
   153 
   110 		if ( '.php' == substr( $file, strrpos( $file, '.' ) ) ) {
   154 		if ( '.php' == substr( $file, strrpos( $file, '.' ) ) ) {
   111 			$functions = wp_doc_link_parse( $content );
   155 			$functions = wp_doc_link_parse( $content );
   119 		}
   163 		}
   120 
   164 
   121 		$content = esc_textarea( $content );
   165 		$content = esc_textarea( $content );
   122 	}
   166 	}
   123 
   167 
   124 	if ( isset( $_GET['updated'] ) ) : ?>
   168 $file_description = get_file_description( $relative_file );
   125  <div id="message" class="updated notice is-dismissible"><p><?php _e( 'File edited successfully.' ) ?></p></div>
       
   126 <?php endif;
       
   127 
       
   128 $description = get_file_description( $file );
       
   129 $file_show = array_search( $file, array_filter( $allowed_files ) );
   169 $file_show = array_search( $file, array_filter( $allowed_files ) );
   130 if ( $description != $file_show )
   170 $description = esc_html( $file_description );
   131 	$description .= ' <span>(' . $file_show . ')</span>';
   171 if ( $file_description != $file_show ) {
       
   172 	$description .= ' <span>(' . esc_html( $file_show ) . ')</span>';
       
   173 }
   132 ?>
   174 ?>
   133 <div class="wrap">
   175 <div class="wrap">
   134 <h2><?php echo esc_html( $title ); ?></h2>
   176 <h1><?php echo esc_html( $title ); ?></h1>
       
   177 
       
   178 <?php if ( isset( $_GET['a'] ) ) : ?>
       
   179 	<div id="message" class="updated notice is-dismissible">
       
   180 		<p><?php _e( 'File edited successfully.' ); ?></p>
       
   181 	</div>
       
   182 <?php elseif ( is_wp_error( $edit_error ) ) : ?>
       
   183 	<div id="message" class="notice notice-error">
       
   184 		<p><?php _e( 'There was an error while trying to update the file. You may need to fix something and try updating again.' ); ?></p>
       
   185 		<pre><?php echo esc_html( $edit_error->get_error_message() ? $edit_error->get_error_message() : $edit_error->get_error_code() ); ?></pre>
       
   186 	</div>
       
   187 <?php endif; ?>
       
   188 <?php if ( preg_match( '/\.css$/', $file ) ) : ?>
       
   189 	<div id="message" class="notice-info notice">
       
   190 		<p><strong><?php _e( 'Did you know?' ); ?></strong></p>
       
   191 		<p>
       
   192 			<?php
       
   193 			echo sprintf(
       
   194 				/* translators: %s: link to Custom CSS section in the Customizer */
       
   195 				__( '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>.' ),
       
   196 				esc_url( add_query_arg( 'autofocus[section]', 'custom_css', admin_url( 'customize.php' ) ) )
       
   197 			);
       
   198 			?>
       
   199 		</p>
       
   200 	</div>
       
   201 <?php endif; ?>
   135 
   202 
   136 <div class="fileedit-sub">
   203 <div class="fileedit-sub">
   137 <div class="alignleft">
   204 <div class="alignleft">
   138 <h3><?php echo $theme->display('Name'); if ( $description ) echo ': ' . $description; ?></h3>
   205 <h2><?php echo $theme->display( 'Name' ); if ( $description ) echo ': ' . $description; ?></h2>
   139 </div>
   206 </div>
   140 <div class="alignright">
   207 <div class="alignright">
   141 	<form action="theme-editor.php" method="post">
   208 	<form action="theme-editor.php" method="get">
   142 		<strong><label for="theme"><?php _e('Select theme to edit:'); ?> </label></strong>
   209 		<strong><label for="theme"><?php _e('Select theme to edit:'); ?> </label></strong>
   143 		<select name="theme" id="theme">
   210 		<select name="theme" id="theme">
   144 <?php
   211 <?php
   145 foreach ( wp_get_themes( array( 'errors' => null ) ) as $a_stylesheet => $a_theme ) {
   212 foreach ( wp_get_themes( array( 'errors' => null ) ) as $a_stylesheet => $a_theme ) {
   146 	if ( $a_theme->errors() && 'theme_no_stylesheet' == $a_theme->errors()->get_error_code() )
   213 	if ( $a_theme->errors() && 'theme_no_stylesheet' == $a_theme->errors()->get_error_code() )
   149 	$selected = $a_stylesheet == $stylesheet ? ' selected="selected"' : '';
   216 	$selected = $a_stylesheet == $stylesheet ? ' selected="selected"' : '';
   150 	echo "\n\t" . '<option value="' . esc_attr( $a_stylesheet ) . '"' . $selected . '>' . $a_theme->display('Name') . '</option>';
   217 	echo "\n\t" . '<option value="' . esc_attr( $a_stylesheet ) . '"' . $selected . '>' . $a_theme->display('Name') . '</option>';
   151 }
   218 }
   152 ?>
   219 ?>
   153 		</select>
   220 		</select>
   154 		<?php submit_button( __( 'Select' ), 'button', 'Submit', false ); ?>
   221 		<?php submit_button( __( 'Select' ), '', 'Submit', false ); ?>
   155 	</form>
   222 	</form>
   156 </div>
   223 </div>
   157 <br class="clear" />
   224 <br class="clear" />
   158 </div>
   225 </div>
   159 <?php
   226 <?php
   160 if ( $theme->errors() )
   227 if ( $theme->errors() )
   161 	echo '<div class="error"><p><strong>' . __( 'This theme is broken.' ) . '</strong> ' . $theme->errors()->get_error_message() . '</p></div>';
   228 	echo '<div class="error"><p><strong>' . __( 'This theme is broken.' ) . '</strong> ' . $theme->errors()->get_error_message() . '</p></div>';
   162 ?>
   229 ?>
   163 	<div id="templateside">
   230 <div id="templateside">
   164 <?php
   231 	<h2 id="theme-files-label"><?php _e( 'Theme Files' ); ?></h2>
   165 if ( $allowed_files ) :
   232 	<ul role="tree" aria-labelledby="theme-files-label">
   166 	if ( $has_templates || $theme->parent() ) :
   233 		<?php if ( ( $has_templates || $theme->parent() ) && $theme->parent() ) : ?>
   167 ?>
   234 			<li class="howto">
   168 	<h3><?php _e('Templates'); ?></h3>
   235 				<?php
   169 	<?php if ( $theme->parent() ) : ?>
   236 				/* translators: %s: link to edit parent theme */
   170 	<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>
   237 				echo sprintf( __( 'This child theme inherits templates from a parent theme, %s.' ),
   171 	<?php endif; ?>
   238 					sprintf( '<a href="%s">%s</a>',
   172 	<ul>
   239 						self_admin_url( 'theme-editor.php?theme=' . urlencode( $theme->get_template() ) ),
   173 <?php
   240 						$theme->parent()->display( 'Name' )
   174 	endif;
   241 					)
   175 
   242 				);
   176 	foreach ( $allowed_files as $filename => $absolute_filename ) :
   243 				?>
   177 		if ( 'style.css' == $filename )
   244 			</li>
   178 			echo "\t</ul>\n\t<h3>" . _x( 'Styles', 'Theme stylesheets in theme editor' ) . "</h3>\n\t<ul>\n";
   245 		<?php endif; ?>
   179 
   246 		<li role="treeitem" tabindex="-1" aria-expanded="true" aria-level="1" aria-posinset="1" aria-setsize="1">
   180 		$file_description = get_file_description( $absolute_filename );
   247 			<ul role="group">
   181 		if ( $file_description != basename( $filename ) )
   248 				<?php wp_print_theme_file_tree( wp_make_theme_file_tree( $allowed_files ) ); ?>
   182 			$file_description .= '<br /><span class="nonessential">(' . $filename . ')</span>';
   249 			</ul>
   183 
   250 		</li>
   184 		if ( $absolute_filename == $file )
   251 	</ul>
   185 			$file_description = '<span class="highlight">' . $file_description . '</span>';
   252 </div>
   186 ?>
   253 
   187 		<li><a href="theme-editor.php?file=<?php echo urlencode( $filename ) ?>&amp;theme=<?php echo urlencode( $stylesheet ) ?>"><?php echo $file_description; ?></a></li>
       
   188 <?php
       
   189 	endforeach;
       
   190 ?>
       
   191 </ul>
       
   192 <?php endif; ?>
       
   193 </div>
       
   194 <?php if ( $error ) :
   254 <?php if ( $error ) :
   195 	echo '<div class="error"><p>' . __('Oops, no such file exists! Double check the name and try again, merci.') . '</p></div>';
   255 	echo '<div class="error"><p>' . __('Oops, no such file exists! Double check the name and try again, merci.') . '</p></div>';
   196 else : ?>
   256 else : ?>
   197 	<form name="template" id="template" action="theme-editor.php" method="post">
   257 	<form name="template" id="template" action="theme-editor.php" method="post">
   198 	<?php wp_nonce_field( 'edit-theme_' . $file . $stylesheet ); ?>
   258 		<?php wp_nonce_field( 'edit-theme_' . $file . $stylesheet, 'nonce' ); ?>
   199 		<div><textarea cols="70" rows="30" name="newcontent" id="newcontent" aria-describedby="newcontent-description"><?php echo $content; ?></textarea>
   259 		<div>
   200 		<input type="hidden" name="action" value="update" />
   260 			<label for="newcontent" id="theme-plugin-editor-label"><?php _e( 'Selected file content:' ); ?></label>
   201 		<input type="hidden" name="file" value="<?php echo esc_attr( $relative_file ); ?>" />
   261 			<textarea cols="70" rows="30" name="newcontent" id="newcontent" aria-describedby="editor-keyboard-trap-help-1 editor-keyboard-trap-help-2 editor-keyboard-trap-help-3 editor-keyboard-trap-help-4"><?php echo $content; ?></textarea>
   202 		<input type="hidden" name="theme" value="<?php echo esc_attr( $theme->get_stylesheet() ); ?>" />
   262 			<input type="hidden" name="action" value="update" />
   203 		<input type="hidden" name="scrollto" id="scrollto" value="<?php echo $scrollto; ?>" />
   263 			<input type="hidden" name="file" value="<?php echo esc_attr( $relative_file ); ?>" />
       
   264 			<input type="hidden" name="theme" value="<?php echo esc_attr( $theme->get_stylesheet() ); ?>" />
   204 		</div>
   265 		</div>
   205 	<?php if ( ! empty( $functions ) ) : ?>
   266 	<?php if ( ! empty( $functions ) ) : ?>
   206 		<div id="documentation" class="hide-if-no-js">
   267 		<div id="documentation" class="hide-if-no-js">
   207 		<label for="docs-list"><?php _e('Documentation:') ?></label>
   268 		<label for="docs-list"><?php _e('Documentation:') ?></label>
   208 		<?php echo $docs_select; ?>
   269 		<?php echo $docs_select; ?>
   209 		<input type="button" class="button" value=" <?php esc_attr_e( 'Look Up' ); ?> " onclick="if ( '' != jQuery('#docs-list').val() ) { window.open( 'http://api.wordpress.org/core/handbook/1.0/?function=' + escape( jQuery( '#docs-list' ).val() ) + '&amp;locale=<?php echo urlencode( get_locale() ) ?>&amp;version=<?php echo urlencode( $wp_version ) ?>&amp;redirect=true'); }" />
   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() ) + '&amp;locale=<?php echo urlencode( get_user_locale() ) ?>&amp;version=<?php echo urlencode( get_bloginfo( 'version' ) ) ?>&amp;redirect=true'); }" />
   210 		</div>
   271 		</div>
   211 	<?php endif; ?>
   272 	<?php endif; ?>
   212 
   273 
   213 		<div>
   274 	<div>
   214 		<?php if ( is_child_theme() && $theme->get_stylesheet() == get_template() ) : ?>
   275 		<div class="editor-notices">
   215 			<p><?php if ( is_writeable( $file ) ) { ?><strong><?php _e( 'Caution:' ); ?></strong><?php } ?>
   276 			<?php if ( is_child_theme() && $theme->get_stylesheet() == get_template() ) : ?>
   216 			<?php _e( 'This is a file in your current parent theme.' ); ?></p>
   277 				<div class="notice notice-warning inline">
   217 		<?php endif; ?>
   278 					<p>
   218 <?php
   279 						<?php if ( is_writeable( $file ) ) { ?><strong><?php _e( 'Caution:' ); ?></strong><?php } ?>
   219 	if ( is_writeable( $file ) ) :
   280 						<?php _e( 'This is a file in your current parent theme.' ); ?>
   220 		submit_button( __( 'Update File' ), 'primary', 'submit', true );
   281 					</p>
   221 	else : ?>
   282 				</div>
   222 <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>
   283 			<?php endif; ?>
   223 <?php endif; ?>
       
   224 		</div>
   284 		</div>
       
   285 	<?php if ( is_writeable( $file ) ) : ?>
       
   286 		<p class="submit">
       
   287 			<?php submit_button( __( 'Update File' ), 'primary', 'submit', false ); ?>
       
   288 			<span class="spinner"></span>
       
   289 		</p>
       
   290 	<?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>
       
   292 	<?php endif; ?>
       
   293 	</div>
       
   294 	<?php wp_print_file_editor_templates(); ?>
   225 	</form>
   295 	</form>
   226 <?php
   296 <?php
   227 endif; // $error
   297 endif; // $error
   228 ?>
   298 ?>
   229 <br class="clear" />
   299 <br class="clear" />
   230 </div>
   300 </div>
   231 <script type="text/javascript">
   301 <?php
   232 jQuery(document).ready(function($){
   302 $dismissed_pointers = explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) );
   233 	$('#template').submit(function(){ $('#scrollto').val( $('#newcontent').scrollTop() ); });
   303 if ( ! in_array( 'theme_editor_notice', $dismissed_pointers, true ) ) :
   234 	$('#newcontent').scrollTop( $('#scrollto').val() );
   304 	// Get a back URL
   235 });
   305 	$referer = wp_get_referer();
   236 </script>
   306 	$excluded_referer_basenames = array( 'theme-editor.php', 'wp-login.php' );
   237 <?php
   307 
   238 break;
   308 	if ( $referer && ! in_array( basename( parse_url( $referer, PHP_URL_PATH ) ), $excluded_referer_basenames, true ) ) {
   239 }
   309 		$return_url = $referer;
       
   310 	} else {
       
   311 		$return_url = admin_url( '/' );
       
   312 	}
       
   313 ?>
       
   314 <div id="file-editor-warning" class="notification-dialog-wrap file-editor-warning hide-if-no-js hidden">
       
   315 	<div class="notification-dialog-background"></div>
       
   316 	<div class="notification-dialog">
       
   317 		<div class="file-editor-warning-content">
       
   318 			<div class="file-editor-warning-message">
       
   319 				<h1><?php _e( 'Heads up!' ); ?></h1>
       
   320 				<p>
       
   321 					<?php
       
   322 					echo sprintf(
       
   323 						/* translators: %s: Codex URL */
       
   324 						__( '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. If you need to tweak more than your theme&#8217;s CSS, you might want to try <a href="%s">making a child theme</a>.' ),
       
   325 						esc_url( __( 'https://codex.wordpress.org/Child_Themes' ) )
       
   326 					);
       
   327 					?>
       
   328 				</p>
       
   329 				<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>
       
   330 				
       
   331 			</div>
       
   332 			<p>
       
   333 				<a class="button file-editor-warning-go-back" href="<?php echo esc_url( $return_url ); ?>"><?php _e( 'Go back' ); ?></a>
       
   334 				<button type="button" class="file-editor-warning-dismiss button button-primary"><?php _e( 'I understand' ); ?></button>
       
   335 			</p>
       
   336 		</div>
       
   337 	</div>
       
   338 </div>
       
   339 <?php
       
   340 endif; // editor warning notice
   240 
   341 
   241 include(ABSPATH . 'wp-admin/admin-footer.php' );
   342 include(ABSPATH . 'wp-admin/admin-footer.php' );