WordPress.org

Make WordPress Core

Changeset 7525


Ignore:
Timestamp:
03/26/08 16:14:29 (7 years ago)
Author:
ryan
Message:

Fix plugin error scraping in the plugin editor. Props DD32. fixes #6332

File:
1 edited

Legend:

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

    r7456 r7525  
    1515$plugin_files = array_keys($plugins); 
    1616 
    17 if (empty($file)) { 
     17if (empty($file)) 
    1818    $file = $plugin_files[0]; 
    19 } 
    2019 
    2120$file = validate_file_to_edit($file, $plugin_files); 
     
    3231 
    3332    $newcontent = stripslashes($_POST['newcontent']); 
    34     if (is_writeable($real_file)) { 
     33    if ( is_writeable($real_file) ) { 
    3534        $f = fopen($real_file, 'w+'); 
    3635        fwrite($f, $newcontent); 
     
    3837 
    3938        // Deactivate so we can test it. 
    40         $current = get_option('active_plugins'); 
    41         if ( in_array($file, $current) || isset($_POST['phperror']) ) { 
    42             if ( in_array($file, $current) ) { 
    43                 if ( ( $key = array_search( $plugin, $current) ) !== false ) 
    44                     array_splice($current, $key, 1 ); // Fixed Array-fu! 
    45                 update_option('active_plugins', $current); 
    46             } 
     39        if ( is_plugin_active($file) || isset($_POST['phperror']) ) { 
     40            if ( is_plugin_active($file) ) 
     41                deactivate_plugins($file, true); 
    4742            wp_redirect(add_query_arg('_wpnonce', wp_create_nonce('edit-plugin-test_' . $file), "plugin-editor.php?file=$file&liveupdate=1")); 
    48             exit(); 
     43            exit; 
    4944        } 
    5045        wp_redirect("plugin-editor.php?file=$file&a=te"); 
     
    5247        wp_redirect("plugin-editor.php?file=$file"); 
    5348    } 
    54  
    55     exit(); 
     49    exit; 
    5650 
    5751break; 
     
    6256        wp_die('<p>'.__('You do not have sufficient permissions to edit plugins for this blog.').'</p>'); 
    6357 
    64     if ( $_GET['liveupdate'] ) { 
     58    if ( isset($_GET['liveupdate']) ) { 
    6559        check_admin_referer('edit-plugin-test_' . $file); 
    66         $current = get_option('active_plugins'); 
    67         $plugin = $file; 
    68         if ( validate_file($plugin) ) 
    69             wp_die(__('Invalid plugin.')); 
    70         if ( ! file_exists(ABSPATH . PLUGINDIR . '/' . $plugin) ) 
    71             wp_die(__('Plugin file does not exist.')); 
    72         if (!in_array($plugin, $current)) { 
    73             wp_redirect("plugin-editor.php?file=$file&phperror=1"); // we'll override this later if the plugin can be included without fatal error 
    74             @include(ABSPATH . PLUGINDIR . '/' . $plugin); 
    75             $current[] = $plugin; 
    76             sort($current); 
    77             update_option('active_plugins', $current); 
    78         } 
     60 
     61        $error = validate_plugin($file); 
     62        if( is_wp_error($error) ) 
     63            wp_die( $error ); 
     64 
     65        if ( ! is_plugin_active($file) ) 
     66            activate_plugin($file, "plugin-editor.php?file=$file&phperror=1");// we'll override this later if the plugin can be included without fatal error 
     67 
    7968        wp_redirect("plugin-editor.php?file=$file&a=te"); 
     69        exit; 
    8070    } 
    8171 
     
    8474    update_recently_edited(PLUGINDIR . "/$file"); 
    8575 
    86     if (!is_file($real_file)) 
     76    if ( ! is_file($real_file) ) 
    8777        $error = 1; 
    8878 
    89     if (!$error) { 
    90         $f = fopen($real_file, 'r'); 
    91         $content = fread($f, filesize($real_file)); 
    92         $content = htmlspecialchars($content); 
    93     } 
     79    if ( ! $error ) 
     80        $content = htmlspecialchars(file_get_contents($real_file)); 
    9481 
    9582    ?> 
     
    9784 <div id="message" class="updated fade"><p><?php _e('File edited successfully.') ?></p></div> 
    9885<?php elseif (isset($_GET['phperror'])) : ?> 
    99  <div id="message" class="updated fade"><p><?php _e('This plugin has been deactivated because your changes resulted in a <strong>fatal error</strong>.') ?></p></div> 
     86 <div id="message" class="updated fade"><p><?php _e('This plugin has been deactivated because your changes resulted in a <strong>fatal error</strong>.') ?></p> 
     87    <?php 
     88        if ( wp_verify_nonce($_GET['_error_nonce'], 'plugin-activation-error_' . $file) ) { ?> 
     89    <iframe style="border:0" width="100%" height="70px" src="<?php bloginfo('wpurl'); ?>/wp-admin/plugins.php?action=error_scrape&amp;plugin=<?php echo attribute_escape($file); ?>&amp;_wpnonce=<?php echo attribute_escape($_GET['_error_nonce']); ?>"></iframe> 
     90    <?php } ?> 
     91</div> 
    10092<?php endif; ?> 
    10193 <div class="wrap"> 
     
    10698<div class="alignleft"> 
    10799<big><strong><?php 
    108     if ( in_array($file, (array) get_option('active_plugins')) ) { 
    109         if (is_writeable($real_file)) { 
     100    if ( is_plugin_active($file) ) { 
     101        if ( is_writeable($real_file) ) 
    110102            echo sprintf(__('Editing <strong>%s</strong> (active)'), $file); 
    111         } else { 
    112         echo sprintf(__('Browsing <strong>%s</strong> (active)'), $file); 
    113         } 
     103        else 
     104            echo sprintf(__('Browsing <strong>%s</strong> (active)'), $file); 
    114105    } else { 
    115         if (is_writeable($real_file)) { 
     106        if ( is_writeable($real_file) ) 
    116107            echo sprintf(__('Editing <strong>%s</strong> (inactive)'), $file); 
    117         } else { 
    118         echo sprintf(__('Browsing <strong>%s</strong> (inactive)'), $file); 
    119         } 
     108        else 
     109            echo sprintf(__('Browsing <strong>%s</strong> (inactive)'), $file); 
    120110    } 
    121111    ?></strong></big> 
     
    125115<br class="clear" /> 
    126116    <div id="templateside"> 
    127     <h3 id="bordertitle"><?php _e("Plugin Files"); ?></h3> 
     117    <h3 id="bordertitle"><?php _e('Plugin Files'); ?></h3> 
    128118 
    129119    <h4><?php _e('Plugins'); ?></h4> 
    130120    <ul> 
    131121<?php foreach($plugin_files as $plugin_file) : ?> 
    132         <li><a href="plugin-editor.php?file=<?php echo "$plugin_file"; ?>"><?php echo $plugins[$plugin_file]['Name']; ?></a></li> 
     122        <li><a href="plugin-editor.php?file=<?php echo $plugin_file; ?>"><?php echo $plugins[$plugin_file]['Name']; ?></a></li> 
    133123<?php endforeach; ?> 
    134124    </ul> 
    135125    </div> 
    136 <?php   if (!$error) { ?> 
     126<?php   if ( ! $error ) { ?> 
    137127    <form name="template" id="template" action="plugin-editor.php" method="post"> 
    138128    <?php wp_nonce_field('edit-plugin_' . $file) ?> 
     
    165155</div> 
    166156<?php 
    167 break; 
     157    break; 
    168158} 
    169159include("admin-footer.php") ?> 
Note: See TracChangeset for help on using the changeset viewer.