Skip to content

Commit

Permalink
Make the theme and plugin file editor more consistent
Browse files Browse the repository at this point in the history
Update the header area of the theme and plugin file editors to be more consistent.

Display the name of theme or plugin, the active or inactive state, and the path to the file that is selected (including the file name).
  • Loading branch information
carolinan committed Dec 5, 2024
1 parent 7d3ce7a commit 250d0ca
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 17 deletions.
26 changes: 18 additions & 8 deletions src/wp-admin/plugin-editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@
$file = validate_file_to_edit( $file, $plugin_files );
$real_file = WP_PLUGIN_DIR . '/' . $file;

$plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin_files[0] );
$plugin_name = $plugin_data['Name'];

// Handle fallback editing of file when JavaScript is not available.
$edit_error = null;
$posted_content = null;
Expand Down Expand Up @@ -220,23 +223,30 @@
<?php
if ( is_plugin_active( $plugin ) ) {
if ( is_writable( $real_file ) ) {
/* translators: %s: Plugin file name. */
printf( __( 'Editing %s (active)' ), '<strong>' . esc_html( $file ) . '</strong>' );
/* translators: %s: Plugin name. */
printf( __( 'Editing %s (active)' ), '<strong>' . esc_html( $plugin_name ) . '</strong>' );
} else {
/* translators: %s: Plugin file name. */
printf( __( 'Browsing %s (active)' ), '<strong>' . esc_html( $file ) . '</strong>' );
/* translators: %s: Plugin name. */
printf( __( 'Browsing %s (active)' ), '<strong>' . esc_html( $plugin_name ) . '</strong>' );
}
} else {
if ( is_writable( $real_file ) ) {
/* translators: %s: Plugin file name. */
printf( __( 'Editing %s (inactive)' ), '<strong>' . esc_html( $file ) . '</strong>' );
/* translators: %s: Plugin name. */
printf( __( 'Editing %s (inactive)' ), '<strong>' . esc_html( $plugin_name ) . '</strong>' );
} else {
/* translators: %s: Plugin file name. */
printf( __( 'Browsing %s (inactive)' ), '<strong>' . esc_html( $file ) . '</strong>' );
/* translators: %s: Plugin name. */
printf( __( 'Browsing %s (inactive)' ), '<strong>' . esc_html( $plugin_name ) . '</strong>' );
}
}
?>
</h2>
<?php
printf(
/* translators: %s: File path. */
' <span><strong>' . __( 'File: %s' ) . '</strong></span>',
esc_html( $file )
);
?>
</div>
<div class="alignright">
<form action="plugin-editor.php" method="get">
Expand Down
24 changes: 15 additions & 9 deletions src/wp-admin/theme-editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,7 @@
$content = esc_textarea( $content );
}

$file_description = get_file_description( $relative_file );
$file_show = array_search( $file, array_filter( $allowed_files ), true );
$description = esc_html( $file_description );
if ( $file_description !== $file_show ) {
$description .= ' <span>(' . esc_html( $file_show ) . ')</span>';
}
$file_show = array_search( $file, array_filter( $allowed_files ), true );
?>
<div class="wrap">
<h1><?php echo esc_html( $title ); ?></h1>
Expand Down Expand Up @@ -235,12 +230,23 @@
<div class="alignleft">
<h2>
<?php
echo $theme->display( 'Name' );
if ( $description ) {
echo ': ' . $description;
if ( wp_get_theme()->get( 'Name' ) === $theme->display( 'Name' ) ) {
/* translators: %s: Theme name. */
printf( __( 'Editing %s (active)' ), '<strong>' . $theme->display( 'Name' ) . '</strong>' );
} else {
/* translators: %s: Theme name. */
printf( __( 'Editing %s (inactive)' ), '<strong>' . $theme->display( 'Name' ) . '</strong>' );
}

?>
</h2>
<?php
printf(
/* translators: %s: File path. */
' <span><strong>' . __( 'File: %s' ) . '</strong></span>',
esc_html( $file_show )
);
?>
</div>
<div class="alignright">
<form action="theme-editor.php" method="get">
Expand Down

0 comments on commit 250d0ca

Please sign in to comment.