[wp-trac] [WordPress Trac] #56859: Blocks: register_block_script_handle() does not account for symlinks
WordPress Trac
noreply at wordpress.org
Thu Oct 20 00:24:27 UTC 2022
#56859: Blocks: register_block_script_handle() does not account for symlinks
--------------------------+------------------------------
Reporter: cr0ybot | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Editor | Version: 6.0.3
Severity: normal | Resolution:
Keywords: | Focuses:
--------------------------+------------------------------
Comment (by cr0ybot):
Prior to the update that allows block registration in themes, I had been
filtering `plugins_url` but also checking for symlinks with `is_link()`
and `readlink()`. This doesn't really solve for expanding the path though.
Here's that filter for reference. It's a bit of a blunt instrument, but it
works.
{{{#!php
<?php
/**
* While block registration from themes is now supported, registration
from
* themes that are symlinked, like you might do when developing locally,
is not.
*
* @link https://core.trac.wordpress.org/ticket/56859
*
* Used in register_blocks().
*/
function block_plugins_url( $url, $path ) {
// Handle symlinked paths (generally only during local
development).
$dir = get_template_directory();
if ( is_link( $dir ) ) {
$dir = readlink( $dir );
}
// Split the $url by the current theme slug and get just the file
path.
$file = explode( $dir, $url )[1];
// For some reason this is getting applied to the gutenberg plugin
urls, so we check if the string explode above worked.
if ( empty( $file ) ) {
return $url;
}
return untrailingslashit( get_template_directory_uri() ) . $file;
}
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/56859#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list