Make WordPress Core

Ticket #17552: 17552.2.patch

File 17552.2.patch, 7.4 KB (added by DrewAPicture, 9 years ago)

Refresh

  • src/wp-admin/plugin-editor.php

     
    3636        exit;
    3737}
    3838
    39 if ( $file ) {
    40         $plugin = $file;
    41 } elseif ( empty( $plugin ) ) {
    42         $plugin = array_keys($plugins);
    43         $plugin = $plugin[0];
     39if ( empty( $plugin ) ) {
     40        if ( $file ) {
     41                $plugin = $file;
     42        } elseif ( empty( $plugin ) ) {
     43                $plugin = array_keys($plugins);
     44                $plugin = $plugin[0];
     45        }
    4446}
    4547
    4648$plugin_files = get_plugin_files($plugin);
     
    5860
    5961        check_admin_referer('edit-plugin_' . $file);
    6062
    61         $newcontent = wp_unslash( $_POST['newcontent'] );
    62         if ( is_writeable($real_file) ) {
    63                 $f = fopen($real_file, 'w+');
    64                 fwrite($f, $newcontent);
    65                 fclose($f);
     63        if ( is_writeable( $real_file ) ) {
     64                $newcontent = wp_unslash( $_POST['newcontent'] );
    6665
    67                 $network_wide = is_plugin_active_for_network( $file );
     66                file_put_contents( $real_file, $newcontent );
    6867
     68                $network_wide = is_plugin_active_for_network( $plugin );
     69        // @TODO: Network Wide activated plugins do not go through this lint check
     70
    6971                // Deactivate so we can test it.
    70                 if ( is_plugin_active($file) || isset($_POST['phperror']) ) {
    71                         if ( is_plugin_active($file) )
    72                                 deactivate_plugins($file, true);
     72                if ( is_plugin_active( $plugin ) || isset($_POST['phperror'] ) ) {
     73                        if ( is_plugin_active( $plugin ) )
     74                                deactivate_plugins( $plugin, true );
    7375
    7476                        if ( ! is_network_admin() ) {
    75                                 update_option( 'recently_activated', array( $file => time() ) + (array) get_option( 'recently_activated' ) );
     77                                update_option( 'recently_activated', array( $plugin => time() ) + (array) get_option( 'recently_activated' ) );
    7678                        } else {
    77                                 update_network_option( 'recently_activated', array( $file => time() ) + (array) get_network_option( 'recently_activated' ) );
     79                                update_network_option( 'recently_activated', array( $plugin => time() ) + (array) get_network_option( 'recently_activated' ) );
    7880                        }
    7981
    80                         wp_redirect(add_query_arg('_wpnonce', wp_create_nonce('edit-plugin-test_' . $file), "plugin-editor.php?file=$file&liveupdate=1&scrollto=$scrollto&networkwide=" . $network_wide));
     82                        wp_redirect(add_query_arg('_wpnonce', wp_create_nonce( 'edit-plugin-test_' . $file ), "plugin-editor.php?file=$plugin&liveupdate=1&scrollto=$scrollto&networkwide=" . $network_wide));
    8183                        exit;
    8284                }
    83                 wp_redirect( self_admin_url("plugin-editor.php?file=$file&a=te&scrollto=$scrollto") );
     85                wp_redirect( self_admin_url("plugin-editor.php?file=$file&plugin=$plugin&updated=1&scrollto=$scrollto") );
    8486        } else {
    85                 wp_redirect( self_admin_url("plugin-editor.php?file=$file&scrollto=$scrollto") );
     87                wp_redirect( self_admin_url("plugin-editor.php?file=$file&plugin=$plugin&scrollto=$scrollto") );
    8688        }
    8789        exit;
    8890
     
    9193        if ( isset($_GET['liveupdate']) ) {
    9294                check_admin_referer('edit-plugin-test_' . $file);
    9395
    94                 $error = validate_plugin($file);
     96                $error = validate_plugin( $plugin );
    9597                if ( is_wp_error($error) )
    9698                        wp_die( $error );
    9799
    98                 if ( ( ! empty( $_GET['networkwide'] ) && ! is_plugin_active_for_network($file) ) || ! is_plugin_active($file) )
    99                         activate_plugin($file, "plugin-editor.php?file=$file&phperror=1", ! empty( $_GET['networkwide'] ) ); // we'll override this later if the plugin can be included without fatal error
     100                if ( ( ! empty( $_GET['networkwide'] ) && ! is_plugin_active_for_network( $plugin ) ) | is_plugin_active( $plugin ) ) {
     101                        activate_plugin( $plugin, "plugin-editor.php?file=$file&plugin=$plugin&phperror=1", ! empty( $_GET['networkwide'] ) ); // we'll override this later if the plugin can be included without fatal error
     102                }
    100103
    101                 wp_redirect( self_admin_url("plugin-editor.php?file=$file&a=te&scrollto=$scrollto") );
     104                wp_redirect( self_admin_url("plugin-editor.php?file=$file&plugin=$plugin&updated=1&scrollto=$scrollto") );
    102105                exit;
    103106        }
    104107
     
    115118        $editable_extensions = (array) apply_filters( 'editable_extensions', $editable_extensions );
    116119
    117120        if ( ! is_file($real_file) ) {
    118                 wp_die(sprintf('<p>%s</p>', __('No such file exists! Double check the name and try again.')));
     121                wp_die(  __( 'No such file exists! Double check the name and try again.' ) );
    119122        } else {
    120123                // Get the extension of the file
    121124                if ( preg_match('/\.([^.]+)$/', $real_file, $matches) ) {
     
    122125                        $ext = strtolower($matches[1]);
    123126                        // If extension is not in the acceptable list, skip it
    124127                        if ( !in_array( $ext, $editable_extensions) )
    125                                 wp_die(sprintf('<p>%s</p>', __('Files of this type are not editable.')));
     128                                wp_die( __( 'Files of this type are not editable.' ) );
    126129                }
    127130        }
    128131
     
    147150
    148151        require_once(ABSPATH . 'wp-admin/admin-header.php');
    149152
    150         update_recently_edited(WP_PLUGIN_DIR . '/' . $file);
     153        update_recently_edited( WP_PLUGIN_DIR . '/' . $plugin );
    151154
    152155        $content = file_get_contents( $real_file );
    153156
     
    166169
    167170        $content = esc_textarea( $content );
    168171        ?>
    169 <?php if (isset($_GET['a'])) : ?>
     172<?php if ( isset( $_GET['updated'] ) ) : ?>
    170173 <div id="message" class="updated notice is-dismissible"><p><?php _e('File edited successfully.') ?></p></div>
    171174<?php elseif (isset($_GET['phperror'])) : ?>
    172175 <div id="message" class="updated"><p><?php _e('This plugin has been deactivated because your changes resulted in a <strong>fatal error</strong>.') ?></p>
    173176        <?php
    174                 if ( wp_verify_nonce($_GET['_error_nonce'], 'plugin-activation-error_' . $file) ) { ?>
    175         <iframe style="border:0" width="100%" height="70px" src="<?php bloginfo('wpurl'); ?>/wp-admin/plugins.php?action=error_scrape&amp;plugin=<?php echo esc_attr($file); ?>&amp;_wpnonce=<?php echo esc_attr($_GET['_error_nonce']); ?>"></iframe>
    176         <?php } ?>
     177        if ( wp_verify_nonce($_GET['_error_nonce'], 'plugin-activation-error_' . $plugin ) ) :
     178                //@TODO: Is this Network Admin safe? (admin_url()) ?>
     179                <iframe style="border:0" width="100%" height="70px" src="<?php echo admin_url('plugins.php?action=error_scrape&plugin=' . urlencode($plugin) . '&_wpnonce=' . urlencode($_GET['_error_nonce']) ); ?>"></iframe>
     180        <?php endif; ?>
    177181</div>
    178182<?php endif; ?>
    179183<div class="wrap">
     
    182186<div class="fileedit-sub">
    183187<div class="alignleft">
    184188<big><?php
    185         if ( is_plugin_active( $plugin ) ) {
     189        if ( is_plugin_active( $plugin ) || is_plugin_active_for_network( $plugin ) ) {
    186190                if ( is_writeable( $real_file ) ) {
    187191                        /* translators: %s: plugin file name */
    188192                        echo sprintf( __( 'Editing %s (active)' ), '<strong>' . $file . '</strong>' );
     
    257261                <div id="documentation" class="hide-if-no-js"><label for="docs-list"><?php _e('Documentation:') ?></label> <?php echo $docs_select ?> <input 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_locale() ) ?>&amp;version=<?php echo urlencode( $wp_version ) ?>&amp;redirect=true'); }" /></div>
    258262                <?php endif; ?>
    259263<?php if ( is_writeable($real_file) ) : ?>
    260         <?php if ( in_array( $file, (array) get_option( 'active_plugins', array() ) ) ) { ?>
     264        <?php if ( s_plugin_active( $plugin ) || is_plugin_active_for_network( $plugin ) ) : ?>
    261265                <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>
    262         <?php } ?>
     266        <?php endif; ?>
    263267        <p class="submit">
    264268        <?php
    265269                if ( isset($_GET['phperror']) ) {