Make WordPress Core

Opened 2 months ago

Closed 2 months ago

Last modified 2 months ago

#59453 closed enhancement (fixed)

Replace property_exists call in block api with instanceof

Reported by: spacedmonkey's profile spacedmonkey Owned by: gziolo's profile gziolo
Milestone: Future Release Priority: normal
Severity: normal Version: 5.8
Component: Editor Keywords: has-patch gutenberg-merge
Focuses: coding-standards Cc:

Description

Remove calls this in block functions

property_exists( $block_type, 'supports' ) 

with

$block_type instanceof WP_Block_Type

Change History (9)

This ticket was mentioned in PR #5308 on WordPress/wordpress-develop by @spacedmonkey.


2 months ago
#1

  • Keywords has-patch added

#2 @spacedmonkey
2 months ago

  • Owner set to gziolo
  • Status changed from new to reviewing

#3 @spacedmonkey
2 months ago

There are performance benefits and code quality to this improvement.

#4 @flixos90
2 months ago

@spacedmonkey Could you share some benchmarks or profiles here in regards to the performance impact?

#5 @gziolo
2 months ago

I'm not entirely sure how backporting works for these files, but it's worth emphasizing that the same code lives in the Gutenberg plugin in https://github.com/WordPress/gutenberg/tree/trunk/lib/block-supports. I'm sure these files aren't copied automatically, but if you agree on the changes, we will have to apply the same set of changes in the Gutenberg plugin. I can see how these changes would improve performance by using language constructs like instanceof and isset.

A separate discussion would be how to make it easier to sync code between WordPress core and Gutenberg for block supports.

#7 @spacedmonkey
2 months ago

  • Keywords gutenberg-merge added

#8 @spacedmonkey
2 months ago

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

In 56742:

Editor: Replace property_exists calls in block related functions with instanceof

Replace calls to property_exists with instanceof WP_Block_Type in block related functions. This change not only improves type safety but also enhances performance.

Follow on from [56678] and [56677].

Props gziolo, aristath, aaronrobertshaw, spacedmonkey.
Fixes #59453

Note: See TracTickets for help on using tickets.