Opened 14 years ago
Closed 13 years ago
#16744 closed defect (bug) (fixed)
Theme editor doesn't work on child themes whose parents have a custom theme directory root
Reported by: | DJPaul | Owned by: | nacin |
---|---|---|---|
Milestone: | 3.4 | Priority: | normal |
Severity: | normal | Version: | 3.1 |
Component: | Administration | Keywords: | needs-patch |
Focuses: | Cc: |
Description
The theme editor doesn't work when trying to edit a child theme whose base theme is not located in /wp-content/themes, i.e. register_theme_directory. For example, on a child theme of BuddyPress' default theme:
Child theme: /themes/my-child-theme/
Base theme: /plugins/buddypress/bp-themes/bp-default/
Theme editor fails with 'Sorry, that file cannot be edited'. (BuddyPress 1.2.8, WordPress 3.1)
Change History (8)
#4
@
14 years ago
I didn't test, just assumed. If the issue is the $file going into validate_file_to_edit(), that seems like it's not a regression.
#5
in reply to:
↑ 1
@
14 years ago
- Version changed from 3.0 to 3.1
in theme-editor.php, change
if ( 'theme' == $dir ) { $file = dirname(dirname($themes[$theme]['Template Dir'])) . $file ; }
to
if ( 'theme' == $dir ) { if($themes[$theme]['Template'] == $themes[$theme]['Stylesheet']){ $file = dirname(dirname($themes[$theme]['Template Dir'])) . $file ; } }
it's around line 63, for me, just above the call to validate_file_to_edit().
the problem is the path to a bp child theme's file is already complete, and the path to the buddypress directory gets appended to the front of it, resulting in a path pointing to a non existent file. so, i just put in the test to see if the theme is not a child theme before appending the paths, and if it is a child theme, the $file variable is left alone.
this works fine for all normal themes and all child themes of the bp-default theme. i would imagine that this would break the editing capabilities of a child theme of a normal theme, but as i don't have any to test with, i'm unsure.
the complete fix should check specifically if the parent theme is bp-default or not, but i'll leave that to the experts.
(this problem did not manifest for me in 3.0.1 or 3.0.4, but only in 3.1)
Replying to DJPaul:
This seems to be caused by the call to validate_file_to_edit() in theme-editor.php. The logic when setting $file assumes that the theme root directory is always two levels up.
On a clean debug install, $file looks like:
/Users/paul/Sites/example.com/wp-content/plugins/buddypress/Users/paul/Sites/example.com/wp-content/themes/test/functions.php
This seems to be caused by the call to validate_file_to_edit() in theme-editor.php. The logic when setting $file assumes that the theme root directory is always two levels up.
On a clean debug install, $file looks like: