Make WordPress Core

Opened 13 years ago

Closed 12 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's profile DJPaul Owned by: nacin's profile 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)

#1 follow-up: @DJPaul
13 years ago

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

#2 @nacin
13 years ago

  • Version changed from 3.1 to 3.0

Not a regression, version --.

#3 @StevieG
13 years ago

Can you explain that @nacin? The problem doesn't manifest in 3.0.5

#4 @nacin
13 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 @officialjunk
13 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
Last edited 13 years ago by officialjunk (previous) (diff)

#6 @SergeyBiryukov
13 years ago

  • Keywords needs-patch added

#7 @nacin
12 years ago

  • Owner set to nacin
  • Status changed from new to accepted

#8 @nacin
12 years ago

  • Milestone changed from Awaiting Review to 3.4
  • Resolution set to fixed
  • Status changed from accepted to closed

The work of #15672 and #20103 together should fix this. Looks like a simple 'Template Dir' was supposed to be a 'Stylesheet Dir'.

Note: See TracTickets for help on using tickets.