Ticket #17552: 17552-2.patch
File 17552-2.patch, 7.2 KB (added by , 11 years ago) |
---|
-
wp-admin/plugin-editor.php
27 27 if ( empty($plugins) ) 28 28 wp_die( __('There are no plugins installed on this site.') ); 29 29 30 if ( $file ) { 31 $plugin = $file; 32 } elseif ( empty( $plugin ) ) { 33 $plugin = array_keys($plugins); 34 $plugin = $plugin[0]; 30 if ( empty( $plugin ) ) { 31 if ( $file ) { 32 $plugin = $file; 33 } else { 34 $plugin = array_keys( $plugins ); 35 $plugin = $plugin[0]; 36 } 35 37 } 36 38 37 39 $plugin_files = get_plugin_files($plugin); … … 49 51 50 52 check_admin_referer('edit-plugin_' . $file); 51 53 52 $newcontent = wp_unslash( $_POST['newcontent'] ); 53 if ( is_writeable($real_file) ) { 54 $f = fopen($real_file, 'w+'); 55 fwrite($f, $newcontent); 56 fclose($f); 54 if ( is_writeable( $real_file ) ) { 55 $newcontent = wp_unslash( $_POST['newcontent'] ); 57 56 58 $network_wide = is_plugin_active_for_network( $file );57 file_put_contents($real_file, $newcontent); 59 58 59 $network_wide = is_plugin_active_for_network( $plugin ); 60 // @TODO: Network Wide activated plugins do not go through this lint check 60 61 // Deactivate so we can test it. 61 if ( is_plugin_active($ file) || isset($_POST['phperror']) ) {62 if ( is_plugin_active($ file) )63 deactivate_plugins($ file, true);62 if ( is_plugin_active($plugin) || isset($_POST['phperror']) ) { 63 if ( is_plugin_active($plugin) ) 64 deactivate_plugins($plugin, true); 64 65 65 66 if ( ! is_network_admin() ) 66 update_option( 'recently_activated', array( $ file=> time() ) + (array) get_option( 'recently_activated' ) );67 update_option( 'recently_activated', array( $plugin => time() ) + (array) get_option( 'recently_activated' ) ); 67 68 68 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));69 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)); 69 70 exit; 70 71 } 71 wp_redirect( self_admin_url("plugin-editor.php?file=$file& a=te&scrollto=$scrollto") );72 wp_redirect( self_admin_url("plugin-editor.php?file=$file&plugin=$plugin&updated=1&scrollto=$scrollto") ); 72 73 } else { 73 wp_redirect( self_admin_url("plugin-editor.php?file=$file& scrollto=$scrollto") );74 wp_redirect( self_admin_url("plugin-editor.php?file=$file&plugin=$plugin&scrollto=$scrollto") ); 74 75 } 75 76 exit; 76 77 … … 81 82 if ( isset($_GET['liveupdate']) ) { 82 83 check_admin_referer('edit-plugin-test_' . $file); 83 84 84 $error = validate_plugin($ file);85 $error = validate_plugin($plugin); 85 86 if ( is_wp_error($error) ) 86 87 wp_die( $error ); 87 88 88 if ( ( ! empty( $_GET['networkwide'] ) && ! is_plugin_active_for_network($ file) ) || ! is_plugin_active($file) )89 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 error89 if ( ( ! empty( $_GET['networkwide'] ) && ! is_plugin_active_for_network($plugin) ) || ! is_plugin_active($plugin) ) 90 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 90 91 91 wp_redirect( self_admin_url("plugin-editor.php?file=$file& a=te&scrollto=$scrollto") );92 wp_redirect( self_admin_url("plugin-editor.php?file=$file&plugin=$plugin&updated=1&scrollto=$scrollto") ); 92 93 exit; 93 94 } 94 95 … … 97 98 $editable_extensions = (array) apply_filters('editable_extensions', $editable_extensions); 98 99 99 100 if ( ! is_file($real_file) ) { 100 wp_die( sprintf('<p>%s</p>', __('No such file exists! Double check the name and try again.')));101 wp_die( __('No such file exists! Double check the name and try again.') ); 101 102 } else { 102 103 // Get the extension of the file 103 104 if ( preg_match('/\.([^.]+)$/', $real_file, $matches) ) { 104 105 $ext = strtolower($matches[1]); 105 106 // If extension is not in the acceptable list, skip it 106 107 if ( !in_array( $ext, $editable_extensions) ) 107 wp_die( sprintf('<p>%s</p>', __('Files of this type are not editable.')));108 wp_die( __('Files of this type are not editable.') ); 108 109 } 109 110 } 110 111 … … 129 130 130 131 require_once(ABSPATH . 'wp-admin/admin-header.php'); 131 132 132 update_recently_edited( WP_PLUGIN_DIR . '/' . $file);133 update_recently_edited( WP_PLUGIN_DIR . '/' . $plugin ); 133 134 134 135 $content = file_get_contents( $real_file ); 135 136 … … 148 149 149 150 $content = esc_textarea( $content ); 150 151 ?> 151 <?php if (isset($_GET[' a'])) : ?>152 <?php if (isset($_GET['updated'])) : ?> 152 153 <div id="message" class="updated"><p><?php _e('File edited successfully.') ?></p></div> 153 154 <?php elseif (isset($_GET['phperror'])) : ?> 154 155 <div id="message" class="updated"><p><?php _e('This plugin has been deactivated because your changes resulted in a <strong>fatal error</strong>.') ?></p> 155 156 <?php 156 if ( wp_verify_nonce($_GET['_error_nonce'], 'plugin-activation-error_' . $file) ) { ?> 157 <iframe style="border:0" width="100%" height="70px" src="<?php bloginfo('wpurl'); ?>/wp-admin/plugins.php?action=error_scrape&plugin=<?php echo esc_attr($file); ?>&_wpnonce=<?php echo esc_attr($_GET['_error_nonce']); ?>"></iframe> 157 if ( wp_verify_nonce($_GET['_error_nonce'], 'plugin-activation-error_' . $plugin ) ) { 158 //@TODO: Is this Network Admin safe? (admin_url()) ?> 159 <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> 158 160 <?php } ?> 159 161 </div> 160 162 <?php endif; ?> … … 165 167 <div class="fileedit-sub"> 166 168 <div class="alignleft"> 167 169 <big><?php 168 if ( is_plugin_active( $plugin) ) {170 if ( is_plugin_active( $plugin ) || is_plugin_active_for_network( $plugin ) ) { 169 171 if ( is_writeable($real_file) ) 170 172 echo sprintf(__('Editing <strong>%s</strong> (active)'), $file); 171 173 else … … 193 195 $plugin_key = esc_attr($plugin_key); 194 196 echo "\n\t<option value=\"$plugin_key\" $selected>$plugin_name</option>"; 195 197 } 198 196 199 ?> 197 200 </select> 198 201 <?php submit_button( __( 'Select' ), 'button', 'Submit', false ); ?> … … 234 237 <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( 'http://api.wordpress.org/core/handbook/1.0/?function=' + escape( jQuery( '#docs-list' ).val() ) + '&locale=<?php echo urlencode( get_locale() ) ?>&version=<?php echo urlencode( $wp_version ) ?>&redirect=true'); }" /></div> 235 238 <?php endif; ?> 236 239 <?php if ( is_writeable($real_file) ) : ?> 237 <?php if ( i n_array( $file, (array) get_option( 'active_plugins', array() )) ) { ?>240 <?php if ( is_plugin_active( $plugin ) || is_plugin_active_for_network( $plugin ) ) { ?> 238 241 <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> 239 242 <?php } ?> 240 243 <p class="submit">