Make WordPress Core


Ignore:
Timestamp:
05/22/2026 06:59:15 AM (6 months ago)
Author:
westonruter
Message:

Plugins: Improve hook performance by using spl_object_id() instead of spl_object_hash() to construct unique IDs.

  • Also use spl_object_id() similarly when registering and unregistering classic widgets.
  • Improve typing and phpdoc in _wp_filter_build_unique_id(). Return null for malformed callbacks.
  • Add tests for _wp_filter_build_unique_id().
  • Improve type safety of WP_Hook::add_filter() in case an invalid callback is provided for parity with ::has_filter() and ::remove_filter().

Developed in ​https://github.com/WordPress/wordpress-develop/pull/11865
Follow-up to r46220, r46801, r60179.

Props bor0, westonruter, SergeyBiryukov, schlessera, arshidkv12, knutsp, spacedmonkey, swissspidy.
See #64898.
Fixes #58291.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-hook.php

    r61457 r62408  
    8686
    8787                $idx = _wp_filter_build_unique_id( $hook_name, $callback, $priority );
     88                if ( null === $idx ) {
     89                        return;
     90                }
    8891
    8992                $priority_existed = isset( $this->callbacks[ $priority ] );
Note: See TracChangeset for help on using the changeset viewer.