Ticket #17552: 17552.5.patch
File 17552.5.patch, 8.0 KB (added by , 8 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 } else { 43 $plugin = array_keys( $plugins ); 44 $plugin = $plugin[0]; 45 } 44 46 } 45 47 46 48 $plugin_files = get_plugin_files($plugin); 47 49 48 if ( empty( $file) )50 if ( empty( $file ) ) { 49 51 $file = $plugin_files[0]; 52 } 50 53 51 $file = validate_file_to_edit( $file, $plugin_files);54 $file = validate_file_to_edit( $file, $plugin_files ); 52 55 $real_file = WP_PLUGIN_DIR . '/' . $file; 53 56 $scrollto = isset($_REQUEST['scrollto']) ? (int) $_REQUEST['scrollto'] : 0; 54 57 … … 58 61 59 62 check_admin_referer('edit-plugin_' . $file); 60 63 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); 64 // Shared redirect arguments. 65 $redirect_args = array( 66 'file' => $file, 67 'plugin' => $plugin, 68 'scrollto' => $scrollto, 69 ); 66 70 67 $network_wide = is_plugin_active_for_network( $file ); 71 $network_wide = is_plugin_active_for_network( $file ); 72 if ( is_writeable( $real_file ) ) { 73 $newcontent = wp_unslash( $_POST['newcontent'] ); 68 74 75 file_put_contents( $real_file, $newcontent ); 76 77 $network_wide = is_plugin_active_for_network( $plugin ); 78 69 79 // 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); 80 if ( is_plugin_active( $plugin ) || isset( $_POST['phperror'] ) ) { 81 if ( is_plugin_active( $plugin ) ) { 82 deactivate_plugins( $plugin , true ); 83 } 73 84 74 85 if ( ! is_network_admin() ) { 75 update_option( 'recently_activated', array( $ file=> time() ) + (array) get_option( 'recently_activated' ) );86 update_option( 'recently_activated', array( $plugin => time() ) + (array) get_option( 'recently_activated' ) ); 76 87 } else { 77 update_site_option( 'recently_activated', array( $ file=> time() ) + (array) get_site_option( 'recently_activated' ) );88 update_site_option( 'recently_activated', array( $plugin => time() ) + (array) get_site_option( 'recently_activated' ) ); 78 89 } 79 90 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)); 91 $redirect_args = array_merge( $redirect_args, array( 92 'liveupdate' => 1, 93 'networkwide' => $network_wide, 94 '_wpnonce' => wp_create_nonce( "edit-plugin-test_{$file}" ), 95 ) ); 96 wp_redirect( add_query_arg( $redirect_args, self_admin_url( 'plugin-editor.php?red=1' ) ) ); 81 97 exit; 82 98 } 83 wp_redirect( self_admin_url("plugin-editor.php?file=$file&a=te&scrollto=$scrollto") ); 99 $redirect_args = array_merge( $redirect_args, array( 'updated' => 1 ) ); 100 wp_redirect( add_query_arg( $redirect_args, self_admin_url( 'plugin-editor.php?red=1' ) ) ); 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?red=3' ) ) ); 86 103 } 87 104 exit; 88 105 89 106 default: 90 107 91 if ( isset($_GET['liveupdate']) ) { 108 // Shared redirect arguments. 109 $redirect_args = array( 110 'file' => $file, 111 'plugin' => $plugin, 112 ); 113 114 if ( isset( $_GET['liveupdate'] ) ) { 115 92 116 check_admin_referer('edit-plugin-test_' . $file); 93 117 94 $error = validate_plugin($file); 95 if ( is_wp_error($error) ) 118 $error = validate_plugin( $plugin ); 119 120 if ( is_wp_error( $error ) ) 96 121 wp_die( $error ); 97 122 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 123 if ( ( ! empty( $_GET['networkwide'] ) && ! is_plugin_active_for_network( $plugin ) ) || ! is_plugin_active( $plugin ) ) { 124 // we'll override this later if the plugin can be included without fatal error 125 $redirect_args = array_merge( $redirect_args, array( 'phperror' => 1 ) ); 126 activate_plugin( $plugin, add_query_arg( $redirect_args, self_admin_url( 'plugin-editor.php' ) ), ! empty( $_GET['networkwide'] ) ); 127 } 100 128 101 wp_redirect( self_admin_url("plugin-editor.php?file=$file&a=te&scrollto=$scrollto") ); 129 $redirect_args = array_merge( $redirect_args, array( 130 'scrollto' => $scrollto, 131 'updated' => 1 132 ) ); 133 wp_redirect( add_query_arg( $redirect_args, self_admin_url( 'plugin-editor.php?red=4' ) ) ); 102 134 exit; 103 135 } 104 136 … … 115 147 $editable_extensions = (array) apply_filters( 'editable_extensions', $editable_extensions ); 116 148 117 149 if ( ! is_file($real_file) ) { 118 wp_die( sprintf('<p>%s</p>', __('No such file exists! Double check the name and try again.')));150 wp_die( __( 'No such file exists! Double check the name and try again.' ) ); 119 151 } else { 120 152 // Get the extension of the file 121 153 if ( preg_match('/\.([^.]+)$/', $real_file, $matches) ) { … … 122 154 $ext = strtolower($matches[1]); 123 155 // If extension is not in the acceptable list, skip it 124 156 if ( !in_array( $ext, $editable_extensions) ) 125 wp_die( sprintf('<p>%s</p>', __('Files of this type are not editable.')));157 wp_die( __( 'Files of this type are not editable.' ) ); 126 158 } 127 159 } 128 160 … … 147 179 148 180 require_once(ABSPATH . 'wp-admin/admin-header.php'); 149 181 150 update_recently_edited( WP_PLUGIN_DIR . '/' . $file);182 update_recently_edited( WP_PLUGIN_DIR . '/' . $plugin ); 151 183 152 184 $content = file_get_contents( $real_file ); 153 185 … … 166 198 167 199 $content = esc_textarea( $content ); 168 200 ?> 169 <?php if ( isset($_GET['a'])) : ?>201 <?php if ( isset( $_GET['updated'] ) ) : ?> 170 202 <div id="message" class="updated notice is-dismissible"><p><?php _e('File edited successfully.') ?></p></div> 171 203 <?php elseif (isset($_GET['phperror'])) : ?> 172 204 <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 205 <?php 174 if ( wp_verify_nonce( $_GET['_error_nonce'], 'plugin-activation-error_' . $ file) ) {206 if ( wp_verify_nonce( $_GET['_error_nonce'], 'plugin-activation-error_' . $plugin ) ) { 175 207 $iframe_url = add_query_arg( array( 176 208 'action' => 'error_scrape', 177 'plugin' => urlencode( $ file),209 'plugin' => urlencode( $plugin ), 178 210 '_wpnonce' => urlencode( $_GET['_error_nonce'] ), 179 211 ), admin_url( 'plugins.php' ) ); 180 212 ?> … … 188 220 <div class="fileedit-sub"> 189 221 <div class="alignleft"> 190 222 <big><?php 191 if ( is_plugin_active( $plugin ) ) {223 if ( is_plugin_active( $plugin ) || is_plugin_active_for_network( $plugin ) ) { 192 224 if ( is_writeable( $real_file ) ) { 193 225 /* translators: %s: plugin file name */ 194 226 echo sprintf( __( 'Editing %s (active)' ), '<strong>' . $file . '</strong>' ); … … 263 295 <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> 264 296 <?php endif; ?> 265 297 <?php if ( is_writeable($real_file) ) : ?> 266 <?php if ( i n_array( $file, (array) get_option( 'active_plugins', array() )) ) { ?>298 <?php if ( is_plugin_active( $plugin ) || is_plugin_active_for_network( $plugin ) ) { ?> 267 299 <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> 268 300 <?php } ?> 269 301 <p class="submit">