diff -r 3d4e9c994f10 -r a86126ab1dd4 wp/wp-admin/theme-editor.php --- a/wp/wp-admin/theme-editor.php Tue Oct 22 16:11:46 2019 +0200 +++ b/wp/wp-admin/theme-editor.php Tue Dec 15 13:49:49 2020 +0100 @@ -7,11 +7,11 @@ */ /** WordPress Administration Bootstrap */ -require_once( dirname( __FILE__ ) . '/admin.php' ); +require_once __DIR__ . '/admin.php'; if ( is_multisite() && ! is_network_admin() ) { wp_redirect( network_admin_url( 'theme-editor.php' ) ); - exit(); + exit; } if ( ! current_user_can( 'edit_themes' ) ) { @@ -38,7 +38,7 @@ '
' . __( 'After typing in your edits, click Update File.' ) . '
' . '' . __( 'Advice: Think very carefully about your site crashing if you are live-editing the theme currently in use.' ) . '
' . '' . sprintf( - /* translators: %s: link to documentation on child themes */ + /* translators: %s: Link to documentation on child themes. */ __( 'Upgrading to a newer version of the same theme will override changes made here. To avoid this, consider creating a child theme instead.' ), __( 'https://developer.wordpress.org/themes/advanced-topics/child-themes/' ) ) . '
' . @@ -48,10 +48,10 @@ get_current_screen()->set_help_sidebar( '' . __( 'For more information:' ) . '
' . - '' . __( 'Documentation on Theme Development' ) . '
' . - '' . __( 'Documentation on Using Themes' ) . '
' . - '' . __( 'Documentation on Editing Files' ) . '
' . - '' . __( 'Documentation on Template Tags' ) . '
' . + '' . __( 'Documentation on Theme Development' ) . '
' . + '' . __( 'Documentation on Using Themes' ) . '
' . + '' . __( 'Documentation on Editing Files' ) . '
' . + '' . __( 'Documentation on Template Tags' ) . '
' . '' . __( 'Support' ) . '
' ); @@ -69,12 +69,12 @@ wp_die( __( 'The requested theme does not exist.' ) ); } -if ( $theme->errors() && 'theme_no_stylesheet' == $theme->errors()->get_error_code() ) { +if ( $theme->errors() && 'theme_no_stylesheet' === $theme->errors()->get_error_code() ) { wp_die( __( 'The requested theme does not exist.' ) . ' ' . $theme->errors()->get_error_message() ); } -$allowed_files = $style_files = array(); -$has_templates = false; +$allowed_files = array(); +$style_files = array(); $file_types = wp_get_theme_file_editable_extensions( $theme ); @@ -82,7 +82,6 @@ switch ( $type ) { case 'php': $allowed_files += $theme->get_files( 'php', -1 ); - $has_templates = ! empty( $allowed_files ); break; case 'css': $style_files = $theme->get_files( 'css', -1 ); @@ -116,6 +115,7 @@ // Handle fallback editing of file when JavaScript is not available. $edit_error = null; $posted_content = null; + if ( 'POST' === $_SERVER['REQUEST_METHOD'] ) { $r = wp_edit_theme_plugin_file( wp_unslash( $_POST ) ); if ( is_wp_error( $r ) ) { @@ -138,49 +138,49 @@ } } - $settings = array( - 'codeEditor' => wp_enqueue_code_editor( compact( 'file' ) ), - ); - wp_enqueue_script( 'wp-theme-plugin-editor' ); - wp_add_inline_script( 'wp-theme-plugin-editor', sprintf( 'jQuery( function( $ ) { wp.themePluginEditor.init( $( "#template" ), %s ); } )', wp_json_encode( $settings ) ) ); - wp_add_inline_script( 'wp-theme-plugin-editor', 'wp.themePluginEditor.themeOrPlugin = "theme";' ); +$settings = array( + 'codeEditor' => wp_enqueue_code_editor( compact( 'file' ) ), +); +wp_enqueue_script( 'wp-theme-plugin-editor' ); +wp_add_inline_script( 'wp-theme-plugin-editor', sprintf( 'jQuery( function( $ ) { wp.themePluginEditor.init( $( "#template" ), %s ); } )', wp_json_encode( $settings ) ) ); +wp_add_inline_script( 'wp-theme-plugin-editor', 'wp.themePluginEditor.themeOrPlugin = "theme";' ); + +require_once ABSPATH . 'wp-admin/admin-header.php'; + +update_recently_edited( $file ); + +if ( ! is_file( $file ) ) { + $error = true; +} - require_once( ABSPATH . 'wp-admin/admin-header.php' ); +$content = ''; +if ( ! empty( $posted_content ) ) { + $content = $posted_content; +} elseif ( ! $error && filesize( $file ) > 0 ) { + $f = fopen( $file, 'r' ); + $content = fread( $f, filesize( $file ) ); - update_recently_edited( $file ); + if ( '.php' === substr( $file, strrpos( $file, '.' ) ) ) { + $functions = wp_doc_link_parse( $content ); - if ( ! is_file( $file ) ) { - $error = true; + $docs_select = ''; } - $content = ''; - if ( ! empty( $posted_content ) ) { - $content = $posted_content; - } elseif ( ! $error && filesize( $file ) > 0 ) { - $f = fopen( $file, 'r' ); - $content = fread( $f, filesize( $file ) ); - - if ( '.php' == substr( $file, strrpos( $file, '.' ) ) ) { - $functions = wp_doc_link_parse( $content ); + $content = esc_textarea( $content ); +} - $docs_select = ''; - } - - $content = esc_textarea( $content ); - } - - $file_description = get_file_description( $relative_file ); - $file_show = array_search( $file, array_filter( $allowed_files ) ); - $description = esc_html( $file_description ); - if ( $file_description != $file_show ) { - $description .= ' (' . esc_html( $file_show ) . ')'; - } - ?> +$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 .= ' (' . esc_html( $file_show ) . ')'; +} +?>get_error_message() ? $edit_error->get_error_message() : $edit_error->get_error_code() ); ?>
built-in CSS editor.' ), esc_url( add_query_arg( 'autofocus[section]', 'custom_css', admin_url( 'customize.php' ) ) ) ); @@ -212,46 +213,48 @@
' . __( 'This theme is broken.' ) . ' ' . $theme->errors()->get_error_message() . '
' . __( 'Oops, no such file exists! Double check the name and try again, merci.' ) . '
' . __( 'File does not exist! Please double check the name and try again.' ) . '
- - - -
-+ + + + +
++ + +
+ ++ Changing File Permissions for more information.' ), + __( 'https://wordpress.org/support/article/changing-file-permissions/' ) + ); + ?> +
- - -
- -the Codex for more information.' ); ?>
- -