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

git-svn-id: http://svn.automattic.com/wordpress/trunk@10627 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2009-02-22 20:05:11 +00:00
parent e82379cee2
commit dc1602f411
2 changed files with 69 additions and 6 deletions

View File

@ -98,6 +98,7 @@ function get_plugin_data( $plugin_file, $markup = true, $translate = true ) {
); );
if ( $markup || $translate ) if ( $markup || $translate )
$plugin_data = _get_plugin_data_markup_translate($plugin_data, $markup, $translate); $plugin_data = _get_plugin_data_markup_translate($plugin_data, $markup, $translate);
return $plugin_data; return $plugin_data;
} }
@ -140,6 +141,46 @@ function _get_plugin_data_markup_translate($plugin_data, $markup = true, $transl
return $plugin_data; return $plugin_data;
} }
/**
* Get a list of a plugin's files.
*
* @since 2.8.0
*
* @param string $plugin Plugin ID
* @return array List of files relative to the plugin root.
*/
function get_plugin_files($plugin) {
$plugin_file = WP_PLUGIN_DIR . '/' . $plugin;
$dir = dirname($plugin_file);
$plugin_files = array($plugin);
if ( is_dir($dir) && $dir != WP_PLUGIN_DIR ) {
$plugins_dir = @ opendir( $dir );
if ( $plugins_dir ) {
while (($file = readdir( $plugins_dir ) ) !== false ) {
if ( substr($file, 0, 1) == '.' )
continue;
if ( is_dir( $dir . '/' . $file ) ) {
$plugins_subdir = @ opendir( $dir . '/' . $file );
if ( $plugins_subdir ) {
while (($subfile = readdir( $plugins_subdir ) ) !== false ) {
if ( substr($subfile, 0, 1) == '.' )
continue;
$plugin_files[] = plugin_basename("$dir/$file/$subfile");
}
@closedir( $plugins_subdir );
}
} else {
if ( plugin_basename("$dir/$file") != $plugin )
$plugin_files[] = plugin_basename("$dir/$file");
}
}
@closedir( $plugins_dir );
}
}
return $plugin_files;
}
/** /**
* Check the plugins directory and retrieve all plugin files with plugin data. * Check the plugins directory and retrieve all plugin files with plugin data.
* *

View File

@ -12,12 +12,18 @@ require_once('admin.php');
$title = __("Edit Plugins"); $title = __("Edit Plugins");
$parent_file = 'plugins.php'; $parent_file = 'plugins.php';
wp_reset_vars(array('action', 'redirect', 'profile', 'error', 'warning', 'a', 'file')); wp_reset_vars(array('action', 'redirect', 'profile', 'error', 'warning', 'a', 'file', 'plugin'));
wp_admin_css( 'theme-editor' ); wp_admin_css( 'theme-editor' );
$plugins = get_plugins(); $plugins = get_plugins();
$plugin_files = array_keys($plugins);
if ( empty($plugin) ) {
$plugin = array_keys($plugins);
$plugin = $plugin[0];
}
$plugin_files = get_plugin_files($plugin);
if (empty($file)) if (empty($file))
$file = $plugin_files[0]; $file = $plugin_files[0];
@ -115,11 +121,27 @@ default:
<div class="wrap"> <div class="wrap">
<?php screen_icon(); ?> <?php screen_icon(); ?>
<h2><?php echo wp_specialchars( $title ); ?></h2> <h2><?php echo wp_specialchars( $title ); ?></h2>
<div class="bordertitle">
<form id="themeselector" action="plugin-editor.php" method="post">
<strong><label for="theme"><?php _e('Select plugin to edit:'); ?> </label></strong>
<select name="plugin" id="plugin">
<?php
foreach ($plugins as $plugin_key => $a_plugin) {
$plugin_name = $a_plugin['Name'];
if ($plugin_key == $plugin) $selected = " selected='selected'";
else $selected = '';
$plugin_name = attribute_escape($plugin_name);
echo "\n\t<option value=\"$plugin_key\" $selected>$plugin_name</option>";
}
?>
</select>
<input type="submit" name="Submit" value="<?php _e('Select') ?>" class="button" />
</form>
</div>
<div class="tablenav"> <div class="tablenav">
<div class="alignleft"> <div class="alignleft">
<big><?php <big><?php
if ( is_plugin_active($file) ) { if ( is_plugin_active($plugin) ) {
if ( is_writeable($real_file) ) if ( is_writeable($real_file) )
echo sprintf(__('Editing <strong>%s</strong> (active)'), $file); echo sprintf(__('Editing <strong>%s</strong> (active)'), $file);
else else
@ -138,10 +160,9 @@ default:
<div id="templateside"> <div id="templateside">
<h3 id="bordertitle"><?php _e('Plugin Files'); ?></h3> <h3 id="bordertitle"><?php _e('Plugin Files'); ?></h3>
<h4><?php _e('Plugins'); ?></h4>
<ul> <ul>
<?php foreach($plugin_files as $plugin_file) : ?> <?php foreach($plugin_files as $plugin_file) : ?>
<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> <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>
<?php endforeach; ?> <?php endforeach; ?>
</ul> </ul>
</div> </div>
@ -151,6 +172,7 @@ default:
<div><textarea cols="70" rows="25" name="newcontent" id="newcontent" tabindex="1" class="codepress <?php echo $codepress_lang ?>"><?php echo $content ?></textarea> <div><textarea cols="70" rows="25" name="newcontent" id="newcontent" tabindex="1" class="codepress <?php echo $codepress_lang ?>"><?php echo $content ?></textarea>
<input type="hidden" name="action" value="update" /> <input type="hidden" name="action" value="update" />
<input type="hidden" name="file" value="<?php echo $file ?>" /> <input type="hidden" name="file" value="<?php echo $file ?>" />
<input type="hidden" name="plugin" value="<?php echo $plugin ?>" />
</div> </div>
<?php if ( count( $functions ) ) : ?> <?php if ( count( $functions ) ) : ?>
<div id="documentation"><label for="docs-list">Documentation:</label> <?php echo $docs_select ?> <input type="button" class="button" value=" <?php _e( 'Lookup' ) ?> " 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> <div id="documentation"><label for="docs-list">Documentation:</label> <?php echo $docs_select ?> <input type="button" class="button" value=" <?php _e( 'Lookup' ) ?> " 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>