Make WordPress Core

Changeset 10627


Ignore:
Timestamp:
02/22/2009 08:05:11 PM (18 years ago)
Author:
ryan
Message:

Allow editing all of a plugin's files. see #6732

Location:
trunk/wp-admin
Files:
2 edited

Legend:

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

    r10594 r10627  
    9999        if ( $markup || $translate )
    100100                $plugin_data = _get_plugin_data_markup_translate($plugin_data, $markup, $translate);
     101
    101102        return $plugin_data;
    102103}
     
    139140
    140141        return $plugin_data;
     142}
     143
     144/**
     145 * Get a list of a plugin's files.
     146 *
     147 * @since 2.8.0
     148 *
     149 * @param string $plugin Plugin ID
     150 * @return array List of files relative to the plugin root.
     151 */
     152function get_plugin_files($plugin) {
     153        $plugin_file = WP_PLUGIN_DIR . '/' . $plugin;
     154        $dir = dirname($plugin_file);
     155        $plugin_files = array($plugin);
     156        if ( is_dir($dir) && $dir != WP_PLUGIN_DIR ) {
     157                $plugins_dir = @ opendir( $dir );
     158                if ( $plugins_dir ) {
     159                        while (($file = readdir( $plugins_dir ) ) !== false ) {
     160                                if ( substr($file, 0, 1) == '.' )
     161                                        continue;
     162                                if ( is_dir( $dir . '/' . $file ) ) {
     163                                        $plugins_subdir = @ opendir( $dir . '/' . $file );
     164                                        if ( $plugins_subdir ) {
     165                                                while (($subfile = readdir( $plugins_subdir ) ) !== false ) {
     166                                                        if ( substr($subfile, 0, 1) == '.' )
     167                                                                continue;
     168                                                        $plugin_files[] = plugin_basename("$dir/$file/$subfile");
     169                                                }
     170                                                @closedir( $plugins_subdir );
     171                                        }
     172                                } else {
     173                                        if ( plugin_basename("$dir/$file") != $plugin )
     174                                                $plugin_files[] = plugin_basename("$dir/$file");
     175                                }
     176                        }
     177                        @closedir( $plugins_dir );
     178                }
     179        }
     180
     181        return $plugin_files;
    141182}
    142183
  • trunk/wp-admin/plugin-editor.php

    r10614 r10627  
    1313$parent_file = 'plugins.php';
    1414
    15 wp_reset_vars(array('action', 'redirect', 'profile', 'error', 'warning', 'a', 'file'));
     15wp_reset_vars(array('action', 'redirect', 'profile', 'error', 'warning', 'a', 'file', 'plugin'));
    1616
    1717wp_admin_css( 'theme-editor' );
    1818
    1919$plugins = get_plugins();
    20 $plugin_files = array_keys($plugins);
     20
     21if ( empty($plugin) ) {
     22        $plugin = array_keys($plugins);
     23        $plugin = $plugin[0];
     24}
     25
     26$plugin_files = get_plugin_files($plugin);
    2127
    2228if (empty($file))
     
    116122<?php screen_icon(); ?>
    117123<h2><?php echo wp_specialchars( $title ); ?></h2>
    118 
     124<div class="bordertitle">
     125        <form id="themeselector" action="plugin-editor.php" method="post">
     126                <strong><label for="theme"><?php _e('Select plugin to edit:'); ?> </label></strong>
     127                <select name="plugin" id="plugin">
     128<?php
     129        foreach ($plugins as $plugin_key => $a_plugin) {
     130        $plugin_name = $a_plugin['Name'];
     131        if ($plugin_key == $plugin) $selected = " selected='selected'";
     132        else $selected = '';
     133        $plugin_name = attribute_escape($plugin_name);
     134        echo "\n\t<option value=\"$plugin_key\" $selected>$plugin_name</option>";
     135}
     136?>
     137                </select>
     138                <input type="submit" name="Submit" value="<?php _e('Select') ?>" class="button" />
     139        </form>
     140</div>
    119141<div class="tablenav">
    120142<div class="alignleft">
    121143<big><?php
    122         if ( is_plugin_active($file) ) {
     144        if ( is_plugin_active($plugin) ) {
    123145                if ( is_writeable($real_file) )
    124146                        echo sprintf(__('Editing <strong>%s</strong> (active)'), $file);
     
    139161        <h3 id="bordertitle"><?php _e('Plugin Files'); ?></h3>
    140162
    141         <h4><?php _e('Plugins'); ?></h4>
    142163        <ul>
    143164<?php foreach($plugin_files as $plugin_file) : ?>
    144                 <li<?php echo $file == $plugin_file ? ' class="highlight"' : ''; ?>><a href="plugin-editor.php?file=<?php echo $plugin_file; ?>"><?php echo $plugins[$plugin_file]['Name']; ?></a></li>
     165                <li<?php echo $file == $plugin_file ? ' class="highlight"' : ''; ?>><a href="plugin-editor.php?file=<?php echo $plugin_file; ?>&plugin=<?php echo $plugin; ?>"><?php echo $plugin_file ?></a></li>
    145166<?php endforeach; ?>
    146167        </ul>
     
    152173                <input type="hidden" name="action" value="update" />
    153174                <input type="hidden" name="file" value="<?php echo $file ?>" />
     175                <input type="hidden" name="plugin" value="<?php echo $plugin ?>" />
    154176                </div>
    155177                <?php if ( count( $functions ) ) : ?>
Note: See TracChangeset for help on using the changeset viewer.