Bug Report: PHP 8.1+: `plugin_basename()` / `wp_normalize_path()` receive null..
-
Bug report: PHP 8.1+:
plugin_basename()/wp_normalize_path()receive null when Sugar Calendar registers its admin menuEnvironment
- Plugin: Sugar Calendar (Lite) v3.11.0
- Also active: Sugar Calendar Gridview Add-On (custom, by Saskia Teichmann)
- WordPress: 6.9.x
- PHP: 8.4.20
- Webserver: nginx (WordOps)
Summary
On every backend request, the following two PHP deprecation warnings fire in series:
[PHP Deprecated] strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in wp-includes/functions.php on line 7374 [PHP Deprecated] str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in wp-includes/functions.php on line 2196These originate in WordPress core (
wp_is_stream()andwp_normalize_path()), but they are reached through Sugar Calendar’s admin menu registration path — specificallySugar_Calendar\Admin\Area->admin_menu()callingadd_submenu_page()with a$menu_slug/ file path argument that isnull.We identified the caller by installing a narrow diagnostic error handler (
Tierheim_MU_Deprecation_Tracer) which, when triggered by those specific deprecations fromwp-includes/functions.php:7374or:2196, attaches a backtrace.Captured backtrace (real, from our site)
strpos wp_is_stream wp_normalize_path plugin_basename add_submenu_page Sugar_Calendar\Admin\Area->admin_menu WP_Hook->apply_filters WP_Hook->do_action do_action('admin_menu') require_once('wp-admin/includes/menu.php') require('wp-admin/menu.php') require_once('wp-admin/admin.php')Same chain for
str_replace/wp_normalize_path→plugin_basename→add_submenu_page→Sugar_Calendar\Admin\Area->admin_menu.Expected vs. actual
- Expected:
add_submenu_page()receives a non-null$menu_slug(and, when it represents a filesystem path, a non-null path argument). - Actual: Sugar Calendar passes
nullintoadd_submenu_page()for at least one menu slot, which propagates throughplugin_basename() → wp_normalize_path() → str_replace(null)andwp_is_stream() → strpos(null).
Reproduction
- WordPress 6.9.x on PHP 8.1 or later (we observed on 8.4.20).
- Activate Sugar Calendar (Lite) v3.11.0.
- Enable
WP_DEBUG+WP_DEBUG_LOG. - Visit any
/wp-admin/page. - Tail
wp-content/debug.log— two deprecation entries per request.
Suggested fix
Inside
Sugar_Calendar\Admin\Area::admin_menu(), review everyadd_submenu_page()call and ensure the$menu_slugargument is always a non-null string. A minimal local fix is to coerce:add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, (string) $menu_slug, // was sometimes null $function );A better fix is to track down where
$menu_slugbecomes null (likely a conditional branch that returns early without assigning a slug) and assign a sensible default or skip theadd_submenu_page()call entirely.Workaround in place
No workaround for this one – we only installed a diagnostic tracer that logs the backtrace once per unique signature, so we could identify the caller. The two deprecation messages still appear in our debug log (which is fine: we want them visible upstream).
The tracer will be removed after this ticket is acknowledged or the plugin is updated.
You must be logged in to reply to this topic.