[wp-trac] [WordPress Trac] #59969: Conditional loading `build_template_part_block_variations` for performance improvement
WordPress Trac
noreply at wordpress.org
Mon Jan 22 21:12:09 UTC 2024
#59969: Conditional loading `build_template_part_block_variations` for performance
improvement
--------------------------------------+--------------------------
Reporter: thekt12 | Owner: joemcgill
Type: defect (bug) | Status: reopened
Priority: normal | Milestone: 6.5
Component: General | Version:
Severity: normal | Resolution:
Keywords: has-patch needs-dev-note | Focuses: performance
--------------------------------------+--------------------------
Comment (by joemcgill):
The PHPUnit tests in the Gutenberg plugin for the Nav Link block has been
fixed, but this did expose an issue where indirectly modifying the
overloaded variations property no longer works. Copying the description
from @thekt12 on #60309 here so we can keep discussion of this issue all
in one place:
> The setting of WP_Block_Type::$variations from the outside in a normal
way like $block_type-> variations = array( array(...), ... ) works fine.
However if we try to set it especially $block_type->variations[] = array(
... ); it throws Indirect modification of overloaded property
WP_Block_Type::$variations has no effect.
>
> The reason is WP_Block_Type::$variations is only accessible via the
magic __get, __set function. __get always returns a copy of the original
attribute variable and not the reference of the actual attribute variable.
>
> So, when we do $block_type->variations = array( array(...), ... ) we are
only setting the temporary variable which is then processed by __set to
set the original attribute.
>
> But this fails when we try to set the variable in a way where it's
original state is checked like in ->$block_type->variations[] = array( ...
);; Here, we try to add to the original variable array.
>
> The way to fix this is by trying to get the reference of the original
variable from __get instead of copy of variable
--
Ticket URL: <https://core.trac.wordpress.org/ticket/59969#comment:63>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list