WordPress.org

Make WordPress Core

Changeset 38745


Ignore:
Timestamp:
10/07/2016 04:57:49 PM (20 months ago)
Author:
swissspidy
Message:

Plugins: Correctly display the current plugin in the plugin editor.

When editing a plugin file, show the correct plugin as being edited in the dropdown with the correct activation status.

Props aniketpant, dd32, DrewAPicture, jayarjo, MattyRob, mt8.biz, solarissmoke, swissspidy, WraithKenny.
Fixes #24122, #17552.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/plugin-editor.php

    r38722 r38745  
    2020$title = __("Edit Plugins");
    2121$parent_file = 'plugins.php';
    22 
    23 wp_reset_vars( array( 'action', 'error', 'file', 'plugin' ) );
    2422
    2523$plugins = get_plugins();
     
    3735}
    3836
    39 if ( $file ) {
    40     $plugin = $file;
    41 } elseif ( empty( $plugin ) ) {
    42     $plugin = array_keys($plugins);
    43     $plugin = $plugin[0];
     37$file = '';
     38$plugin = '';
     39if ( isset( $_REQUEST['file'] ) ) {
     40    $file = sanitize_text_field( $_REQUEST['file'] );
     41}
     42
     43if ( isset( $_REQUEST['plugin'] ) ) {
     44    $plugin = sanitize_text_field( $_REQUEST['plugin'] );
     45}
     46
     47if ( empty( $plugin ) ) {
     48    if ( $file ) {
     49        $plugin = $file;
     50    } else {
     51        $plugin = array_keys( $plugins );
     52        $plugin = $plugin[0];
     53    }
    4454}
    4555
     
    5363$scrollto = isset($_REQUEST['scrollto']) ? (int) $_REQUEST['scrollto'] : 0;
    5464
    55 switch ( $action ) {
    56 
    57 case 'update':
     65if ( isset( $_REQUEST['action'] ) && 'update' === $_REQUEST['action'] ) {
    5866
    5967    check_admin_referer('edit-plugin_' . $file);
     
    6876
    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 );
     81            }
    7382
    7483            if ( ! is_network_admin() ) {
     
    7887            }
    7988
    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));
     89            wp_redirect( add_query_arg( '_wpnonce', wp_create_nonce( 'edit-plugin-test_' . $file ), "plugin-editor.php?file=$file&plugin=$plugin&liveupdate=1&scrollto=$scrollto&networkwide=" . $network_wide ) );
    8190            exit;
    8291        }
    83         wp_redirect( self_admin_url("plugin-editor.php?file=$file&a=te&scrollto=$scrollto") );
    84     } else {
    85         wp_redirect( self_admin_url("plugin-editor.php?file=$file&scrollto=$scrollto") );
     92        wp_redirect( self_admin_url( "plugin-editor.php?file=$file&plugin=$plugin&a=te&scrollto=$scrollto" ) );
     93    } else {
     94        wp_redirect( self_admin_url( "plugin-editor.php?file=$file&plugin=$plugin&scrollto=$scrollto" ) );
    8695    }
    8796    exit;
    8897
    89 default:
     98} else {
    9099
    91100    if ( isset($_GET['liveupdate']) ) {
    92101        check_admin_referer('edit-plugin-test_' . $file);
    93102
    94         $error = validate_plugin($file);
    95         if ( is_wp_error($error) )
     103        $error = validate_plugin( $plugin );
     104
     105        if ( is_wp_error( $error ) ) {
    96106            wp_die( $error );
    97 
    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 
    101         wp_redirect( self_admin_url("plugin-editor.php?file=$file&a=te&scrollto=$scrollto") );
     107        }
     108
     109        if ( ( ! empty( $_GET['networkwide'] ) && ! is_plugin_active_for_network( $file ) ) || ! is_plugin_active( $file ) ) {
     110            activate_plugin( $plugin, "plugin-editor.php?file=$file&phperror=1", ! empty( $_GET['networkwide'] ) );
     111        } // we'll override this later if the plugin can be included without fatal error
     112
     113        wp_redirect( self_admin_url("plugin-editor.php?file=$file&plugin=$plugin&a=te&scrollto=$scrollto") );
    102114        exit;
    103115    }
     
    264276        <?php endif; ?>
    265277<?php if ( is_writeable($real_file) ) : ?>
    266     <?php if ( in_array( $file, (array) get_option( 'active_plugins', array() ) ) ) { ?>
     278    <?php if ( in_array( $plugin, (array) get_option( 'active_plugins', array() ) ) ) { ?>
    267279        <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>
    268280    <?php } ?>
     
    290302</script>
    291303<?php
    292     break;
    293 }
     304}
     305
    294306include(ABSPATH . "wp-admin/admin-footer.php");
Note: See TracChangeset for help on using the changeset viewer.