• Bug report: PHP 8.1+: plugin_basename() / wp_normalize_path() receive null when Sugar Calendar registers its admin menu

    Environment

    • 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 2196

    These originate in WordPress core (wp_is_stream() and wp_normalize_path()), but they are reached through Sugar Calendar’s admin menu registration path — specifically Sugar_Calendar\Admin\Area->admin_menu() calling add_submenu_page() with a $menu_slug / file path argument that is null.

    We identified the caller by installing a narrow diagnostic error handler (Tierheim_MU_Deprecation_Tracer) which, when triggered by those specific deprecations from wp-includes/functions.php:7374 or :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_pathplugin_basenameadd_submenu_pageSugar_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 null into add_submenu_page() for at least one menu slot, which propagates through plugin_basename() → wp_normalize_path() → str_replace(null) and wp_is_stream() → strpos(null).

    Reproduction

    1. WordPress 6.9.x on PHP 8.1 or later (we observed on 8.4.20).
    2. Activate Sugar Calendar (Lite) v3.11.0.
    3. Enable WP_DEBUG + WP_DEBUG_LOG.
    4. Visit any /wp-admin/ page.
    5. Tail wp-content/debug.log — two deprecation entries per request.

    Suggested fix

    Inside Sugar_Calendar\Admin\Area::admin_menu(), review every add_submenu_page() call and ensure the $menu_slug argument 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_slug becomes null (likely a conditional branch that returns early without assigning a slug) and assign a sensible default or skip the add_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.

Viewing 1 replies (of 1 total)
  • Plugin Author Michael

    (@donmhico)

    @jyria – Thank you so much and we appreciate your detailed report! We will include the fix in our next release.

    Michael Panaga
    Sugar Calendar Lead Developer

Viewing 1 replies (of 1 total)

You must be logged in to reply to this topic.