Make WordPress Core

Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#56284 closed defect (bug) (fixed)

Site Editor: Pass correct context into get_block_categories

Reported by: mamaduka's profile Mamaduka Owned by: gziolo's profile gziolo
Milestone: 6.1 Priority: normal
Severity: normal Version: 5.9
Component: Editor Keywords: has-patch
Focuses: Cc:

Description

Site Editor passes global $post as a context when setting up block categories. Instead, it should pass $block_editor_context, since global $post is null in this file.

To reproduce:

<?php
add_filter( 'block_categories_all', function( $categories, $context ) {
        error_log( var_export( $context instanceof WP_Block_Editor_Context, true ) );

        return $categories;
}, 10, 2 );

Expected:

The example above should log true twice.

Actual:

Logs true and false.

Note: The second log represents the get_block_categories call when setting up the categories. The first comes from get_block_editor_settings, where context is correctly set.

Change History (8)

This ticket was mentioned in PR #3021 on WordPress/wordpress-develop by Mamaduka.


3 years ago
#1

  • Keywords has-patch added

Passes correct context into get_block_categories and removes $post global from the site-editor.php file.

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

Mamaduka commented on PR #3021:


3 years ago
#2

cc @gziolo

gziolo commented on PR #3021:


3 years ago
#3

Thank you for working on it and the ping @Mamaduka. It looks like a step in the right direction. It feels like there are more places where the same issue might exist already, or it might get exposed in the future when the context passed on different screens further evolves.

#4 @gziolo
3 years ago

To clarify, with the patch applied, the filter presented in the description runs only once and it has the correct block context provided.

#5 @gziolo
3 years ago

  • Milestone changed from Awaiting Review to 6.1
  • Version set to 5.9

Mamaduka commented on PR #3021:


3 years ago
#6

Thanks for the feedback and review, @gziolo!

#7 @gziolo
3 years ago

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

In 53784:

Site Editor: Pass correct context into get_block_categories

Site Editor passed incorrectly global $post as a context when setting up block categories. Instead, it should pass $block_editor_context, since global $post is null in this file.

Props Mamaduka.
Fixes #56284.

Note: See TracTickets for help on using tickets.