WordPress.org

Make WordPress Core

Opened 2 months ago

Closed 4 weeks ago

#53757 closed defect (bug) (fixed)

Widget editor calls get_block_categories() with incorrect arg type

Reported by: Enchiridion Owned by: audrasjb
Milestone: 5.8.1 Priority: normal
Severity: normal Version: 5.8
Component: Widgets Keywords: has-patch commit fixed-major
Focuses: Cc:

Description

Just updated to 5.8.0 and found a couple issues with the new block widget editor while fixing all the new deprecated filters related to blocks.

\wp-admin\widgets-form-blocks.php:55
sprintf( 'wp.blocks.setCategories( %s );', wp_json_encode( get_block_categories( 'widgets-editor' ) ) ),

\wp-includes\class-wp-customize-widgets.php:865
sprintf( 'wp.blocks.setCategories( %s );', wp_json_encode( get_block_categories( 'widgets-customizer' ) ) ),

In these two places, get_block_categories() is being passed a string instead of the required WP_Post or WP_Block_Editor_Context instance. The string is causing a fatal error due to the type hinting on my function for the block_categories_all filter.

Change History (9)

#1 @SergeyBiryukov
2 months ago

  • Milestone changed from Awaiting Review to 5.8.1

#2 @audrasjb
2 months ago

  • Keywords needs-patch added

Good catch. It looks like we should replace 'widgets-customizer' and 'widgets-editor' with $block_editor_context variable on both files.

This ticket was mentioned in PR #1532 on WordPress/wordpress-develop by pbearne.


2 months ago

  • Keywords has-patch added; needs-patch removed

Replaced 'widgets-customizer' and 'widgets-editor' with $block_editor context in get_block_categories() function calls

Trac ticket: https://core.trac.wordpress.org/ticket/53757

#4 @prbot
6 weeks ago

willrowe commented on PR #1532:

Just got errors related to this, thanks for the fix @pbearne!

#5 @audrasjb
4 weeks ago

  • Keywords commit added
  • Owner set to audrasjb
  • Status changed from new to accepted

PR #1532 applies cleanly against trunk and fixes the issue on my side. Thanks for the PR!

Marking for commit consideration as this issue is clearly related to the widget editor and needs to be addressed in the next point release.

#6 @SergeyBiryukov
4 weeks ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In 51700:

Widgets: Pass correct context to get_block_categories() calls.

The get_block_categories() function expects either a WP_Post or a WP_Block_Editor_Context instance as the context argument, not a string.

Follow-up to [50996], [50997].

Props Enchiridion, pbearne, audrasjb.
Fixes #53757.

#7 @SergeyBiryukov
4 weeks ago

  • Keywords fixed-major added
  • Resolution fixed deleted
  • Status changed from closed to reopened

Reopening for backporting to the 5.8 branch.

#9 @desrosj
4 weeks ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 51711:

Widgets: Pass correct context to get_block_categories() calls.

The get_block_categories() function expects either a WP_Post or a WP_Block_Editor_Context instance as the context argument, not a string.

Follow-up to [50996], [50997].

Props Enchiridion, pbearne, audrasjb, SergeyBiryukov.
Merges [51700] to the 5.8 branch.
Fixes #53757.

Note: See TracTickets for help on using tickets.