wp/wp-admin/theme-editor.php
changeset 16 a86126ab1dd4
parent 9 177826044cd9
child 18 be944660c56a
equal deleted inserted replaced
15:3d4e9c994f10 16:a86126ab1dd4
     5  * @package WordPress
     5  * @package WordPress
     6  * @subpackage Administration
     6  * @subpackage Administration
     7  */
     7  */
     8 
     8 
     9 /** WordPress Administration Bootstrap */
     9 /** WordPress Administration Bootstrap */
    10 require_once( dirname( __FILE__ ) . '/admin.php' );
    10 require_once __DIR__ . '/admin.php';
    11 
    11 
    12 if ( is_multisite() && ! is_network_admin() ) {
    12 if ( is_multisite() && ! is_network_admin() ) {
    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>' . __( '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 }
    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>' .
    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>' .
    37 				'</ul>' .
    38 				'<p>' . __( 'After typing in your edits, click Update File.' ) . '</p>' .
    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>' .
    39 				'<p>' . __( '<strong>Advice:</strong> Think very carefully about your site crashing if you are live-editing the theme currently in use.' ) . '</p>' .
    40 				'<p>' . sprintf(
    40 				'<p>' . sprintf(
    41 					/* translators: %s: link to documentation on child themes */
    41 					/* translators: %s: Link to documentation on child themes. */
    42 					__( '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.' ),
    42 					__( '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.' ),
    43 					__( 'https://developer.wordpress.org/themes/advanced-topics/child-themes/' )
    43 					__( 'https://developer.wordpress.org/themes/advanced-topics/child-themes/' )
    44 				) . '</p>' .
    44 				) . '</p>' .
    45 				( is_network_admin() ? '<p>' . __( 'Any edits to files from this screen will be reflected on all sites in the network.' ) . '</p>' : '' ),
    45 				( is_network_admin() ? '<p>' . __( 'Any edits to files from this screen will be reflected on all sites in the network.' ) . '</p>' : '' ),
    46 	)
    46 	)
    47 );
    47 );
    48 
    48 
    49 get_current_screen()->set_help_sidebar(
    49 get_current_screen()->set_help_sidebar(
    50 	'<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
    50 	'<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
    51 	'<p>' . __( '<a href="https://codex.wordpress.org/Theme_Development">Documentation on Theme Development</a>' ) . '</p>' .
    51 	'<p>' . __( '<a href="https://developer.wordpress.org/themes/">Documentation on Theme Development</a>' ) . '</p>' .
    52 	'<p>' . __( '<a href="https://codex.wordpress.org/Using_Themes">Documentation on Using Themes</a>' ) . '</p>' .
    52 	'<p>' . __( '<a href="https://wordpress.org/support/article/using-themes/">Documentation on Using Themes</a>' ) . '</p>' .
    53 	'<p>' . __( '<a href="https://codex.wordpress.org/Editing_Files">Documentation on Editing Files</a>' ) . '</p>' .
    53 	'<p>' . __( '<a href="https://wordpress.org/support/article/editing-files/">Documentation on Editing Files</a>' ) . '</p>' .
    54 	'<p>' . __( '<a href="https://codex.wordpress.org/Template_Tags">Documentation on Template Tags</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://wordpress.org/support/">Support</a>' ) . '</p>'
    55 	'<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>'
    56 );
    56 );
    57 
    57 
    58 wp_reset_vars( array( 'action', 'error', 'file', 'theme' ) );
    58 wp_reset_vars( array( 'action', 'error', 'file', 'theme' ) );
    59 
    59 
    67 
    67 
    68 if ( ! $theme->exists() ) {
    68 if ( ! $theme->exists() ) {
    69 	wp_die( __( 'The requested theme does not exist.' ) );
    69 	wp_die( __( 'The requested theme does not exist.' ) );
    70 }
    70 }
    71 
    71 
    72 if ( $theme->errors() && 'theme_no_stylesheet' == $theme->errors()->get_error_code() ) {
    72 if ( $theme->errors() && 'theme_no_stylesheet' === $theme->errors()->get_error_code() ) {
    73 	wp_die( __( 'The requested theme does not exist.' ) . ' ' . $theme->errors()->get_error_message() );
    73 	wp_die( __( 'The requested theme does not exist.' ) . ' ' . $theme->errors()->get_error_message() );
    74 }
    74 }
    75 
    75 
    76 $allowed_files = $style_files = array();
    76 $allowed_files = array();
    77 $has_templates = false;
    77 $style_files   = array();
    78 
    78 
    79 $file_types = wp_get_theme_file_editable_extensions( $theme );
    79 $file_types = wp_get_theme_file_editable_extensions( $theme );
    80 
    80 
    81 foreach ( $file_types as $type ) {
    81 foreach ( $file_types as $type ) {
    82 	switch ( $type ) {
    82 	switch ( $type ) {
    83 		case 'php':
    83 		case 'php':
    84 			$allowed_files += $theme->get_files( 'php', -1 );
    84 			$allowed_files += $theme->get_files( 'php', -1 );
    85 			$has_templates  = ! empty( $allowed_files );
       
    86 			break;
    85 			break;
    87 		case 'css':
    86 		case 'css':
    88 			$style_files                = $theme->get_files( 'css', -1 );
    87 			$style_files                = $theme->get_files( 'css', -1 );
    89 			$allowed_files['style.css'] = $style_files['style.css'];
    88 			$allowed_files['style.css'] = $style_files['style.css'];
    90 			$allowed_files             += $style_files;
    89 			$allowed_files             += $style_files;
   114 validate_file_to_edit( $file, $allowed_files );
   113 validate_file_to_edit( $file, $allowed_files );
   115 
   114 
   116 // Handle fallback editing of file when JavaScript is not available.
   115 // Handle fallback editing of file when JavaScript is not available.
   117 $edit_error     = null;
   116 $edit_error     = null;
   118 $posted_content = null;
   117 $posted_content = null;
       
   118 
   119 if ( 'POST' === $_SERVER['REQUEST_METHOD'] ) {
   119 if ( 'POST' === $_SERVER['REQUEST_METHOD'] ) {
   120 	$r = wp_edit_theme_plugin_file( wp_unslash( $_POST ) );
   120 	$r = wp_edit_theme_plugin_file( wp_unslash( $_POST ) );
   121 	if ( is_wp_error( $r ) ) {
   121 	if ( is_wp_error( $r ) ) {
   122 		$edit_error = $r;
   122 		$edit_error = $r;
   123 		if ( check_ajax_referer( 'edit-theme_' . $stylesheet . '_' . $relative_file, 'nonce', false ) && isset( $_POST['newcontent'] ) ) {
   123 		if ( check_ajax_referer( 'edit-theme_' . $stylesheet . '_' . $relative_file, 'nonce', false ) && isset( $_POST['newcontent'] ) ) {
   136 		);
   136 		);
   137 		exit;
   137 		exit;
   138 	}
   138 	}
   139 }
   139 }
   140 
   140 
   141 	$settings = array(
   141 $settings = array(
   142 		'codeEditor' => wp_enqueue_code_editor( compact( 'file' ) ),
   142 	'codeEditor' => wp_enqueue_code_editor( compact( 'file' ) ),
   143 	);
   143 );
   144 	wp_enqueue_script( 'wp-theme-plugin-editor' );
   144 wp_enqueue_script( 'wp-theme-plugin-editor' );
   145 	wp_add_inline_script( 'wp-theme-plugin-editor', sprintf( 'jQuery( function( $ ) { wp.themePluginEditor.init( $( "#template" ), %s ); } )', wp_json_encode( $settings ) ) );
   145 wp_add_inline_script( 'wp-theme-plugin-editor', sprintf( 'jQuery( function( $ ) { wp.themePluginEditor.init( $( "#template" ), %s ); } )', wp_json_encode( $settings ) ) );
   146 	wp_add_inline_script( 'wp-theme-plugin-editor', 'wp.themePluginEditor.themeOrPlugin = "theme";' );
   146 wp_add_inline_script( 'wp-theme-plugin-editor', 'wp.themePluginEditor.themeOrPlugin = "theme";' );
   147 
   147 
   148 	require_once( ABSPATH . 'wp-admin/admin-header.php' );
   148 require_once ABSPATH . 'wp-admin/admin-header.php';
   149 
   149 
   150 	update_recently_edited( $file );
   150 update_recently_edited( $file );
   151 
   151 
   152 	if ( ! is_file( $file ) ) {
   152 if ( ! is_file( $file ) ) {
   153 		$error = true;
   153 	$error = true;
       
   154 }
       
   155 
       
   156 $content = '';
       
   157 if ( ! empty( $posted_content ) ) {
       
   158 	$content = $posted_content;
       
   159 } elseif ( ! $error && filesize( $file ) > 0 ) {
       
   160 	$f       = fopen( $file, 'r' );
       
   161 	$content = fread( $f, filesize( $file ) );
       
   162 
       
   163 	if ( '.php' === substr( $file, strrpos( $file, '.' ) ) ) {
       
   164 		$functions = wp_doc_link_parse( $content );
       
   165 
       
   166 		$docs_select  = '<select name="docs-list" id="docs-list">';
       
   167 		$docs_select .= '<option value="">' . esc_attr__( 'Function Name&hellip;' ) . '</option>';
       
   168 		foreach ( $functions as $function ) {
       
   169 			$docs_select .= '<option value="' . esc_attr( urlencode( $function ) ) . '">' . htmlspecialchars( $function ) . '()</option>';
       
   170 		}
       
   171 		$docs_select .= '</select>';
   154 	}
   172 	}
   155 
   173 
   156 	$content = '';
   174 	$content = esc_textarea( $content );
   157 	if ( ! empty( $posted_content ) ) {
   175 }
   158 		$content = $posted_content;
   176 
   159 	} elseif ( ! $error && filesize( $file ) > 0 ) {
   177 $file_description = get_file_description( $relative_file );
   160 		$f       = fopen( $file, 'r' );
   178 $file_show        = array_search( $file, array_filter( $allowed_files ), true );
   161 		$content = fread( $f, filesize( $file ) );
   179 $description      = esc_html( $file_description );
   162 
   180 if ( $file_description !== $file_show ) {
   163 		if ( '.php' == substr( $file, strrpos( $file, '.' ) ) ) {
   181 	$description .= ' <span>(' . esc_html( $file_show ) . ')</span>';
   164 			$functions = wp_doc_link_parse( $content );
   182 }
   165 
   183 ?>
   166 			$docs_select  = '<select name="docs-list" id="docs-list">';
       
   167 			$docs_select .= '<option value="">' . esc_attr__( 'Function Name&hellip;' ) . '</option>';
       
   168 			foreach ( $functions as $function ) {
       
   169 				$docs_select .= '<option value="' . esc_attr( urlencode( $function ) ) . '">' . htmlspecialchars( $function ) . '()</option>';
       
   170 			}
       
   171 			$docs_select .= '</select>';
       
   172 		}
       
   173 
       
   174 		$content = esc_textarea( $content );
       
   175 	}
       
   176 
       
   177 	$file_description = get_file_description( $relative_file );
       
   178 	$file_show        = array_search( $file, array_filter( $allowed_files ) );
       
   179 	$description      = esc_html( $file_description );
       
   180 	if ( $file_description != $file_show ) {
       
   181 		$description .= ' <span>(' . esc_html( $file_show ) . ')</span>';
       
   182 	}
       
   183 	?>
       
   184 <div class="wrap">
   184 <div class="wrap">
   185 <h1><?php echo esc_html( $title ); ?></h1>
   185 <h1><?php echo esc_html( $title ); ?></h1>
   186 
   186 
   187 <?php if ( isset( $_GET['a'] ) ) : ?>
   187 <?php if ( isset( $_GET['a'] ) ) : ?>
   188 	<div id="message" class="updated notice is-dismissible">
   188 	<div id="message" class="updated notice is-dismissible">
   192 	<div id="message" class="notice notice-error">
   192 	<div id="message" class="notice notice-error">
   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>
   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 		<pre><?php echo esc_html( $edit_error->get_error_message() ? $edit_error->get_error_message() : $edit_error->get_error_code() ); ?></pre>
   194 		<pre><?php echo esc_html( $edit_error->get_error_message() ? $edit_error->get_error_message() : $edit_error->get_error_code() ); ?></pre>
   195 	</div>
   195 	</div>
   196 <?php endif; ?>
   196 <?php endif; ?>
       
   197 
   197 <?php if ( preg_match( '/\.css$/', $file ) ) : ?>
   198 <?php if ( preg_match( '/\.css$/', $file ) ) : ?>
   198 	<div id="message" class="notice-info notice">
   199 	<div id="message" class="notice-info notice">
   199 		<p><strong><?php _e( 'Did you know?' ); ?></strong></p>
   200 		<p><strong><?php _e( 'Did you know?' ); ?></strong></p>
   200 		<p>
   201 		<p>
   201 			<?php
   202 			<?php
   202 			echo sprintf(
   203 			printf(
   203 				/* translators: %s: link to Custom CSS section in the Customizer */
   204 				/* translators: %s: Link to Custom CSS section in the Customizer. */
   204 				__( '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>.' ),
   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>.' ),
   205 				esc_url( add_query_arg( 'autofocus[section]', 'custom_css', admin_url( 'customize.php' ) ) )
   206 				esc_url( add_query_arg( 'autofocus[section]', 'custom_css', admin_url( 'customize.php' ) ) )
   206 			);
   207 			);
   207 			?>
   208 			?>
   208 		</p>
   209 		</p>
   210 <?php endif; ?>
   211 <?php endif; ?>
   211 
   212 
   212 <div class="fileedit-sub">
   213 <div class="fileedit-sub">
   213 <div class="alignleft">
   214 <div class="alignleft">
   214 <h2>
   215 <h2>
   215 <?php
   216 	<?php
   216 echo $theme->display( 'Name' );
   217 	echo $theme->display( 'Name' );
   217 if ( $description ) {
   218 	if ( $description ) {
   218 	echo ': ' . $description;}
   219 		echo ': ' . $description;}
   219 ?>
   220 	?>
   220 </h2>
   221 </h2>
   221 </div>
   222 </div>
   222 <div class="alignright">
   223 <div class="alignright">
   223 	<form action="theme-editor.php" method="get">
   224 	<form action="theme-editor.php" method="get">
   224 		<strong><label for="theme"><?php _e( 'Select theme to edit:' ); ?> </label></strong>
   225 		<strong><label for="theme"><?php _e( 'Select theme to edit:' ); ?> </label></strong>
   225 		<select name="theme" id="theme">
   226 		<select name="theme" id="theme">
   226 <?php
   227 		<?php
   227 foreach ( wp_get_themes( array( 'errors' => null ) ) as $a_stylesheet => $a_theme ) {
   228 		foreach ( wp_get_themes( array( 'errors' => null ) ) as $a_stylesheet => $a_theme ) {
   228 	if ( $a_theme->errors() && 'theme_no_stylesheet' == $a_theme->errors()->get_error_code() ) {
   229 			if ( $a_theme->errors() && 'theme_no_stylesheet' === $a_theme->errors()->get_error_code() ) {
   229 		continue;
   230 				continue;
   230 	}
   231 			}
   231 
   232 
   232 	$selected = $a_stylesheet == $stylesheet ? ' selected="selected"' : '';
   233 			$selected = ( $a_stylesheet === $stylesheet ) ? ' selected="selected"' : '';
   233 	echo "\n\t" . '<option value="' . esc_attr( $a_stylesheet ) . '"' . $selected . '>' . $a_theme->display( 'Name' ) . '</option>';
   234 			echo "\n\t" . '<option value="' . esc_attr( $a_stylesheet ) . '"' . $selected . '>' . $a_theme->display( 'Name' ) . '</option>';
   234 }
   235 		}
   235 ?>
   236 		?>
   236 		</select>
   237 		</select>
   237 		<?php submit_button( __( 'Select' ), '', 'Submit', false ); ?>
   238 		<?php submit_button( __( 'Select' ), '', 'Submit', false ); ?>
   238 	</form>
   239 	</form>
   239 </div>
   240 </div>
   240 <br class="clear" />
   241 <br class="clear" />
   241 </div>
   242 </div>
       
   243 
   242 <?php
   244 <?php
   243 if ( $theme->errors() ) {
   245 if ( $theme->errors() ) {
   244 	echo '<div class="error"><p><strong>' . __( 'This theme is broken.' ) . '</strong> ' . $theme->errors()->get_error_message() . '</p></div>';
   246 	echo '<div class="error"><p><strong>' . __( 'This theme is broken.' ) . '</strong> ' . $theme->errors()->get_error_message() . '</p></div>';
   245 }
   247 }
   246 ?>
   248 ?>
       
   249 
   247 <div id="templateside">
   250 <div id="templateside">
   248 	<h2 id="theme-files-label"><?php _e( 'Theme Files' ); ?></h2>
   251 	<h2 id="theme-files-label"><?php _e( 'Theme Files' ); ?></h2>
   249 	<ul role="tree" aria-labelledby="theme-files-label">
   252 	<ul role="tree" aria-labelledby="theme-files-label">
   250 		<?php if ( ( $has_templates || $theme->parent() ) && $theme->parent() ) : ?>
   253 		<?php if ( $theme->parent() ) : ?>
   251 			<li class="howto">
   254 			<li class="howto">
   252 				<?php
   255 				<?php
   253 				/* translators: %s: link to edit parent theme */
   256 				printf(
   254 				echo sprintf(
   257 					/* translators: %s: Link to edit parent theme. */
   255 					__( 'This child theme inherits templates from a parent theme, %s.' ),
   258 					__( 'This child theme inherits templates from a parent theme, %s.' ),
   256 					sprintf(
   259 					sprintf(
   257 						'<a href="%s">%s</a>',
   260 						'<a href="%s">%s</a>',
   258 						self_admin_url( 'theme-editor.php?theme=' . urlencode( $theme->get_template() ) ),
   261 						self_admin_url( 'theme-editor.php?theme=' . urlencode( $theme->get_template() ) ),
   259 						$theme->parent()->display( 'Name' )
   262 						$theme->parent()->display( 'Name' )
   270 	</ul>
   273 	</ul>
   271 </div>
   274 </div>
   272 
   275 
   273 <?php
   276 <?php
   274 if ( $error ) :
   277 if ( $error ) :
   275 	echo '<div class="error"><p>' . __( 'Oops, no such file exists! Double check the name and try again, merci.' ) . '</p></div>';
   278 	echo '<div class="error"><p>' . __( 'File does not exist! Please double check the name and try again.' ) . '</p></div>';
   276 else :
   279 else :
   277 	?>
   280 	?>
   278 	<form name="template" id="template" action="theme-editor.php" method="post">
   281 	<form name="template" id="template" action="theme-editor.php" method="post">
   279 		<?php wp_nonce_field( 'edit-theme_' . $stylesheet . '_' . $relative_file, 'nonce' ); ?>
   282 		<?php wp_nonce_field( 'edit-theme_' . $stylesheet . '_' . $relative_file, 'nonce' ); ?>
   280 		<div>
   283 		<div>
   282 			<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>
   285 			<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>
   283 			<input type="hidden" name="action" value="update" />
   286 			<input type="hidden" name="action" value="update" />
   284 			<input type="hidden" name="file" value="<?php echo esc_attr( $relative_file ); ?>" />
   287 			<input type="hidden" name="file" value="<?php echo esc_attr( $relative_file ); ?>" />
   285 			<input type="hidden" name="theme" value="<?php echo esc_attr( $theme->get_stylesheet() ); ?>" />
   288 			<input type="hidden" name="theme" value="<?php echo esc_attr( $theme->get_stylesheet() ); ?>" />
   286 		</div>
   289 		</div>
   287 	<?php if ( ! empty( $functions ) ) : ?>
   290 
   288 		<div id="documentation" class="hide-if-no-js">
   291 		<?php if ( ! empty( $functions ) ) : ?>
   289 		<label for="docs-list"><?php _e( 'Documentation:' ); ?></label>
   292 			<div id="documentation" class="hide-if-no-js">
   290 		<?php echo $docs_select; ?>
   293 				<label for="docs-list"><?php _e( 'Documentation:' ); ?></label>
   291 		<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() ) + '&amp;locale=<?php echo urlencode( get_user_locale() ); ?>&amp;version=<?php echo urlencode( get_bloginfo( 'version' ) ); ?>&amp;redirect=true'); }" />
   294 				<?php echo $docs_select; ?>
   292 		</div>
   295 				<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() ) + '&amp;locale=<?php echo urlencode( get_user_locale() ); ?>&amp;version=<?php echo urlencode( get_bloginfo( 'version' ) ); ?>&amp;redirect=true'); }" />
   293 	<?php endif; ?>
   296 			</div>
   294 
   297 		<?php endif; ?>
   295 	<div>
   298 
   296 		<div class="editor-notices">
   299 		<div>
   297 			<?php if ( is_child_theme() && $theme->get_stylesheet() == get_template() ) : ?>
   300 			<div class="editor-notices">
   298 				<div class="notice notice-warning inline">
   301 				<?php if ( is_child_theme() && $theme->get_stylesheet() === get_template() ) : ?>
   299 					<p>
   302 					<div class="notice notice-warning inline">
   300 						<?php
   303 						<p>
   301 						if ( is_writeable( $file ) ) {
   304 							<?php if ( is_writeable( $file ) ) : ?>
   302 							?>
   305 								<strong><?php _e( 'Caution:' ); ?></strong>
   303 						<strong><?php _e( 'Caution:' ); ?></strong><?php } ?>
   306 							<?php endif; ?>
   304 						<?php _e( 'This is a file in your current parent theme.' ); ?>
   307 							<?php _e( 'This is a file in your current parent theme.' ); ?>
   305 					</p>
   308 						</p>
   306 				</div>
   309 					</div>
       
   310 				<?php endif; ?>
       
   311 			</div>
       
   312 			<?php if ( is_writeable( $file ) ) : ?>
       
   313 				<p class="submit">
       
   314 					<?php submit_button( __( 'Update File' ), 'primary', 'submit', false ); ?>
       
   315 					<span class="spinner"></span>
       
   316 				</p>
       
   317 			<?php else : ?>
       
   318 				<p><em>
       
   319 					<?php
       
   320 					printf(
       
   321 						/* translators: %s: Documentation URL. */
       
   322 						__( 'You need to make this file writable before you can save your changes. See <a href="%s">Changing File Permissions</a> for more information.' ),
       
   323 						__( 'https://wordpress.org/support/article/changing-file-permissions/' )
       
   324 					);
       
   325 					?>
       
   326 				</em></p>
   307 			<?php endif; ?>
   327 			<?php endif; ?>
   308 		</div>
   328 		</div>
   309 	<?php if ( is_writeable( $file ) ) : ?>
   329 
   310 		<p class="submit">
   330 		<?php wp_print_file_editor_templates(); ?>
   311 			<?php submit_button( __( 'Update File' ), 'primary', 'submit', false ); ?>
       
   312 			<span class="spinner"></span>
       
   313 		</p>
       
   314 	<?php else : ?>
       
   315 		<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>
       
   316 	<?php endif; ?>
       
   317 	</div>
       
   318 	<?php wp_print_file_editor_templates(); ?>
       
   319 	</form>
   331 	</form>
   320 	<?php
   332 	<?php
   321 endif; // $error
   333 endif; // End if $error.
   322 ?>
   334 ?>
   323 <br class="clear" />
   335 <br class="clear" />
   324 </div>
   336 </div>
   325 <?php
   337 <?php
   326 $dismissed_pointers = explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) );
   338 $dismissed_pointers = explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) );
   327 if ( ! in_array( 'theme_editor_notice', $dismissed_pointers, true ) ) :
   339 if ( ! in_array( 'theme_editor_notice', $dismissed_pointers, true ) ) :
   328 	// Get a back URL
   340 	// Get a back URL.
   329 	$referer                    = wp_get_referer();
   341 	$referer = wp_get_referer();
       
   342 
   330 	$excluded_referer_basenames = array( 'theme-editor.php', 'wp-login.php' );
   343 	$excluded_referer_basenames = array( 'theme-editor.php', 'wp-login.php' );
   331 
   344 
   332 	if ( $referer && ! in_array( basename( parse_url( $referer, PHP_URL_PATH ) ), $excluded_referer_basenames, true ) ) {
   345 	if ( $referer && ! in_array( basename( parse_url( $referer, PHP_URL_PATH ) ), $excluded_referer_basenames, true ) ) {
   333 		$return_url = $referer;
   346 		$return_url = $referer;
   334 	} else {
   347 	} else {
   335 		$return_url = admin_url( '/' );
   348 		$return_url = admin_url( '/' );
   336 	}
   349 	}
   337 	?>
   350 	?>
   338 <div id="file-editor-warning" class="notification-dialog-wrap file-editor-warning hide-if-no-js hidden">
   351 	<div id="file-editor-warning" class="notification-dialog-wrap file-editor-warning hide-if-no-js hidden">
   339 	<div class="notification-dialog-background"></div>
   352 		<div class="notification-dialog-background"></div>
   340 	<div class="notification-dialog">
   353 		<div class="notification-dialog">
   341 		<div class="file-editor-warning-content">
   354 			<div class="file-editor-warning-content">
   342 			<div class="file-editor-warning-message">
   355 				<div class="file-editor-warning-message">
   343 				<h1><?php _e( 'Heads up!' ); ?></h1>
   356 					<h1><?php _e( 'Heads up!' ); ?></h1>
       
   357 					<p>
       
   358 						<?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.' );
       
   360 						?>
       
   361 					</p>
       
   362 						<?php
       
   363 						if ( ! $theme->parent() ) {
       
   364 							echo '<p>';
       
   365 							printf(
       
   366 								/* translators: %s: Link to documentation on child themes. */
       
   367 								__( '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>.' ),
       
   368 								esc_url( __( 'https://developer.wordpress.org/themes/advanced-topics/child-themes/' ) )
       
   369 							);
       
   370 							echo '</p>';
       
   371 						}
       
   372 						?>
       
   373 					<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>
       
   374 				</div>
   344 				<p>
   375 				<p>
   345 					<?php
   376 					<a class="button file-editor-warning-go-back" href="<?php echo esc_url( $return_url ); ?>"><?php _e( 'Go back' ); ?></a>
   346 					echo sprintf(
   377 					<button type="button" class="file-editor-warning-dismiss button button-primary"><?php _e( 'I understand' ); ?></button>
   347 						/* translators: %s: link to documentation on child themes */
       
   348 						__( '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>.' ),
       
   349 						esc_url( __( 'https://developer.wordpress.org/themes/advanced-topics/child-themes/' ) )
       
   350 					);
       
   351 					?>
       
   352 				</p>
   378 				</p>
   353 				<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>
       
   354 			</div>
   379 			</div>
   355 			<p>
       
   356 				<a class="button file-editor-warning-go-back" href="<?php echo esc_url( $return_url ); ?>"><?php _e( 'Go back' ); ?></a>
       
   357 				<button type="button" class="file-editor-warning-dismiss button button-primary"><?php _e( 'I understand' ); ?></button>
       
   358 			</p>
       
   359 		</div>
   380 		</div>
   360 	</div>
   381 	</div>
   361 </div>
       
   362 	<?php
   382 	<?php
   363 endif; // editor warning notice
   383 endif; // Editor warning notice.
   364 
   384 
   365 include( ABSPATH . 'wp-admin/admin-footer.php' );
   385 require_once ABSPATH . 'wp-admin/admin-footer.php';