[wp-trac] [WordPress Trac] #54829: Allow classic themes to be optionally block themes if 'templates' and 'parts' folders exists

WordPress Trac noreply at wordpress.org
Sat Jan 15 18:37:03 UTC 2022


#54829: Allow classic themes to be optionally block themes if 'templates' and
'parts' folders exists
-------------------------+-----------------------------
 Reporter:  exstheme     |      Owner:  (none)
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  Themes       |    Version:  trunk
 Severity:  normal       |   Keywords:  needs-patch
  Focuses:               |
-------------------------+-----------------------------
 Hello!

 I have created folders 'templates' and 'parts' inside classic WordPress
 theme folder (and 'index.html' file) as noted here:
 [https://developer.wordpress.org/block-editor/how-to-guides/themes/block-
 theme-overview/].

 This automatically converts classic theme to a block theme.

 But I want to this conversion was optionally - depending of theme's
 settings.

 I was able to create two filters.
 First filter will disable 'Appearance -> Editor' admin menu item and
 return 'Appearance -> Customize' menu item.

 {{{
 if ( ! function_exists( 'disable_block_dirs' ) ) :
   function disable_block_dirs( $path, $file ) {
     //Custom logic to check settings to make block theme from classic
 theme here:
     if ( 'templates/index.html' === $file ) {
       $path = 'SOME_NOT_EXISTING_PATH';
     }
     return $path;
   }
 endif;
 add_filter( 'theme_file_path', 'disable_block_dirs', 10, 2 );
 }}}


 This filter is used in the '**wp-includes/class-wp-theme.php**' in the
 **public function get_file_path**, which is used in the **public function
 is_block_theme**

 Can we patch this file to add some filter **public function
 is_block_theme** that we could hook to before returning true or false?

 Second filter is more harmful.
 It will disable using custom HTML block templates on the front end. But it
 can be potentially very harmful because it's changing theme_root folder
 for the WordPress itself.

 {{{
 if ( ! function_exists( 'disable_block_dirs_second' ) ) :
   function disable_block_dirs_second( $path ) {
     //Custom logic to check settings to make block theme from classic
 theme here before return:
     return 'SOME_NOT_EXISTING_PATH';
   }
 endif;
 add_filter( 'theme_root', 'disable_block_dirs_second');
 }}}

 This filter is used in the '**wp-includes/block-template-utils.php**' in
 the **function get_block_theme_folders**

 Can we patch this file to add some filter to the
 **get_block_theme_folders** function to filter array that this function is
 returning that we could hook to?

 ---

 Anyway now '**get_block_theme_folders**' and
 '**wp_get_theme()->is_block_theme**' are working independent from each
 other that does not make any sense. This should be fixed, I guess.

 Hope this make sense.
 Best regards!

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


More information about the wp-trac mailing list