Make WordPress Core

Opened 10 months ago

Closed 4 months ago

Last modified 3 months ago

#59175 closed defect (bug) (fixed)

register_block_type is not working with symbolic links

Reported by: antonlukin's profile antonlukin Owned by: audrasjb's profile audrasjb
Milestone: 6.5 Priority: normal
Severity: normal Version:
Component: Editor Keywords: has-patch
Focuses: Cc:

Description

I try to register new block inside functions.php of my theme with register_block_type( DIR . '/build/speech' ); function.
block.json is located inside './build/speech' directory.

The block registered correctly, but files editorScript and editorStyle can't enqueue because of the symlinks problem.

$is_theme_block variable set to false while
$style_path_norm points to /srv/http/kedr.media/theme/public/blocks/build/help/index.css
$template_path_norm points to /srv/http/kedr.media/wordpress/wp-content/themes/kedr

https://github.com/WordPress/WordPress/blob/106404bcbd2e8c19947b64691dd2dbadf0f02a47/wp-includes/blocks.php#L272

My theme is physically located on /srv/http/kedr.media/theme/public/ path, but WordPress core on /srv/http/kedr.media/wordpress/

This doesn't seem to be the best way to check if a block is part of a theme.

Change History (12)

#1 @spacedmonkey
9 months ago

@antonlukin There are been changes to the block registration process in WP 6.4. It is possible that you could test the latest beta to see if that fixes the issue.

This ticket was mentioned in PR #5460 on WordPress/wordpress-develop by @spacedmonkey.


8 months ago
#2

  • Keywords has-patch added

#3 @spacedmonkey
8 months ago

Pinging @audrasjb, as this is an area that they have looked at in the past. There is a draft PR with a fix.

#4 @antonlukin
8 months ago

I apologize for the delay, I'll try to check today with the latest patch

#5 @antonlukin
8 months ago

@spacedmonkey checked on 6.4. It works, thanks!

#6 @spacedmonkey
8 months ago

I believe it too late for 6.4, but maybe 6.4.1.

#7 @maxpertici
4 months ago

I encountered the same problem today and arrived at the same place (and solution). It would be very useful to support symbolic links for themes. Thanks for this PR.

#8 @audrasjb
4 months ago

  • Milestone changed from Awaiting Review to 6.5

Self assigning for testing/review 👀

#9 @audrasjb
4 months ago

I reproduced the issue and the patch fixes it.
I'm gonna commit it so it still have time to be tested during beta cycle.

By the way I'm wondering about directly including realpath() in wp_normalize_path() to avoid those issues in the future? (but that's for another ticket).

#10 @audrasjb
4 months ago

  • Owner set to audrasjb
  • Resolution set to fixed
  • Status changed from new to closed

In 57675:

Editor: Allow symlinks in directories provided to get_block_asset_url().

This changeset allows using symbolic links for editorScript and editorStyle in register_block_type(). This adds realpath to template and stylesheet in get_block_asset_url() to ensure returning canonicalized absolute pathnames.

Follow-up to [56683].

Props antonlukin, spacedmonkey, maxpertici.
Fixes #59175.
See #58525.

This ticket was mentioned in Slack in #core-test by oglekler. View the logs.


3 months ago

Note: See TracTickets for help on using tickets.