Make WordPress Core

Ticket #17552: 17552.4.patch

File 17552.4.patch, 7.9 KB (added by DrewAPicture, 9 years ago)
  • 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        // Shared redirect arguments.
     64        $redirect_args = array(
     65                'file'     => $file,
     66                'plugin'   => $plugin,
     67                'scrollto' => $scrollto,
     68        );
    6669
    67                 $network_wide = is_plugin_active_for_network( $file );
     70        if ( is_writeable( $real_file ) ) {
     71                $newcontent = wp_unslash( $_POST['newcontent'] );
    6872
     73                file_put_contents( $real_file, $newcontent );
     74
     75                $network_wide = is_plugin_active_for_network( $plugin );
     76
    6977                // 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);
     78                if ( is_plugin_active( $plugin ) || isset($_POST['phperror'] ) ) {
     79                        if ( is_plugin_active( $plugin ) )
     80                                deactivate_plugins( $plugin, true );
    7381
    7482                        if ( ! is_network_admin() ) {
    75                                 update_option( 'recently_activated', array( $file => time() ) + (array) get_option( 'recently_activated' ) );
     83                                update_option( 'recently_activated', array( $plugin => time() ) + (array) get_option( 'recently_activated' ) );
    7684                        } else {
    77                                 update_network_option( 'recently_activated', array( $file => time() ) + (array) get_network_option( 'recently_activated' ) );
     85                                update_network_option( 'recently_activated', array( $plugin => time() ) + (array) get_network_option( 'recently_activated' ) );
    7886                        }
    7987
    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));
     88                        $redirect_args = array_merge( $redirect_args, array(
     89                                'liveupdate'  => 1,
     90                                'networkwide' => $network_wide,
     91                                '_wpnonce'    => wp_create_nonce( "edit-plugin-test_{$file}" ),
     92                        ) );
     93
     94                        wp_redirect( add_query_arg( $redirect_args, self_admin_url( 'plugin-editor.php' )  ) );
    8195                        exit;
    8296                }
    83                 wp_redirect( self_admin_url("plugin-editor.php?file=$file&a=te&scrollto=$scrollto") );
     97
     98                $redirect_args = array_merge( $redirect_args, array( 'updated'  => 1 ) );
     99                wp_redirect( add_query_arg( $redirect_args, self_admin_url( 'plugin-editor.php' ) ) );
    84100        } else {
    85                 wp_redirect( self_admin_url("plugin-editor.php?file=$file&scrollto=$scrollto") );
     101                wp_redirect( add_query_arg( $redirect_args, self_admin_url( 'plugin-editor.php' ) ) );
    86102        }
    87103        exit;
    88104
    89105default:
    90106
     107        // Shared redirect arguments.
     108        $redirect_args = array(
     109                'file'     => $file,
     110                'plugin'   => $plugin,
     111        );
     112
    91113        if ( isset($_GET['liveupdate']) ) {
    92114                check_admin_referer('edit-plugin-test_' . $file);
    93115
    94                 $error = validate_plugin($file);
     116                $error = validate_plugin( $plugin );
    95117                if ( is_wp_error($error) )
    96118                        wp_die( $error );
    97119
    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
     120                if ( ( ! empty( $_GET['networkwide'] ) && ! is_plugin_active_for_network( $plugin ) ) || is_plugin_active( $plugin ) ) {
    100121
    101                 wp_redirect( self_admin_url("plugin-editor.php?file=$file&a=te&scrollto=$scrollto") );
     122                        // we'll override this later if the plugin can be included without fatal error
     123                        $redirect_args = array_merge( $redirect_args, array( 'phperror' => 1 ) );
     124                        activate_plugin( $plugin, add_query_arg( $redirect_args, self_admin_url( 'plugin-editor.php' ) ), ! empty( $_GET['networkwide'] ) );
     125                }
     126
     127                $redirect_args = array_merge( $redirect_args, array(
     128                        'scrollto' => $scrollto,
     129                        'updated'  => 1
     130                ) );
     131                wp_redirect( add_query_arg( $redirect_args, self_admin_url( 'plugin-editor.php' ) ) );
    102132                exit;
    103133        }
    104134
     
    115145        $editable_extensions = (array) apply_filters( 'editable_extensions', $editable_extensions );
    116146
    117147        if ( ! is_file($real_file) ) {
    118                 wp_die(sprintf('<p>%s</p>', __('No such file exists! Double check the name and try again.')));
     148                wp_die(  __( 'No such file exists! Double check the name and try again.' ) );
    119149        } else {
    120150                // Get the extension of the file
    121151                if ( preg_match('/\.([^.]+)$/', $real_file, $matches) ) {
     
    122152                        $ext = strtolower($matches[1]);
    123153                        // If extension is not in the acceptable list, skip it
    124154                        if ( !in_array( $ext, $editable_extensions) )
    125                                 wp_die(sprintf('<p>%s</p>', __('Files of this type are not editable.')));
     155                                wp_die( __( 'Files of this type are not editable.' ) );
    126156                }
    127157        }
    128158
     
    147177
    148178        require_once(ABSPATH . 'wp-admin/admin-header.php');
    149179
    150         update_recently_edited(WP_PLUGIN_DIR . '/' . $file);
     180        update_recently_edited( WP_PLUGIN_DIR . '/' . $plugin );
    151181
    152182        $content = file_get_contents( $real_file );
    153183
     
    166196
    167197        $content = esc_textarea( $content );
    168198        ?>
    169 <?php if (isset($_GET['a'])) : ?>
     199<?php if ( isset( $_GET['updated'] ) ) : ?>
    170200 <div id="message" class="updated notice is-dismissible"><p><?php _e('File edited successfully.') ?></p></div>
    171201<?php elseif (isset($_GET['phperror'])) : ?>
    172202 <div id="message" class="updated"><p><?php _e('This plugin has been deactivated because your changes resulted in a <strong>fatal error</strong>.') ?></p>
    173203        <?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 } ?>
     204        if ( wp_verify_nonce($_GET['_error_nonce'], 'plugin-activation-error_' . $plugin ) ) : ?>
     205                <iframe style="border:0" width="100%" height="70px" src="<?php echo self_admin_url('plugins.php?action=error_scrape&plugin=' . urlencode($plugin) . '&_wpnonce=' . urlencode($_GET['_error_nonce']) ); ?>"></iframe>
     206        <?php endif; ?>
    177207</div>
    178208<?php endif; ?>
    179209<div class="wrap">
     
    182212<div class="fileedit-sub">
    183213<div class="alignleft">
    184214<big><?php
    185         if ( is_plugin_active( $plugin ) ) {
     215        if ( is_plugin_active( $plugin ) || is_plugin_active_for_network( $plugin ) ) {
    186216                if ( is_writeable( $real_file ) ) {
    187217                        /* translators: %s: plugin file name */
    188218                        echo sprintf( __( 'Editing %s (active)' ), '<strong>' . $file . '</strong>' );
     
    257287                <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>
    258288                <?php endif; ?>
    259289<?php if ( is_writeable($real_file) ) : ?>
    260         <?php if ( in_array( $file, (array) get_option( 'active_plugins', array() ) ) ) { ?>
     290        <?php if ( is_plugin_active( $plugin ) || is_plugin_active_for_network( $plugin ) ) : ?>
    261291                <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 } ?>
     292        <?php endif; ?>
    263293        <p class="submit">
    264294        <?php
    265295                if ( isset($_GET['phperror']) ) {