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

Block Templates: Fix PHP notices on WP 5.8 #36964

Merged
merged 1 commit into from
Nov 29, 2021

Conversation

Mamaduka
Copy link
Member

Description

When the plugin runs on WP 5.8.x, it will use the WP_Block_Template class from the core, which doesn't have new properties. To avoid PHP notices, we've to use dynamic properties when building templates from the file.

Note: The issue doesn't affect WP 5.9.

How has this been tested?

  1. Clone this branch.
  2. Open Site Editor with WP_DEBUG_LOG enabled.
  3. The debug.log shouldn't contain notices.

Log

PHP Notice:  Undefined property: WP_Block_Template::$origin in ~/Projects/gutenberg/wp-content/plugins/gutenberg/lib/compat/wordpress-5.9/class-gutenberg-rest-templates-controller.php on line 467
PHP Notice:  Undefined property: WP_Block_Template::$author in ~/Projects/gutenberg/wp-content/plugins/gutenberg/lib/compat/wordpress-5.9/class-gutenberg-rest-templates-controller.php on line 477

Types of changes

Bugfix

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • I've tested my changes with keyboard and screen readers.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR (please manually search all *.native.js files for terms that need renaming or removal).

@Mamaduka Mamaduka self-assigned this Nov 29, 2021
@Mamaduka Mamaduka added [Feature] Themes Questions or issues with incorporating or styling blocks in a theme. [Type] Bug An existing feature does not function as intended labels Nov 29, 2021
@cbravobernal
Copy link
Contributor

Hi there!

I'm still having those notices when being on site editor.

Attached a Loom Video:
https://www.loom.com/share/8b7dd24c887e4dd1bf57089112a9970b

@Mamaduka
Copy link
Member Author

Thanks for testing, @c4rl0sbr4v0.

Are you using wp-env with WP 5.8.x?

I've to call it a day, but will check back on this issue tomorrow morning :)

@cbravobernal
Copy link
Contributor

I was using wp-env with a development version (5.9-alpha-52268).

Using 5.8 is working fine!

@Mamaduka
Copy link
Member Author

Makes sense :) This should fix the notice for 5.9 - WordPress/wordpress-develop#1967.

@Mamaduka Mamaduka merged commit 14612c9 into trunk Nov 29, 2021
@Mamaduka Mamaduka deleted the fix/templates-undefined-props branch November 29, 2021 17:03
@github-actions github-actions bot added this to the Gutenberg 12.1 milestone Nov 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Themes Questions or issues with incorporating or styling blocks in a theme. [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants