Skip to content
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

Add null check to prevent errors in get_block_template filter #60491

Merged
merged 1 commit into from
Apr 5, 2024

Conversation

okmttdhr
Copy link
Contributor

@okmttdhr okmttdhr commented Apr 5, 2024

What?

This PR adds null check to prevent Error : Attempt to assign property "content" on null in gutenberg_replace_pattern_blocks_get_block_template filter introduced in #60349.

Why?

Since the first param $template is WP_Block_Template or null if there isn't one.
https://github.com/WordPress/wordpress-develop/blob/8d0aed455b1790c5d51386f7675d9e8d68e48edf/src/wp-includes/block-template-utils.php#L1113

How?

Added null check before assigning the content.

Testing Instructions

Testing Instructions for Keyboard

Screenshots or screencast

@okmttdhr okmttdhr marked this pull request as ready for review April 5, 2024 04:09
@okmttdhr okmttdhr requested a review from spacedmonkey as a code owner April 5, 2024 04:09
Copy link

github-actions bot commented Apr 5, 2024

Warning: Type of PR label mismatch

To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.

  • Type-related labels to choose from: [Type] Automated Testing, [Type] Breaking Change, [Type] Bug, [Type] Build Tooling, [Type] Code Quality, [Type] Copy, [Type] Developer Documentation, [Type] Enhancement, [Type] Experimental, [Type] Feature, [Type] New API, [Type] Task, [Type] Technical Prototype, [Type] Performance, [Type] Project Management, [Type] Regression, [Type] Security, [Type] WP Core Ticket, Backport from WordPress Core.
  • Labels found: [Type] Bug, [Type] Performance, Needs PHP backport.

Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task.

Copy link

github-actions bot commented Apr 5, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: okmttdhr <okat@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@okmttdhr okmttdhr requested a review from ellatrix April 5, 2024 04:09
@okmttdhr okmttdhr added the [Type] Bug An existing feature does not function as intended label Apr 5, 2024
Copy link
Member

@Mamaduka Mamaduka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense.

@okmttdhr okmttdhr merged commit e4e7a71 into trunk Apr 5, 2024
69 of 72 checks passed
@okmttdhr okmttdhr deleted the fix/get-block-template branch April 5, 2024 08:57
@github-actions github-actions bot added this to the Gutenberg 18.2 milestone Apr 5, 2024
@@ -71,6 +71,9 @@ function gutenberg_replace_pattern_blocks_get_block_templates( $templates ) {
}

function gutenberg_replace_pattern_blocks_get_block_template( $template ) {
if ( null === $template ) {
return $template;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me that sounds like there's a bug in the get_block_template filter, which should be called at all for null.

@jeremyfelt
Copy link
Member

Related, this fixes a fatal error documented in #60638

@colorful-tones colorful-tones added [Type] Performance Related to performance efforts Needs PHP backport Needs PHP backport to Core labels Apr 19, 2024
@colorful-tones
Copy link
Member

I've added the Needs PHP backport label, but I'm unsure if it applies here. I'm mostly inferring this from the referenced #60349 which has the Needs PHP backport label. Feel free to remove if it is not applicable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs PHP backport Needs PHP backport to Core [Type] Bug An existing feature does not function as intended [Type] Performance Related to performance efforts
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants