Opened 4 weeks ago
Last modified 4 weeks ago
#62067 new enhancement
Remove Unnecessary array_flip Function in VALID_TOP_LEVEL_KEYS Filter
Reported by: | wpdebuglog | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | |
Component: | General | Keywords: | has-patch |
Focuses: | Cc: |
Description
The current implementation of the array_intersect_key
function uses an array_flip
on the VALID_TOP_LEVEL_KEYS
array to filter input.
This adds unnecessary overhead. We can optimize the process by converting VALID_TOP_LEVEL_KEYS
into an associative array and passing it directly to array_intersect_key
, eliminating the need for array_flip
.
Sample code:
<?php function test(){ $a = array( 'blockTypes' => 0, 'customTemplates' => 1, 'description' => 2, 'patterns' => 3, 'settings' => 4, 'slug' => 5, 'styles' => 6, 'templateParts' => 7, 'title' => 8, 'version' => 9, ); return $a; } function flip(){ $a = array( 'blockTypes', 'customTemplates', 'description', 'patterns', 'settings', 'slug', 'styles', 'templateParts', 'title', 'version', ); return array_flip( $a ); } test(); flip();
File: wp-includes/class-wp-theme-json.php
WP_Theme_JSON::sanitize is calling more than 50 times.
Attachments (1)
Change History (2)
This ticket was mentioned in PR #7392 on WordPress/wordpress-develop by arshidkv12.
4 weeks ago
#1
- Keywords has-patch added
Note: See
TracTickets for help on using
tickets.
https://core.trac.wordpress.org/ticket/62067