[wp-trac] [WordPress Trac] #31620: get_raw_theme_root does not resolve custom theme folder when is the unique

WordPress Trac noreply at wordpress.org
Fri Mar 13 02:54:51 UTC 2015


#31620: get_raw_theme_root does not resolve custom theme folder when is the unique
--------------------------------+-----------------------------
 Reporter:  giuseppe.mazzapica  |      Owner:
     Type:  defect (bug)        |     Status:  new
 Priority:  normal              |  Milestone:  Awaiting Review
Component:  Bootstrap/Load      |    Version:
 Severity:  normal              |   Keywords:
  Focuses:                      |
--------------------------------+-----------------------------
 `get_raw_theme_root`
 (https://developer.wordpress.org/reference/functions/get_raw_theme_root/)
 does this check:


 {{{
 if ( count($wp_theme_directories) <= 1 )
    return '/themes';
 }}}

 It means that if there is just one theme directory it is always assumed to
 be the `/themes` folder inside content directory.

 If an user wants to register a custom theme folder via
 `register_theme_directory()` (in a MU plugin) that user is forced to keep
 `WP_CONTENT_DIR/themes` folder (even empty) otherwise the custom directory
 registration does not work and WP will try to load a theme from a folder
 that doesn't exist.

 That is an edge case, but can be easily solved by picking the unique
 folder if there is only one:

 {{{
 $count = count($wp_theme_directories);

 if ( 0 === $count ) {
     return '/themes';
 }

 if ( 1 === $count ) {
     $path = reset($wp_theme_directories);
     $real = realpath($path);
     $content = realpath(WP_CONTENT_DIR);
     return strpos($real, $content) === 0 ? substr($real, strlen($content))
 : $path;
 }
 }}}

 If there is only one folder and it is inside content directory, the code
 above also takes care of returning the relative path.
 That, according to #17597, is necessary to obtain a correct theme url.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/31620>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list