[wp-trac] [WordPress Trac] #3674: WordPress Admin Theme Editor
Right Sidebar drops files from template list.
WordPress Trac
wp-trac at lists.automattic.com
Thu Jan 25 11:23:20 GMT 2007
#3674: WordPress Admin Theme Editor Right Sidebar drops files from template list.
----------------------------+-----------------------------------------------
Reporter: gjorgensen | Owner: anonymous
Type: defect | Status: new
Priority: high | Milestone: 2.3
Component: Administration | Version:
Severity: major | Keywords:
----------------------------+-----------------------------------------------
This ticket includes both the problem introduced in version 2.1, and the
(very easy) bug fix to wp-admin/admin.functions.php.
For full text and sample screen shots please visit
http://gilbertjorgensen.com/2007/01/24/wordpress-21-admin-theme-file-
patch/
The screenshots make the problem obvious.
In the Admin Theme Editor, I could mouse over the right side listing of
templates and the screen would indicate that they were there by providing
highlighted vertical bars at the ends of the lines, but the text was
missing.
Deciding that this was unacceptable, I did a little research to determine
what had changed and found the offending line. It seems that in the new
2.1 release there has been an attempt to make the code more readable by
adding spaces around field names, etc. In most cases that doesn’t create
any problem, however in a regular expression it can produce unexpected
results.
Starting at line 1597 of wp-admin/admin.functions.php we have the
following code:
function get_file_description( $file ) {
global $wp_file_descriptions;
if ( isset( $wp_file_descriptions[basename( $file )] ) ) {
return $wp_file_descriptions[basename( $file )];
}
elseif ( file_exists( ABSPATH . $file ) && is_file( ABSPATH .
$file ) ) {
$template_data = implode( '', file( ABSPATH . $file ) );
if ( preg_match( "|Template Name:(.* )|i", $template_data,
$name ))
return $name[1];
}
return basename( $file );
}
Notice specifically line 1605 which says:
if ( preg_match( "|Template Name:(.* )|i", $template_data, $name ))
Line 1605 instructs the PHP regular expression parser to match against the
string “|Template Name:(.* )|i”. Notice how we have in parenthesis (.* ),
e.g. a left parenthesis, a period, and asterisc, a space, and a right
parenthesis. The space is the culprit. Take the space out so we have (.*),
and our list or WordPress templates will display just fine.
I did a “Search all files” with my UltraEdit text editor and did not find
any other “preg_match” occurances with offending spaces in the new
WordPress 2.1 release.
--
Ticket URL: <http://trac.wordpress.org/ticket/3674>
WordPress Trac <http://trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list