diff --git src/wp-admin/includes/plugin.php src/wp-admin/includes/plugin.php
index a357779..f4958a3 100644
|
|
function _get_plugin_data_markup_translate( $plugin_file, $plugin_data, $markup |
182 | 182 | * @param string $plugin Plugin ID |
183 | 183 | * @return array List of files relative to the plugin root. |
184 | 184 | */ |
185 | | function get_plugin_files($plugin) { |
| 185 | function get_plugin_files( $plugin ) { |
186 | 186 | $plugin_file = WP_PLUGIN_DIR . '/' . $plugin; |
187 | | $dir = dirname($plugin_file); |
188 | | $plugin_files = array($plugin); |
189 | | if ( is_dir($dir) && $dir != WP_PLUGIN_DIR ) { |
190 | | $plugins_dir = @ opendir( $dir ); |
| 187 | $dir = WP_PLUGIN_DIR . '/' . current( explode( '/', $plugin, 2 ) ); |
| 188 | $plugin_files = array( $plugin ); |
| 189 | if ( is_dir( $dir ) && $dir != WP_PLUGIN_DIR ) { |
| 190 | $plugins_dir = @opendir( $dir ); |
191 | 191 | if ( $plugins_dir ) { |
192 | | while (($file = readdir( $plugins_dir ) ) !== false ) { |
193 | | if ( substr($file, 0, 1) == '.' ) |
| 192 | $plugin_basedir = plugin_basename( $dir ); |
| 193 | while ( ( $file = readdir( $plugins_dir ) ) !== false ) { |
| 194 | if ( substr( $file, 0, 1 ) == '.' ) { |
194 | 195 | continue; |
| 196 | } |
195 | 197 | if ( is_dir( $dir . '/' . $file ) ) { |
196 | | $plugins_subdir = @ opendir( $dir . '/' . $file ); |
197 | | if ( $plugins_subdir ) { |
198 | | while (($subfile = readdir( $plugins_subdir ) ) !== false ) { |
199 | | if ( substr($subfile, 0, 1) == '.' ) |
200 | | continue; |
201 | | $plugin_files[] = plugin_basename("$dir/$file/$subfile"); |
202 | | } |
203 | | @closedir( $plugins_subdir ); |
204 | | } |
| 198 | $subfiles = _get_plugin_sub_files( $dir . '/' . $file ); |
| 199 | $plugin_files = array_merge( $plugin_files, $subfiles ); |
205 | 200 | } else { |
206 | | if ( plugin_basename("$dir/$file") != $plugin ) |
207 | | $plugin_files[] = plugin_basename("$dir/$file"); |
| 201 | if ( "$plugin_basedir/$file" != $plugin ) |
| 202 | $plugin_files[] = "$plugin_basedir/$file"; |
208 | 203 | } |
209 | 204 | } |
210 | 205 | @closedir( $plugins_dir ); |
211 | 206 | } |
212 | 207 | } |
| 208 | return $plugin_files; |
| 209 | } |
213 | 210 | |
| 211 | /** |
| 212 | * Returns a recursive list of a plugin's sub files. |
| 213 | * |
| 214 | * @since 4.2.0 |
| 215 | * @access private |
| 216 | * |
| 217 | * @param string $subdir Sub directory path. |
| 218 | * @return array List of files relative to the sub directoy root. |
| 219 | */ |
| 220 | function _get_plugin_sub_files( $subdir ) { |
| 221 | $plugins_subdir = @opendir( $subdir ); |
| 222 | if ( $plugins_subdir ) { |
| 223 | $plugin_basedir = plugin_basename( $subdir ); |
| 224 | $plugin_files = array(); |
| 225 | while ( ( $subfile = readdir( $plugins_subdir ) ) !== false ) { |
| 226 | if ( substr( $subfile, 0, 1 ) == '.' ) { |
| 227 | continue; |
| 228 | } |
| 229 | if ( is_dir( $subdir . '/' . $subfile ) ) { |
| 230 | $subfiles = _get_plugin_sub_files( $subdir . '/' . $subfile ); |
| 231 | $plugin_files = array_merge( $plugin_files, $subfiles ); |
| 232 | } else { |
| 233 | $plugin_files[] = "$plugin_basedir/$subfile"; |
| 234 | } |
| 235 | } |
| 236 | @closedir( $plugins_subdir ); |
| 237 | } |
214 | 238 | return $plugin_files; |
215 | 239 | } |
216 | 240 | |
diff --git src/wp-admin/plugin-editor.php src/wp-admin/plugin-editor.php
index 1c24295..1abe221 100644
|
|
default: |
199 | 199 | <?php |
200 | 200 | foreach ( $plugins as $plugin_key => $a_plugin ) { |
201 | 201 | $plugin_name = $a_plugin['Name']; |
202 | | if ( $plugin_key == $plugin ) |
203 | | $selected = " selected='selected'"; |
204 | | else |
205 | | $selected = ''; |
206 | | $plugin_name = esc_attr($plugin_name); |
207 | | $plugin_key = esc_attr($plugin_key); |
| 202 | $plugin_parts = explode( '/', $plugin ); |
| 203 | $plugin_key_parts = explode( '/', $plugin_key ); |
| 204 | $selected = $plugin_key_parts[0] == $plugin_parts[0] ? " selected='selected'" : ''; |
| 205 | $plugin_name = esc_attr( $plugin_name ); |
| 206 | $plugin_key = esc_attr( $plugin_key ); |
208 | 207 | echo "\n\t<option value=\"$plugin_key\" $selected>$plugin_name</option>"; |
209 | 208 | } |
210 | 209 | ?> |
… |
… |
default: |
220 | 219 | |
221 | 220 | <ul> |
222 | 221 | <?php |
223 | | foreach ( $plugin_files as $plugin_file ) : |
| 222 | foreach ( $plugin_files as $key => $plugin_file ) : |
224 | 223 | // Get the extension of the file |
225 | | if ( preg_match('/\.([^.]+)$/', $plugin_file, $matches) ) { |
| 224 | if ( preg_match( '/\.([^.]+)$/', $plugin_file, $matches ) ) { |
226 | 225 | $ext = strtolower($matches[1]); |
227 | 226 | // If extension is not in the acceptable list, skip it |
228 | | if ( !in_array( $ext, $editable_extensions ) ) |
| 227 | if ( ! in_array( $ext, $editable_extensions ) ) { |
229 | 228 | continue; |
| 229 | } |
230 | 230 | } else { |
231 | 231 | // No extension found |
232 | 232 | continue; |
233 | 233 | } |
| 234 | |
| 235 | // Don't show the file twice. |
| 236 | if ( $key > 0 && $plugin_file == $file ) { |
| 237 | continue; |
| 238 | } |
| 239 | |
| 240 | $file_parts = explode( '/', $plugin_file ); |
| 241 | $relative_file = str_replace( $file_parts[0] . '/', '', $plugin_file ); |
| 242 | $file_description = get_file_description( WP_PLUGIN_DIR . '/' . $plugin_file ); |
| 243 | |
| 244 | if ( $file_description != $plugin_file ) { |
| 245 | $file_description .= '<br /><span class="nonessential">(' . $relative_file . ')</span>'; |
| 246 | } |
| 247 | if ( $plugin_file == $file ) { |
| 248 | $file_description = '<span class="highlight">' . $file_description . '</span>'; |
| 249 | } |
234 | 250 | ?> |
235 | | <li<?php echo $file == $plugin_file ? ' class="highlight"' : ''; ?>><a href="plugin-editor.php?file=<?php echo urlencode( $plugin_file ) ?>&plugin=<?php echo urlencode( $plugin ) ?>"><?php echo $plugin_file ?></a></li> |
| 251 | <li><a href="plugin-editor.php?file=<?php echo urlencode( $plugin_file ) ?>&plugin=<?php echo urlencode( $plugin ) ?>"><?php echo $file_description ?></a></li> |
236 | 252 | <?php endforeach; ?> |
237 | 253 | </ul> |
238 | 254 | </div> |
diff --git src/wp-admin/theme-editor.php src/wp-admin/theme-editor.php
index d0ecee4..d999bc6 100644
|
|
if ( $allowed_files ) : |
174 | 174 | endif; |
175 | 175 | |
176 | 176 | foreach ( $allowed_files as $filename => $absolute_filename ) : |
177 | | if ( 'style.css' == $filename ) |
| 177 | if ( 'style.css' == $filename ) { |
178 | 178 | echo "\t</ul>\n\t<h3>" . _x( 'Styles', 'Theme stylesheets in theme editor' ) . "</h3>\n\t<ul>\n"; |
| 179 | } |
| 180 | |
| 181 | $relative_file = explode( $theme->offsetGet( 'Template' ) . '/', $absolute_filename ); |
| 182 | $relative_file = $relative_file[1]; |
179 | 183 | |
180 | 184 | $file_description = get_file_description( $absolute_filename ); |
181 | | if ( $file_description != basename( $filename ) ) |
182 | | $file_description .= '<br /><span class="nonessential">(' . $filename . ')</span>'; |
183 | 185 | |
184 | | if ( $absolute_filename == $file ) |
| 186 | if ( $file_description != $relative_file ) { |
| 187 | $file_description .= '<br /><span class="nonessential">(' . $relative_file . ')</span>'; |
| 188 | } |
| 189 | if ( $absolute_filename == $file ) { |
185 | 190 | $file_description = '<span class="highlight">' . $file_description . '</span>'; |
| 191 | } |
186 | 192 | ?> |
187 | 193 | <li><a href="theme-editor.php?file=<?php echo urlencode( $filename ) ?>&theme=<?php echo urlencode( $stylesheet ) ?>"><?php echo $file_description; ?></a></li> |
188 | 194 | <?php |
diff --git tests/phpunit/tests/admin/includesPlugin.php tests/phpunit/tests/admin/includesPlugin.php
index 15afaef..931ad82 100644
|
|
class Tests_Admin_includesPlugin extends WP_UnitTestCase { |
92 | 92 | $name = 'hello.php'; |
93 | 93 | $this->assertEquals( array( $name ), get_plugin_files( $name ) ); |
94 | 94 | } |
| 95 | |
| 96 | /** |
| 97 | * @covers ::get_plugin_files |
| 98 | * |
| 99 | * @ticket 6531 |
| 100 | */ |
| 101 | public function test_get_plugin_files_beyond_two_levels_deep() { |
| 102 | mkdir( WP_PLUGIN_DIR . '/foo' ); |
| 103 | mkdir( WP_PLUGIN_DIR . '/foo/bar' ); |
| 104 | mkdir( WP_PLUGIN_DIR . '/foo/bar/baz' ); |
| 105 | |
| 106 | $this->_create_plugin( '<?php\n//Foo', 'foo.php', WP_PLUGIN_DIR . '/foo' ); |
| 107 | $this->_create_plugin( '<?php\n//Baz', 'baz.php', WP_PLUGIN_DIR . '/foo/bar/baz' ); |
| 108 | $this->assertEquals( Array ( 'foo/foo.php', 'foo/bar/baz/baz.php' ), get_plugin_files( 'foo/foo.php' ) ); |
| 109 | |
| 110 | // Clean up. |
| 111 | unlink( WP_PLUGIN_DIR . '/foo/foo.php' ); |
| 112 | unlink( WP_PLUGIN_DIR . '/foo/bar/baz/baz.php' ); |
| 113 | rmdir( WP_PLUGIN_DIR . '/foo/bar/baz' ); |
| 114 | rmdir( WP_PLUGIN_DIR . '/foo/bar' ); |
| 115 | rmdir( WP_PLUGIN_DIR . '/foo' ); |
| 116 | } |
95 | 117 | |
96 | 118 | /** |
97 | 119 | * @covers ::get_mu_plugins |