-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PHP Warnings when featured image blocks have a sizeSlug but not classname #49615
Comments
Is this markup copied from an actual block that was inserted in the editor? What I mean is, if this attribute is added manually in the markup, for example, in an HTML template, the attribute is incorrect, because the markup is invalid and the warning would be accurate. |
No it’s based on attributes declared in the block that don’t have GUI
anymore. Trying to resolve blurry featured images when an image tag is
large but has been given a tiny height and width by WP.
It seems that core assumes the class name attribute has a value which isn’t
a safe assumption
…On Thu, 6 Apr 2023 at 08:51, Carolina Nymark ***@***.***> wrote:
Is this markup copied from an actual block that was inserted in the editor?
—
Reply to this email directly, view it on GitHub
<#49615 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAOLZ2R4CCSGYY3YLGJGVLW7ZYZTANCNFSM6AAAAAAWUEV7WY>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
I understand now. I am not sure if that could be handled in the deprecation of the featured image block 🤔 It probably assumes the class name should be preserved. |
Even still I'd assume there'd be a logic issue rather than a warning, this is the place it occurs in one of the stack traces: function wp_apply_custom_classname_support( $block_type, $block_attributes ) {
$has_custom_classname_support = block_has_support( $block_type, array( 'customClassName' ), true );
$attributes = array();
if ( $has_custom_classname_support ) {
$has_custom_classnames = array_key_exists( 'className', $block_attributes ); I'm unsure why Noting I've yet to test this with the GB plugin |
I am attempting to reproduce this problem but have not yet been able to output a warning error. Is this problem related to the size of the images, or the media settings? |
It's using the specific markup I posted in the opening issue, the Somewhere there's an assumption that a value is always a string or array when it is not and it's being passed down and causing a PHP warning. In this case, checking if Note that I have not tested this with the gutenberg plugin, only stock WP 6.2 and a block theme |
Are you saying the markup is not produced by placing a block in the editor and then upgrading WordPress? |
If a block expects both an attribute and a class name, then removing one makes the markup invalid and the error is correct. The solution is to correct the markup, not the expectation... |
The featured image is displayed on the frontend despite the PHP warnings, the HTML is not the problem. As I mentioned, this is enough to reproduce the problem reliably at my end in WordPress 6.2:
But even if I'm also unsure where upgrading WordPress is coming from, I did not mention WordPress upgrades. Just that the above block in WordPress 6.2 generates PHP warnings for me, and that I had to write a filter to give |
If you are suggesting that the |
I asked how the markup was generated, and you replied:
I assumed that if the UI is gone, there has been a change in the block code, and the error, like a missing class name, should have been resolved by a deprecation when the block code was changed. So yes, because it did not sound like the user had manually added incomplete markup, I thought there was a block placed in a previous version of WordPress or Gutenberg and that updating either caused the error. |
I agree |
It is very unclear because not all attributes have a class name, and some class names replace attributes that have been removed or renamed to keep backward compatibility. |
I am not able to reproduce the warning by pasting If I add
The block editor can not "heal" the block and remove the problems without the user opening the template in the site editor. |
Oh wow, I can't believe it took me this long to see it. |
I still agree that it is brittle. I often prefer to add the code in the HTML file without having to copy-paste everything from the editor. We could:
|
It is also unclear why the attributes were removed completely instead of displaying as a block validation error in the editor. |
Description
If i use the following block I get PHP warnings in core:
<!-- wp:post-featured-image {isLink":true,"sizeSlug":"medium"} /-->
The addition of
sizeSlug
is the instigator, and it's related to the className attribute.I can resolve this by using the
render_block_data
to filter the block data and ensure that ifclassName
is unset it has an empty string value:This is the warning:
And it appears in 2 locations in core every time the block is rendered:
and:
Step-by-step reproduction instructions
Try to use a
sizeSlug
attribute on a featured image block in a block themeScreenshots, screen recording, code snippet
No response
Environment info
WP 6.2 with a block theme
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Yes
The text was updated successfully, but these errors were encountered: