Make WordPress Core

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#56284 closed defect (bug) (fixed)

Site Editor: Pass correct context into get_block_categories

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

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.


4 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:


4 years ago
#2

cc @gziolo

​gziolo commented on ​PR #3021:


4 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
4 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
4 years ago

  • Milestone Awaiting Review → 6.1
  • Version → 5.9

​Mamaduka commented on ​PR #3021:


4 years ago
#6

Thanks for the feedback and review, @gziolo!

#7 @gziolo
4 years ago

  • Owner set to gziolo
  • Resolution → fixed
  • Status new → 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.