X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/7688c6ba71852cd89123b62b2d57683535e4702a..80b7979fccf09a75af3f4c111fa27060ae6dbf85:/wp-admin/plugin-editor.php diff --git a/wp-admin/plugin-editor.php b/wp-admin/plugin-editor.php index b25b3d45..b7758d22 100644 --- a/wp-admin/plugin-editor.php +++ b/wp-admin/plugin-editor.php @@ -1,158 +1,269 @@ '.__('You do not have sufficient permissions to edit templates for this blog.').'

'); - $newcontent = stripslashes($_POST['newcontent']); - if (is_writeable($real_file)) { + if ( is_writeable($real_file) ) { $f = fopen($real_file, 'w+'); fwrite($f, $newcontent); fclose($f); + $network_wide = is_plugin_active_for_network( $file ); + // Deactivate so we can test it. - $current = get_option('active_plugins'); - if ( in_array($file, $current) || isset($_POST['phperror']) ) { - if ( in_array($file, $current) ) { - array_splice($current, array_search( $file, $current), 1 ); // Array-fu! - update_option('active_plugins', $current); - } - wp_redirect(add_query_arg('_wpnonce', wp_create_nonce('edit-plugin-test_' . $file), "plugin-editor.php?file=$file&liveupdate=1")); - exit(); + if ( is_plugin_active($file) || isset($_POST['phperror']) ) { + if ( is_plugin_active($file) ) + deactivate_plugins($file, true); + + if ( ! is_network_admin() ) + update_option( 'recently_activated', array( $file => time() ) + (array) get_option( 'recently_activated' ) ); + + 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)); + exit; } - wp_redirect("plugin-editor.php?file=$file&a=te"); + wp_redirect( self_admin_url("plugin-editor.php?file=$file&a=te&scrollto=$scrollto") ); } else { - wp_redirect("plugin-editor.php?file=$file"); + wp_redirect( self_admin_url("plugin-editor.php?file=$file&scrollto=$scrollto") ); } - - exit(); + exit; break; default: - if ( !current_user_can('edit_plugins') ) - wp_die('

'.__('You do not have sufficient permissions to edit plugins for this blog.').'

'); - - if ( $_GET['liveupdate'] ) { + if ( isset($_GET['liveupdate']) ) { check_admin_referer('edit-plugin-test_' . $file); - $current = get_option('active_plugins'); - $plugin = $file; - if ( validate_file($plugin) ) - wp_die(__('Invalid plugin.')); - if ( ! file_exists(ABSPATH . PLUGINDIR . '/' . $plugin) ) - wp_die(__('Plugin file does not exist.')); - if (!in_array($plugin, $current)) { - wp_redirect("plugin-editor.php?file=$file&phperror=1"); // we'll override this later if the plugin can be included without fatal error - @include(ABSPATH . PLUGINDIR . '/' . $plugin); - $current[] = $plugin; - sort($current); - update_option('active_plugins', $current); + + $error = validate_plugin($file); + if ( is_wp_error($error) ) + wp_die( $error ); + + if ( ( ! empty( $_GET['networkwide'] ) && ! is_plugin_active_for_network($file) ) || ! is_plugin_active($file) ) + 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 + + wp_redirect( self_admin_url("plugin-editor.php?file=$file&a=te&scrollto=$scrollto") ); + exit; + } + + // List of allowable extensions + $editable_extensions = array('php', 'txt', 'text', 'js', 'css', 'html', 'htm', 'xml', 'inc', 'include'); + $editable_extensions = (array) apply_filters('editable_extensions', $editable_extensions); + + if ( ! is_file($real_file) ) { + wp_die(sprintf('

%s

', __('No such file exists! Double check the name and try again.'))); + } else { + // Get the extension of the file + if ( preg_match('/\.([^.]+)$/', $real_file, $matches) ) { + $ext = strtolower($matches[1]); + // If extension is not in the acceptable list, skip it + if ( !in_array( $ext, $editable_extensions) ) + wp_die(sprintf('

%s

', __('Files of this type are not editable.'))); } - wp_redirect("plugin-editor.php?file=$file&a=te"); } - require_once('admin-header.php'); + get_current_screen()->add_help_tab( array( + 'id' => 'overview', + 'title' => __('Overview'), + 'content' => + '

' . __('You can use the editor to make changes to any of your plugins’ individual PHP files. Be aware that if you make changes, plugins updates will overwrite your customizations.') . '

' . + '

' . __('Choose a plugin to edit from the menu in the upper right and click the Select button. Click once on any file name to load it in the editor, and make your changes. Don’t forget to save your changes (Update File) when you’re finished.') . '

' . + '

' . __('The Documentation menu below the editor lists the PHP functions recognized in the plugin file. Clicking Lookup takes you to a web page about that particular function.') . '

' . + '

' . __('If you want to make changes but don’t want them to be overwritten when the plugin is updated, you may be ready to think about writing your own plugin. For information on how to edit plugins, write your own from scratch, or just better understand their anatomy, check out the links below.') . '

' . + ( is_network_admin() ? '

' . __('Any edits to files from this screen will be reflected on all sites in the network.') . '

' : '' ) + ) ); + + get_current_screen()->set_help_sidebar( + '

' . __('For more information:') . '

' . + '

' . __('Documentation on Editing Plugins') . '

' . + '

' . __('Documentation on Writing Plugins') . '

' . + '

' . __('Support Forums') . '

' + ); + + require_once(ABSPATH . 'wp-admin/admin-header.php'); + + update_recently_edited(WP_PLUGIN_DIR . '/' . $file); - update_recently_edited(PLUGINDIR . "/$file"); + $content = file_get_contents( $real_file ); - if (!is_file($real_file)) - $error = 1; + if ( '.php' == substr( $real_file, strrpos( $real_file, '.' ) ) ) { + $functions = wp_doc_link_parse( $content ); - if (!$error) { - $f = fopen($real_file, 'r'); - $content = fread($f, filesize($real_file)); - $content = htmlspecialchars($content); + if ( !empty($functions) ) { + $docs_select = ''; + } } + $content = esc_textarea( $content ); ?> -

+

-

fatal error.') ?>

- -
+

fatal error.') ?>

' . sprintf(__('Editing %s (active)'), $file) . ''; - } else { - echo '

' . sprintf(__('Browsing %s (active)'), $file) . '

'; - } + if ( wp_verify_nonce($_GET['_error_nonce'], 'plugin-activation-error_' . $file) ) { ?> + + +
+ +
+ +

+ +
+
+%s (active)'), $file); + else + echo sprintf(__('Browsing %s (active)'), $file); } else { - if (is_writeable($real_file)) { - echo '

' . sprintf(__('Editing %s (inactive)'), $file) . '

'; - } else { - echo '

' . sprintf(__('Browsing %s (inactive)'), $file) . '

'; - } + if ( is_writeable($real_file) ) + echo sprintf(__('Editing %s (inactive)'), $file); + else + echo sprintf(__('Browsing %s (inactive)'), $file); } - ?> -
-

- + ?>
+
+
+
+ + + +
+
+
+
+ +
+

+
    - -
  • ">
  • - + + > +
-
- -
+
- + + +
+ +
+ - -

Warning: Making changes to active plugins is not recommended. If your changes cause a fatal error, the plugin will be automatically deactivated.'); ?>

+ +

Warning: Making changes to active plugins is not recommended. If your changes cause a fatal error, the plugin will be automatically deactivated.'); ?>

"; - else - echo ""; + if ( isset($_GET['phperror']) ) { + echo ""; + submit_button( __( 'Update File and Attempt to Reactivate' ), 'primary', 'submit', false, array( 'tabindex' => '2' ) ); + } else { + submit_button( __( 'Update File' ), 'primary', 'submit', false, array( 'tabindex' => '2' ) ); + } ?>

-

+

the Codex for more information.'); ?>

-
-

' . __('Oops, no such file exists! Double check the name and try again, merci.') . '

'; - } -?> -
 
+ +
+ +include(ABSPATH . "wp-admin/admin-footer.php");