Ticket #17552: 17552.3.patch
File 17552.3.patch, 8.0 KB (added by , 9 years ago) |
---|
-
src/wp-admin/plugin-editor.php
36 36 exit; 37 37 } 38 38 39 if ( $file ) { 40 $plugin = $file; 41 } elseif ( empty( $plugin ) ) { 42 $plugin = array_keys($plugins); 43 $plugin = $plugin[0]; 39 if ( empty( $plugin ) ) { 40 if ( $file ) { 41 $plugin = $file; 42 } elseif ( empty( $plugin ) ) { 43 $plugin = array_keys($plugins); 44 $plugin = $plugin[0]; 45 } 44 46 } 45 47 46 48 $plugin_files = get_plugin_files($plugin); … … 58 60 59 61 check_admin_referer('edit-plugin_' . $file); 60 62 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 ); 66 69 67 $network_wide = is_plugin_active_for_network( $file ); 70 if ( is_writeable( $real_file ) ) { 71 $newcontent = wp_unslash( $_POST['newcontent'] ); 68 72 73 file_put_contents( $real_file, $newcontent ); 74 75 $network_wide = is_plugin_active_for_network( $plugin ); 76 // @TODO: Network Wide activated plugins do not go through this lint check 77 69 78 // 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);79 if ( is_plugin_active( $plugin ) || isset($_POST['phperror'] ) ) { 80 if ( is_plugin_active( $plugin ) ) 81 deactivate_plugins( $plugin, true ); 73 82 74 83 if ( ! is_network_admin() ) { 75 update_option( 'recently_activated', array( $ file=> time() ) + (array) get_option( 'recently_activated' ) );84 update_option( 'recently_activated', array( $plugin => time() ) + (array) get_option( 'recently_activated' ) ); 76 85 } else { 77 update_network_option( 'recently_activated', array( $ file=> time() ) + (array) get_network_option( 'recently_activated' ) );86 update_network_option( 'recently_activated', array( $plugin => time() ) + (array) get_network_option( 'recently_activated' ) ); 78 87 } 79 88 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 $redirect_args = array_merge( $redirect_args, array( 90 'liveupdate' => 1, 91 'networkwide' => $network_wide, 92 '_wpnonce' => wp_create_nonce( "edit-plugin-test_{$file}" ), 93 ) ); 94 95 wp_redirect( add_query_arg( $redirect_args, self_admin_url( 'plugin-editor.php' ) ) ); 81 96 exit; 82 97 } 83 wp_redirect( self_admin_url("plugin-editor.php?file=$file&a=te&scrollto=$scrollto") ); 98 99 $redirect_args = array_merge( $redirect_args, array( 'updated' => 1 ) ); 100 wp_redirect( add_query_arg( $redirect_args, self_admin_url( 'plugin-editor.php' ) ) ); 84 101 } else { 85 wp_redirect( self_admin_url("plugin-editor.php?file=$file&scrollto=$scrollto") );102 wp_redirect( add_query_arg( $redirect_args, self_admin_url( 'plugin-editor.php' ) ) ); 86 103 } 87 104 exit; 88 105 89 106 default: 90 107 108 // Shared redirect arguments. 109 $redirect_args = array( 110 'file' => $file, 111 'plugin' => $plugin, 112 ); 113 91 114 if ( isset($_GET['liveupdate']) ) { 92 115 check_admin_referer('edit-plugin-test_' . $file); 93 116 94 $error = validate_plugin( $file);117 $error = validate_plugin( $plugin ); 95 118 if ( is_wp_error($error) ) 96 119 wp_die( $error ); 97 120 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 121 if ( ( ! empty( $_GET['networkwide'] ) && ! is_plugin_active_for_network( $plugin ) ) | is_plugin_active( $plugin ) ) { 100 122 101 wp_redirect( self_admin_url("plugin-editor.php?file=$file&a=te&scrollto=$scrollto") ); 123 // we'll override this later if the plugin can be included without fatal error 124 $redirect_args = array_merge( $redirect_args, array( 'phperror' => 1 ) ); 125 activate_plugin( $plugin, add_query_arg( $redirect_args, self_admin_url( 'plugin-editor.php' ) ), ! empty( $_GET['networkwide'] ) ); 126 } 127 128 $redirect_args = array_merge( $redirect_args, array( 129 'scrollto' => $scrollto, 130 'updated' => 1 131 ); 132 wp_redirect( add_query_arg( $redirect_args, self_admin_url( 'plugin-editor.php' ) ) ); 102 133 exit; 103 134 } 104 135 … … 115 146 $editable_extensions = (array) apply_filters( 'editable_extensions', $editable_extensions ); 116 147 117 148 if ( ! is_file($real_file) ) { 118 wp_die( sprintf('<p>%s</p>', __('No such file exists! Double check the name and try again.')));149 wp_die( __( 'No such file exists! Double check the name and try again.' ) ); 119 150 } else { 120 151 // Get the extension of the file 121 152 if ( preg_match('/\.([^.]+)$/', $real_file, $matches) ) { … … 122 153 $ext = strtolower($matches[1]); 123 154 // If extension is not in the acceptable list, skip it 124 155 if ( !in_array( $ext, $editable_extensions) ) 125 wp_die( sprintf('<p>%s</p>', __('Files of this type are not editable.')));156 wp_die( __( 'Files of this type are not editable.' ) ); 126 157 } 127 158 } 128 159 … … 147 178 148 179 require_once(ABSPATH . 'wp-admin/admin-header.php'); 149 180 150 update_recently_edited( WP_PLUGIN_DIR . '/' . $file);181 update_recently_edited( WP_PLUGIN_DIR . '/' . $plugin ); 151 182 152 183 $content = file_get_contents( $real_file ); 153 184 … … 166 197 167 198 $content = esc_textarea( $content ); 168 199 ?> 169 <?php if ( isset($_GET['a'])) : ?>200 <?php if ( isset( $_GET['updated'] ) ) : ?> 170 201 <div id="message" class="updated notice is-dismissible"><p><?php _e('File edited successfully.') ?></p></div> 171 202 <?php elseif (isset($_GET['phperror'])) : ?> 172 203 <div id="message" class="updated"><p><?php _e('This plugin has been deactivated because your changes resulted in a <strong>fatal error</strong>.') ?></p> 173 204 <?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&plugin=<?php echo esc_attr($file); ?>&_wpnonce=<?php echo esc_attr($_GET['_error_nonce']); ?>"></iframe> 176 <?php } ?> 205 if ( wp_verify_nonce($_GET['_error_nonce'], 'plugin-activation-error_' . $plugin ) ) : 206 //@TODO: Is this Network Admin safe? (admin_url()) ?> 207 <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> 208 <?php endif; ?> 177 209 </div> 178 210 <?php endif; ?> 179 211 <div class="wrap"> … … 182 214 <div class="fileedit-sub"> 183 215 <div class="alignleft"> 184 216 <big><?php 185 if ( is_plugin_active( $plugin ) ) {217 if ( is_plugin_active( $plugin ) || is_plugin_active_for_network( $plugin ) ) { 186 218 if ( is_writeable( $real_file ) ) { 187 219 /* translators: %s: plugin file name */ 188 220 echo sprintf( __( 'Editing %s (active)' ), '<strong>' . $file . '</strong>' ); … … 257 289 <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() ) + '&locale=<?php echo urlencode( get_locale() ) ?>&version=<?php echo urlencode( $wp_version ) ?>&redirect=true'); }" /></div> 258 290 <?php endif; ?> 259 291 <?php if ( is_writeable($real_file) ) : ?> 260 <?php if ( in_array( $file, (array) get_option( 'active_plugins', array() ) ) ) {?>292 <?php if ( s_plugin_active( $plugin ) || is_plugin_active_for_network( $plugin ) ) : ?> 261 293 <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 }?>294 <?php endif; ?> 263 295 <p class="submit"> 264 296 <?php 265 297 if ( isset($_GET['phperror']) ) {