WordPress.org

Make WordPress Core

Opened 12 months ago

Last modified 3 weeks ago

#24143 reopened defect (bug)

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

Reported by: azizur Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 3.4
Component: Themes Keywords:
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 3 months ago.
Always register ABSPATH . 'wp-content/themes'
24143.2.diff (457 bytes) - added by Denis-de-Bernardy 3 months ago.
fix typo

Download all attachments as: .zip

Change History (20)

comment:1 alexvorn212 months ago

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

WP_CONTENT_DIR is a constant that you can re-define.

comment:2 azizur12 months 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).

comment:3 alexvorn212 months ago

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

comment:4 dd3212 months 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.

comment:5 follow-up: SergeyBiryukov12 months ago

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

comment:6 azizur12 months 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.

comment:7 in reply to: ↑ 5 ; follow-up: azizur12 months ago

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

Last edited 12 months ago by azizur (previous) (diff)

comment:8 lancewillett10 months ago

  • Component changed from Bundled Theme to Themes

comment:9 in reply to: ↑ 7 SergeyBiryukov10 months 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.

comment:10 azizur6 months 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.

comment:11 azizur6 months 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 6 months ago by azizur (previous) (diff)

comment:12 ocean903 months ago

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

comment:13 Denis-de-Bernardy3 months 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-Bernardy3 months ago

Always register ABSPATH . 'wp-content/themes'

Denis-de-Bernardy3 months ago

fix typo

comment:14 follow-up: nacin3 months 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?

comment:15 ircbot3 months ago

This ticket was mentioned in IRC in #wordpress-dev by ddebernardy. View the logs.

comment:16 SergeyBiryukov2 months ago

  • Milestone set to Awaiting Review

comment:17 in reply to: ↑ 14 Denis-de-Bernardy2 months 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.

comment:18 wilsmex3 weeks 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.

Note: See TracTickets for help on using tickets.