WordPress.org

Make WordPress Core

Opened 7 months ago

Last modified 7 months ago

#47002 new enhancement

Create wp_theme_directory_constants() function and dynamic WordPress Themes folder

Reported by: mehrshaddarzi Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Themes Keywords: has-patch needs-testing
Focuses: Cc:
PR Number:

Description

One of the needs of WordPress users is to dynamically modify the themes folder.

For Change themes folder name in (wp-content dir) you can added this code in wp-config.php :

define( 'WP_THEMES_DIR', "template" );

also for change complete path and url :

define( 'WP_THEMES_PATH', ABSPATH . "/public/template" );
define( 'WP_THEMES_URL', WP_SITEURL . "/public/template" );

This item works for WordPress Multi-site without problems.

Attachments (3)

47002.patch (4.9 KB) - added by mehrshaddarzi 7 months ago.
47002-2.patch (3.9 KB) - added by mehrshaddarzi 7 months ago.
Fixed WordPress themes
error.JPG (105.8 KB) - added by mehrshaddarzi 7 months ago.

Download all attachments as: .zip

Change History (7)

#1 @man4toman
7 months ago

  • Keywords needs-testing dev-feedback added
  • Version 5.1.1 deleted

#2 @SergeyBiryukov
7 months ago

  • Component changed from General to Themes
  • Keywords reporter-feedback added; dev-feedback removed

Hi @mehrshaddarzi, welcome to WordPress Trac! Thanks for the ticket.

Have you considered using register_theme_directory() instead?

#3 @mehrshaddarzi
7 months ago

@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
/**
 * 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.

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 :

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.

@mehrshaddarzi
7 months ago

Fixed WordPress themes

@mehrshaddarzi
7 months ago

#4 @ocean90
7 months ago

  • Keywords reporter-feedback removed

Related: #31620

Note: See TracTickets for help on using tickets.