From 761ef884ac2dfe47981b1d3663bfd51afa40aac5 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 16 Aug 2026 14:26:11 +0000 Subject: [PATCH 1/2] Use spl_object_id() instead of spl_object_hash() in the router PHP 8.6 deprecates spl_object_hash() in favour of spl_object_id(). Mirror the current _wp_filter_build_unique_id() implementation from core and drop the wp_filter_id fallback, which only existed for PHP versions that predate SPL. Also note in the docblock why this cannot simply call WP_CLI::add_wp_hook(): router.php is executed by PHP's built-in web server in a separate process, where neither WordPress nor WP-CLI is loaded. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_017jAUxp4R7zvrd6hpgp6eW6 --- router.php | 38 +++++++++++--------------------------- 1 file changed, 11 insertions(+), 27 deletions(-) diff --git a/router.php b/router.php index 0124c33..029109a 100644 --- a/router.php +++ b/router.php @@ -25,49 +25,33 @@ function add_filter( $tag, $function_to_add, $priority = 10, $accepted_args = 1 /** * This is a copy of WordPress's _wp_filter_build_unique_id() function. * - * We duplicate it because WordPress is not loaded yet. + * We duplicate it because WordPress is not loaded yet. It cannot use + * `WP_CLI::add_wp_hook()` either, as this file is executed by PHP's built-in + * web server in a separate process where WP-CLI is not loaded. */ function _wp_filter_build_unique_id( $tag, $callback, $priority ) { - global $wp_filter; - static $filter_id_count = 0; - if ( is_string( $callback ) ) { return $callback; } if ( is_object( $callback ) ) { // Closures are currently implemented as objects - $callback = array( $callback, '' ); - } else { - $callback = (array) $callback; + return (string) spl_object_id( $callback ); + } + + if ( ! isset( $callback[1] ) || ! is_string( $callback[1] ) ) { + return null; } if ( is_object( $callback[0] ) ) { // Object Class Calling - if ( function_exists( 'spl_object_hash' ) ) { - return spl_object_hash( $callback[0] ) . $callback[1]; - } else { - $obj_idx = get_class( $callback[0] ) . $callback[1]; - if ( ! isset( $callback[0]->wp_filter_id ) ) { - if ( false === $priority ) { - return false; - } - $obj_idx .= isset( $wp_filter[ $tag ][ $priority ] ) - ? count( (array) $wp_filter[ $tag ][ $priority ] ) - : $filter_id_count; - - $callback[0]->wp_filter_id = $filter_id_count; - ++$filter_id_count; - } else { - $obj_idx .= $callback[0]->wp_filter_id; - } - - return $obj_idx; - } + return ( (string) spl_object_id( $callback[0] ) ) . $callback[1]; } elseif ( is_string( $callback[0] ) ) { // Static Calling return $callback[0] . '::' . $callback[1]; } + + return null; } function _get_full_host( $url ) { From 1f7f6bd17d7c0059c08f5d3daf4ac08be4838457 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 16 Aug 2026 14:30:23 +0000 Subject: [PATCH 2/2] Silence unused-parameter warning for $priority Dropping the wp_filter_id fallback left $priority unused, which trips Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed. Keep the parameter so the signature still matches core's _wp_filter_build_unique_id(), and annotate it the way the rest of the codebase does. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_017jAUxp4R7zvrd6hpgp6eW6 --- router.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/router.php b/router.php index 029109a..2db7738 100644 --- a/router.php +++ b/router.php @@ -29,7 +29,7 @@ function add_filter( $tag, $function_to_add, $priority = 10, $accepted_args = 1 * `WP_CLI::add_wp_hook()` either, as this file is executed by PHP's built-in * web server in a separate process where WP-CLI is not loaded. */ -function _wp_filter_build_unique_id( $tag, $callback, $priority ) { +function _wp_filter_build_unique_id( $tag, $callback, $priority ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed -- $priority retained to match core's _wp_filter_build_unique_id() signature. if ( is_string( $callback ) ) { return $callback; }