[wp-trac] [WordPress Trac] #47002: Create wp_theme_directory_constants() function and dynamic WordPress Themes folder
WordPress Trac
noreply at wordpress.org
Thu Apr 25 07:16:45 UTC 2019
#47002: Create wp_theme_directory_constants() function and dynamic WordPress Themes
folder
-------------------------------------------------+-------------------------
Reporter: mehrshaddarzi | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting
| Review
Component: Themes | Version:
Severity: normal | Resolution:
Keywords: has-patch needs-testing reporter- | Focuses:
feedback |
-------------------------------------------------+-------------------------
Comment (by mehrshaddarzi):
@SergeyBiryukov
There is a bug between `register_theme_directory()` and `theme_root`
filter
For example, I wanted to changed the WordPress themes folder.
1. i renamed `themes` folder to `templates`.
2. i moved `~/home/wp-content/templates` to `~/home/public/templates`.
3. i created a mu-plugins with `themes-dir.php` and put the following
code.
{{{#!php
<?php
/**
* Plugin Name: Change Themes folder
* Description: A WordPress Plugin For Change themes folder
* Author: Mehrshad Darzi
* Version: 1.0.0
*/
register_theme_directory( ABSPATH . 'public/templates' );
add_filter( 'theme_root', function () { return ABSPATH .
'public/templates'; });
add_filter( 'theme_root_uri', function () { return home_url(
'/public/templates' ); }, 10, 1 );
}}}
I got this error : `ERROR: The theme directory "twentynineteen" does not
exist.`.
then I reviewed the WordPress core code and found two wrong codes.
`wp-includes/theme.php` line 661 and 373.
{{{#!php
if ( ! is_array( $wp_theme_directories ) || count( $wp_theme_directories )
<= 1 ) {
return '/themes';
}
}}}
top code is wrong because `theme_root` filter not considered.
i changed code to :
{{{#!php
if ( ( ! is_array( $wp_theme_directories ) || count( $wp_theme_directories
) <= 1 ) and ! has_filter( 'theme_root' ) ) {
return '/themes';
}
}}}
And worked without problems.
i Created a new patch that Fixed all problem about WordPress themes
according to `register_theme_directory()` function.
please check.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/47002#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list