Make WordPress Core

Opened 11 years ago

Last modified 3 years ago

#24143 reopened defect (bug)

When define('WP_CONTENT_DIR', 'your-dir') twentythirteen - The theme directory does not exist.

Reported by: azizur's profile azizur 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)

24143.diff (464 bytes) - added by Denis-de-Bernardy 10 years ago.
Always register ABSPATH . 'wp-content/themes'
24143.2.diff (457 bytes) - added by Denis-de-Bernardy 10 years ago.
fix typo

Download all attachments as: .zip

Change History (23)

#1 @alexvorn2
11 years ago

  • Resolution set to fixed
  • Status changed from new to closed

WP_CONTENT_DIR is a constant that you can re-define.

#2 @azizur
11 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).

#3 @alexvorn2
11 years ago

maybe you need to define in the wp-settings.php file

#4 @dd32
11 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.

#5 follow-up: @SergeyBiryukov
11 years ago

  • Keywords reporter-feedback added
  • Version changed from trunk to 3.4

#6 @azizur
11 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: @azizur
11 years ago

Replying to SergeyBiryukov:
Did you meant to fix version to 3.6 ?

Last edited 11 years ago by azizur (previous) (diff)

#8 @lancewillett
11 years ago

  • Component changed from Bundled Theme to Themes

#9 in reply to: ↑ 7 @SergeyBiryukov
11 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):

  1. WordPress installation is located at /home/wordpress/trunk, wp-content is one level above.
  2. In wp-config.php:
    define('WP_CONTENT_DIR', '/home/wordpress/wp-content');
    define('WP_CONTENT_URL', 'http://wordpress/wp-content');
    
  3. In a mu-plugin:
    register_theme_directory('/home/wordpress/wp-content/themes');
    
  4. Visit Themes screen, activate the theme.
  5. Visit Customizer. It works correctly.

My steps (take 2):

  1. WordPress installation is located at /home/wordpress/releases/3.4, wp-content is one level above.
  2. In wp-config.php:
    define('WP_CONTENT_DIR', '/home/wordpress/releases/wp-content');
    define('WP_CONTENT_URL', 'http://releases.wordpress/wp-content');
    
  3. In a mu-plugin:
    register_theme_directory('/home/wordpress/releases/wp-content/themes');
    
  4. Visit Themes screen, activate the theme.
  5. 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 @azizur
10 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 @azizur
10 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.

Last edited 10 years ago by azizur (previous) (diff)

#12 @ocean90
10 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from reopened to closed

#13 @Denis-de-Bernardy
10 years ago

  • Resolution worksforme deleted
  • Status changed from closed to reopened

This does NOT workforme. I was about to report the exact same ticket...

@Denis-de-Bernardy
10 years ago

Always register ABSPATH . 'wp-content/themes'

@Denis-de-Bernardy
10 years ago

fix typo

#14 follow-up: @nacin
10 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.


10 years ago

#16 @SergeyBiryukov
10 years ago

  • Milestone set to Awaiting Review

#17 in reply to: ↑ 14 @Denis-de-Bernardy
10 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 @wilsmex
10 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.

#19 @chriscct7
8 years ago

  • Keywords needs-patch needs-unit-tests added

#20 @somedev
8 years ago

This theme issue seems to persist as of September 17, 2016, and 4.6.1. Themes folder path broken by WP_CONTENT_DIR, as well as many instances of "wp-content" hard coded into the core where it should be the GLOBAL instead, in my estimation.

#21 @menathor
3 years ago

Hi all. I see the warning regarding custom content directories is still there when enabling multisite. Is this still an issue in 2021 or has it been fixed?

Note: See TracTickets for help on using tickets.