[wp-trac] [WordPress Trac] #57566: Issue registering blocks within a parent theme
WordPress Trac
noreply at wordpress.org
Thu Jan 26 23:47:21 UTC 2023
#57566: Issue registering blocks within a parent theme
--------------------------+-----------------------------
Reporter: jacknotman | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Editor | Version: 6.1.1
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
Registering a block type using
{{{
register_block_type('./path/to/block/block.json')
}}}
does not work when called from a parent theme. Currently, any existing
instances of the block added prior to enabling the child theme will show
the
{{{
'Your site doesn’t include support for the "..." block.'
}}}
message. With
{{{
define( 'SCRIPT_DEBUG', true );
}}}
multiple errors are outputted to the dev console, indicating that the
necessary CSS / JS files could not be loaded; this is due to the necessary
files returning 404 errors as a result of WordPress appending the paths
with the plugin directory URI.
This appears to be happening due to how WordPress handles registering
blocks from themes. At
{{{
lines 137, and 234
}}}
of
{{{
wp-includes/blocks.php
}}}
when enqueuing necessary block assets from block.json the function
{{{
get_theme_file_path()
}}}
is used with an empty string ie:
{{{
get_theme_file_path('')
}}}
When passed an empty string this function returns the path to the
currently active theme, which in this case is a child theme, therefor
causing the subsequent
{{{
$is_theme_block
}}}
at
{{{
line 141
}}}
to equal
{{{
false
}}}
This causes the function to incorrectly use the
{{{
plugins_url(...)
}}}
path, rather than also checking the parent theme directory as would be
expected.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/57566>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list