diff --git src/wp-admin/css/common.css src/wp-admin/css/common.css
index 6fe50ac93c..d22368d637 100644
|
|
h1.nav-tab-wrapper, /* Back-compat for pre-4.4 */ |
2203 | 2203 | #template > div { |
2204 | 2204 | margin-right: 190px; |
2205 | 2205 | } |
| 2206 | #template .active-plugin-edit-warning { |
| 2207 | margin-top: 1em; |
| 2208 | margin-right: 30%; |
| 2209 | margin-right: calc( 184px + 3% ); |
| 2210 | } |
| 2211 | #template .active-plugin-edit-warning p { |
| 2212 | width: auto; |
| 2213 | } |
2206 | 2214 | |
2207 | 2215 | .metabox-holder .stuffbox > h3, /* Back-compat for pre-4.4 */ |
2208 | 2216 | .metabox-holder .postbox > h3, /* Back-compat for pre-4.4 */ |
… |
… |
img { |
3609 | 3617 | margin-top: -5px; |
3610 | 3618 | } |
3611 | 3619 | |
3612 | | #template > div { |
| 3620 | #template > div, |
| 3621 | #template .active-plugin-edit-warning { |
3613 | 3622 | float: none; |
3614 | | margin: 0; |
| 3623 | margin: 1em 0; |
3615 | 3624 | width: auto; |
3616 | 3625 | } |
3617 | 3626 | |
diff --git src/wp-admin/includes/plugin.php src/wp-admin/includes/plugin.php
index 7d804e1c66..ba6df12a9c 100644
|
|
function activate_plugin( $plugin, $redirect = '', $network_wide = false, $silen |
555 | 555 | if ( !empty($redirect) ) |
556 | 556 | wp_redirect(add_query_arg('_error_nonce', wp_create_nonce('plugin-activation-error_' . $plugin), $redirect)); // we'll override this later if the plugin can be included without fatal error |
557 | 557 | ob_start(); |
558 | | wp_register_plugin_realpath( WP_PLUGIN_DIR . '/' . $plugin ); |
559 | | $_wp_plugin_file = $plugin; |
560 | | include_once( WP_PLUGIN_DIR . '/' . $plugin ); |
561 | | $plugin = $_wp_plugin_file; // Avoid stomping of the $plugin variable in a plugin. |
| 558 | |
| 559 | plugin_sandbox_scrape( $plugin ); |
562 | 560 | |
563 | 561 | if ( ! $silent ) { |
564 | 562 | /** |
… |
… |
function wp_clean_plugins_cache( $clear_update_cache = true ) { |
1881 | 1879 | } |
1882 | 1880 | |
1883 | 1881 | /** |
1884 | | * @param string $plugin |
| 1882 | * Simulate loading the WordPress admin with a given plugin active to attempt to generate errors. |
| 1883 | * |
| 1884 | * Actions are re-triggered in the WP bootstrap process for the WP Admin, and the WP_ADMIN constant is defined. |
| 1885 | * |
| 1886 | * @since 3.0.0 |
| 1887 | * @since 4.4.0 Function was moved into the `wp-admin/includes/plugin.php` file. |
| 1888 | * @since 4.9.0 Add defining of WP_ADMIN and triggering admin WP bootstrap actions. |
| 1889 | * |
| 1890 | * @global array $wp_actions |
| 1891 | * @param string $plugin Plugin file to load. |
1885 | 1892 | */ |
1886 | 1893 | function plugin_sandbox_scrape( $plugin ) { |
| 1894 | global $wp_actions; |
1887 | 1895 | wp_register_plugin_realpath( WP_PLUGIN_DIR . '/' . $plugin ); |
| 1896 | |
| 1897 | if ( ! defined( 'WP_ADMIN' ) ) { |
| 1898 | define( 'WP_ADMIN', true ); |
| 1899 | } |
| 1900 | |
| 1901 | $tested_actions = array( |
| 1902 | 'plugins_loaded' => array(), |
| 1903 | 'setup_theme' => array(), |
| 1904 | 'after_setup_theme' => array(), |
| 1905 | 'init' => array(), |
| 1906 | 'wp_loaded' => array(), |
| 1907 | 'admin_init' => array(), |
| 1908 | ); |
| 1909 | $old_wp_actions = $wp_actions; |
| 1910 | array_map( 'remove_all_actions', array_keys( $tested_actions ) ); |
| 1911 | |
1888 | 1912 | include( WP_PLUGIN_DIR . '/' . $plugin ); |
| 1913 | |
| 1914 | // Trigger key actions that are done on the plugin editor to cause the relevant plugin hooks to fire and potentially cause errors. |
| 1915 | foreach ( $tested_actions as $action => $args ) { |
| 1916 | do_action_ref_array( $action, $args ); |
| 1917 | } |
| 1918 | |
| 1919 | $wp_actions = $old_wp_actions; // Restore actions. |
1889 | 1920 | } |
diff --git src/wp-admin/plugin-editor.php src/wp-admin/plugin-editor.php
index 14d2b65039..239316ae2b 100644
|
|
if ( isset( $_REQUEST['plugin'] ) ) { |
46 | 46 | |
47 | 47 | if ( empty( $plugin ) ) { |
48 | 48 | if ( $file ) { |
49 | | $plugin = $file; |
| 49 | |
| 50 | // Locate the plugin for a given plugin file being edited. |
| 51 | $file_dirname = dirname( $file ); |
| 52 | foreach ( array_keys( $plugins ) as $plugin_candidate ) { |
| 53 | if ( $plugin_candidate === $file || ( '.' !== $file_dirname && dirname( $plugin_candidate ) === $file_dirname ) ) { |
| 54 | $plugin = $plugin_candidate; |
| 55 | break; |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | // Fallback to the file as the plugin. |
| 60 | if ( empty( $plugin ) ) { |
| 61 | $plugin = $file; |
| 62 | } |
50 | 63 | } else { |
51 | 64 | $plugin = array_keys( $plugins ); |
52 | 65 | $plugin = $plugin[0]; |
… |
… |
if ( isset( $_REQUEST['action'] ) && 'update' === $_REQUEST['action'] ) { |
72 | 85 | fwrite($f, $newcontent); |
73 | 86 | fclose($f); |
74 | 87 | |
| 88 | if ( preg_match( '/\.php$/', $real_file ) && function_exists( 'opcache_invalidate' ) ) { |
| 89 | opcache_invalidate( $real_file, true ); |
| 90 | } |
| 91 | |
75 | 92 | $network_wide = is_plugin_active_for_network( $file ); |
76 | 93 | |
77 | 94 | // Deactivate so we can test it. |
… |
… |
if ( isset( $_REQUEST['action'] ) && 'update' === $_REQUEST['action'] ) { |
220 | 237 | <?php if (isset($_GET['a'])) : ?> |
221 | 238 | <div id="message" class="updated notice is-dismissible"><p><?php _e('File edited successfully.') ?></p></div> |
222 | 239 | <?php elseif (isset($_GET['phperror'])) : ?> |
223 | | <div id="message" class="updated"><p><?php _e('This plugin has been deactivated because your changes resulted in a <strong>fatal error</strong>.') ?></p> |
| 240 | <div id="message" class="notice notice-error"><p><?php _e( 'This plugin has been deactivated because your changes resulted in a <strong>fatal error</strong>.' ); ?></p> |
224 | 241 | <?php |
225 | | if ( wp_verify_nonce( $_GET['_error_nonce'], 'plugin-activation-error_' . $file ) ) { |
| 242 | if ( wp_verify_nonce( $_GET['_error_nonce'], 'plugin-activation-error_' . $plugin ) ) { |
226 | 243 | $iframe_url = add_query_arg( array( |
227 | 244 | 'action' => 'error_scrape', |
228 | | 'plugin' => urlencode( $file ), |
| 245 | 'plugin' => urlencode( $plugin ), |
229 | 246 | '_wpnonce' => urlencode( $_GET['_error_nonce'] ), |
230 | 247 | ), admin_url( 'plugins.php' ) ); |
231 | 248 | ?> |
… |
… |
foreach ( $plugin_files as $plugin_file ) : |
315 | 332 | <?php endif; ?> |
316 | 333 | <?php if ( is_writeable($real_file) ) : ?> |
317 | 334 | <?php if ( in_array( $plugin, (array) get_option( 'active_plugins', array() ) ) ) { ?> |
318 | | <p><?php _e('<strong>Warning:</strong> Making changes to active plugins is not recommended. If your changes cause a fatal error, the plugin will be automatically deactivated.'); ?></p> |
| 335 | <div class="notice notice-warning inline active-plugin-edit-warning"> |
| 336 | <p><?php _e('<strong>Warning:</strong> Making changes to active plugins is not recommended. If your changes cause a fatal error, the plugin will be automatically deactivated.'); ?></p> |
| 337 | </div> |
319 | 338 | <?php } ?> |
320 | 339 | <p class="submit"> |
321 | 340 | <?php |