Skip to content

Commit 3fcfefd

Browse files
committed
File Editors: Introduce sandboxed live editing of PHP files with rollbacks for both themes and plugins.
* Edits to active plugins which cause PHP fatal errors will no longer auto-deactivate the plugin. Supersedes #39766. * Introduce sandboxed PHP file edits for active themes, preventing accidental whitescreening of a user's site when introducing a fatal error. * After writing a change to a PHP file for an active theme or plugin, perform loopback requests on the file editor admin screens and the homepage to check for fatal errors. If a fatal error is encountered, roll back the edited file and display the error to the user to fix and try again. * Introduce a secure way to scrape PHP fatal errors from a site via `wp_start_scraping_edited_file_errors()` and `wp_finalize_scraping_edited_file_errors()`. * Moves file modifications from `theme-editor.php` and `plugin-editor.php` to common `wp_edit_theme_plugin_file()` function. * Refactor themes and plugin editors to submit file changes via Ajax instead of doing full page refreshes when JS is available. * Use `get` method for theme/plugin dropdowns. * Improve styling of plugin editors, including width of plugin/theme dropdowns. * Improve notices API for theme/plugin editor JS component. * Strip common base directory from plugin file list. See #24048. * Factor out functions to list editable file types in `wp_get_theme_file_editable_extensions()` and `wp_get_plugin_file_editable_extensions()`. * Scroll to line in editor that has linting error when attempting to save. See #41886. * Add checkbox to dismiss lint errors to proceed with saving. See #41887. * Only style the Update File button as disabled instead of actually disabling it for accessibility reasons. * Ensure that value from CodeMirror is used instead of `textarea` when CodeMirror is present. * Add "Are you sure?" check when leaving editor when there are unsaved changes. Supersedes [41560]. See #39766, #24048, #41886. Props westonruter, Clorith, melchoyce, johnbillion, jjj, jdgrimes, azaozz. Fixes #21622, #41887. git-svn-id: https://develop.svn.wordpress.org/trunk@41721 602fd350-edb4-49c9-b593-d223f7449a82
1 parent e965140 commit 3fcfefd

11 files changed

Lines changed: 867 additions & 291 deletions

File tree

src/wp-admin/admin-ajax.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
'parse-media-shortcode', 'destroy-sessions', 'install-plugin', 'update-plugin', 'crop-image',
6565
'generate-password', 'save-wporg-username', 'delete-plugin', 'search-plugins',
6666
'search-install-plugins', 'activate-plugin', 'update-theme', 'delete-theme', 'install-theme',
67-
'get-post-thumbnail-html', 'get-community-events',
67+
'get-post-thumbnail-html', 'get-community-events', 'edit-theme-plugin-file',
6868
);
6969

7070
// Deprecated

src/wp-admin/css/common.css

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2217,14 +2217,16 @@ h1.nav-tab-wrapper, /* Back-compat for pre-4.4 */
22172217
#template > div {
22182218
margin-right: 190px;
22192219
}
2220-
#template .active-plugin-edit-warning {
2220+
#template .notice {
22212221
margin-top: 1em;
2222-
margin-right: 30%;
2223-
margin-right: calc( 184px + 3% );
2222+
margin-right: 3%;
22242223
}
2225-
#template .active-plugin-edit-warning p {
2224+
#template .notice p {
22262225
width: auto;
22272226
}
2227+
#template .submit .spinner {
2228+
float: none;
2229+
}
22282230

22292231
.metabox-holder .stuffbox > h3, /* Back-compat for pre-4.4 */
22302232
.metabox-holder .postbox > h3, /* Back-compat for pre-4.4 */
@@ -3032,10 +3034,14 @@ img {
30323034
#template textarea,
30333035
#template .CodeMirror {
30343036
width: 97%;
3035-
height: calc( 100vh - 220px );
3037+
height: calc( 100vh - 280px );
3038+
}
3039+
#templateside {
3040+
margin-top: 31px;
3041+
overflow: scroll;
30363042
}
30373043

3038-
#template label {
3044+
#theme-plugin-editor-label {
30393045
display: inline-block;
30403046
margin-bottom: 1em;
30413047
font-weight: 600;
@@ -3047,6 +3053,14 @@ img {
30473053
direction: ltr;
30483054
}
30493055

3056+
.fileedit-sub #theme,
3057+
.fileedit-sub #plugin {
3058+
max-width: 40%;
3059+
}
3060+
.fileedit-sub .alignright {
3061+
text-align: right;
3062+
}
3063+
30503064
#template p {
30513065
width: 97%;
30523066
}
@@ -3624,7 +3638,7 @@ img {
36243638
}
36253639

36263640
#template > div,
3627-
#template .active-plugin-edit-warning {
3641+
#template .notice {
36283642
float: none;
36293643
margin: 1em 0;
36303644
width: auto;

src/wp-admin/includes/ajax-actions.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3966,3 +3966,26 @@ function wp_ajax_search_install_plugins() {
39663966

39673967
wp_send_json_success( $status );
39683968
}
3969+
3970+
/**
3971+
* Ajax handler for editing a theme or plugin file.
3972+
*
3973+
* @since 4.9.0
3974+
* @see wp_edit_theme_plugin_file()
3975+
*/
3976+
function wp_ajax_edit_theme_plugin_file() {
3977+
$r = wp_edit_theme_plugin_file( wp_unslash( $_POST ) ); // Validation of args is done in wp_edit_theme_plugin_file().
3978+
if ( is_wp_error( $r ) ) {
3979+
wp_send_json_error( array_merge(
3980+
array(
3981+
'code' => $r->get_error_code(),
3982+
'message' => $r->get_error_message(),
3983+
),
3984+
(array) $r->get_error_data()
3985+
) );
3986+
} else {
3987+
wp_send_json_success( array(
3988+
'message' => __( 'File edited successfully.' ),
3989+
) );
3990+
}
3991+
}

0 commit comments

Comments
 (0)