Opened 12 years ago
Last modified 4 years ago
#24143 reopened defect (bug)
When define('WP_CONTENT_DIR', 'your-dir') twentythirteen - The theme directory does not exist.
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.4 |
Component: | Themes | Keywords: | needs-patch needs-unit-tests |
Focuses: | Cc: |
Description
If you use either of following in you wp-config.php you'd automatically get a Broken Themes.
define('WP_CONTENT_DIR', 'your-dir'); define('WP_CONTENT_URL', 'your-url');
The following themes are installed but incomplete. Themes must have a stylesheet and a template.
Name Description
twentythirteen The theme directory does not exist.
Attachments (2)
Change History (23)
#2
@
12 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
- Version set to trunk
I have not given enough background on the initial ticket.
Here is the exact process to re-produce this issue.
Directory Structure:
DocRoot/wp-config.php DocRoot/wordpress/ DocRoot/wp-content/ DocRoot/wp-content/themes DocRoot/wp-content/plugins DocRoot/wp-content/mu-plugins
Now if you have (in wp-config.php):
define('WP_CONTENT_DIR', 'DocRoot/wp-content/'); define('WP_CONTENT_URL', 'your-url');
and you have more themes stored in 'DocRoot/wp-content/themes' you can't not access them.
So you use a 'mu-plugin' that register the additional theme directory.
register_theme_directory('DocRoot/wp-content/themes');
Even at this stage you can not access the additional themes.
(I am re-opening this ticket for re-consideration as the above structure may be found to be common in some installation).
#4
@
12 years ago
register_theme_directory('DocRoot/wp-content/themes');
does work, but you need to take into consideration two things: 1. If you use a relative path, it's relative to WP_CONTENT_DIR 2. You can pass an absolute path in
So, this configuration worksforme, and twentythirteen is loaded correctly
WordPress: /media/sf_www/wordpress-commit/ WP_CONTENT_DIR in wp-config.php: /media/sf_www/content/ /media/sf_www/content/mu-plugin/themes.php: register_theme_directory( '/media/sf_www/wordpress-commit/wp-content/themes/' );
Triple check the path's you're using in the example you've given, if any are relative, or don't exist, you'll run into the breakage you're seeing.
#6
@
12 years ago
I have now tested it using absolute path and found another issue.
Now if you have (in wp-config.php):
define('WP_CONTENT_DIR', '/DocRoot/wp-content/'); // <- absolute path define('WP_CONTENT_URL', 'your-url');
Then use a 'mu-plugin' that register the additional theme directory.
register_theme_directory('/DocRoot/wordpress/wp-content/themes'); // <- absolute path
Now try to customize the theme.
Fatal error: Call to a member function theme() on a non-object in /data/site.com/wordpress/wp-admin/customize.php on line 66
Moving wp-content folder Documentation may need to be updated to mention about absolute vs relative path so its clear in its example given.
#7
in reply to:
↑ 5
;
follow-up:
↓ 9
@
12 years ago
Replying to SergeyBiryukov:
Did you meant to fix version to 3.6 ?
#9
in reply to:
↑ 7
@
12 years ago
Replying to azizur:
Did you meant to fix version to 3.6 ?
No, version number indicates the earliest affected version. Customizer and WP_Theme were both introduced in 3.4. However, I could not reproduce the issue from comment:6 neither in 3.4 nor in current trunk.
My steps (take 1):
- WordPress installation is located at
/home/wordpress/trunk
,wp-content
is one level above. - In
wp-config.php
:define('WP_CONTENT_DIR', '/home/wordpress/wp-content'); define('WP_CONTENT_URL', 'http://wordpress/wp-content');
- In a mu-plugin:
register_theme_directory('/home/wordpress/wp-content/themes');
- Visit Themes screen, activate the theme.
- Visit Customizer. It works correctly.
My steps (take 2):
- WordPress installation is located at
/home/wordpress/releases/3.4
,wp-content
is one level above. - In
wp-config.php
:define('WP_CONTENT_DIR', '/home/wordpress/releases/wp-content'); define('WP_CONTENT_URL', 'http://releases.wordpress/wp-content');
- In a mu-plugin:
register_theme_directory('/home/wordpress/releases/wp-content/themes');
- Visit Themes screen, activate the theme.
- Visit Customizer. It works correctly.
In your example from comment:6, you have:
define('WP_CONTENT_DIR', '/DocRoot/wp-content/'); // <- absolute path ... register_theme_directory('/DocRoot/wordpress/wp-content/themes'); // <- absolute path
Seems like you should use /DocRoot/wp-content/themes
in your register_theme_directory()
call.
Also note that WP_CONTENT_DIR
and WP_CONTENT_URL
do not need a trailing slash.
#10
@
11 years ago
According to Codex and implementation code one should be able to register any path in the filesystem as additional theme directory.
However it does not seems to be working that way.
The two methods described above suggest that path defined in $directory
argument must be within the WP_CONTENT_DIR
.
Take the example layout below.
/root /root/wordpress <- WordPress core /root/wp-content <- the WP_CONTENT_DIR
Now try to register the themes that are included in WordPress core plus the ones in WP_CONTENT_DIR
.
So in the /root/wp-content/mu-plugins/register-default-theme.php
register_theme_directory( '/root/wordpress/wp-content/themes' );
Thus the $wp_theme_directories
should have:
/root/wordpress/wp-content/themes /root/wp-content/themes
Because we defined WP_CONTENT_DIR
we should end up with themes from both directories in the wp-admin, unless I am missing something.
#11
@
11 years ago
I have just updated copy of my WordPress core today and everything seem to be working with the layout I have above.
Interesting observation on this issue:
When the /root/wp-content/themes
directory is empty it will result in the issue above.
#12
@
11 years ago
- Milestone Awaiting Review deleted
- Resolution set to worksforme
- Status changed from reopened to closed
#13
@
11 years ago
- Resolution worksforme deleted
- Status changed from closed to reopened
This does NOT workforme. I was about to report the exact same ticket...
#14
follow-up:
↓ 17
@
11 years ago
I don't think the solution for this is forcibly registering wp-content/themes. I think a better solution might be to, on themes.php, notice there are no themes and deduce why. Thoughts?
This ticket was mentioned in IRC in #wordpress-dev by ddebernardy. View the logs.
11 years ago
#17
in reply to:
↑ 14
@
11 years ago
- Keywords reporter-feedback removed
Replying to nacin:
I don't think the solution for this is forcibly registering wp-content/themes. I think a better solution might be to, on themes.php, notice there are no themes and deduce why. Thoughts?
Yeah, I suppose. Here's what I ended up doing in a mu-plugin, fwiw:
/** * Conditionally registers the default wp-cotent/themes folder **/ public function maybeRegisterDefaultThemeDir() { # Bail if no custom content folder is defined if (WP_CONTENT_DIR . '/themes' == ABSPATH . 'wp-content/themes') return; # Bail if a default theme is defined: # WP doesn't set it until later, so assume it's in WP_CONTENT_DIR if (defined('DEFAULT_THEME')) return; register_theme_directory(ABSPATH . 'wp-content/themes'); }
The DEFAULT_THEME
define gets set in an unwieldy location, and any number of plugins can trash whatever fix one might attempt on the 'setup_theme'
hook, so it seemed like a lesser evil.
#18
@
11 years ago
Seems related to this issue, but if I move my wp-content folder to a new location using the either of the
define('WP_CONTENT_DIR', 'your-dir'); define('WP_CONTENT_URL', 'your-url');
config values, I lose the ability to 'Insert Into Post' when adding or editing posts while logged in as anything other than super admin. Editor role won't either. Editor role can upload okay, but insert into post doesn't work, nor do any of the attached images show for a post when filtering by 'uploaded to this post' inside of the 'insert media'.
Remove those values, and everything is back to normal.. This broke in a recent (~1 yearish) WP update, as it used to work fine.
WP_CONTENT_DIR is a constant that you can re-define.