• Resolved tonisbramanis

    (@tonisbramanis)


    Undefined array key “before_widget” and “after_widget” in siteorigin-widget.class.php (PHP 8)

    Description

    When a widget from the Widgets Bundle is rendered in a context where $args is passed without the standard sidebar keys before_widget and after_widget, PHP 8 triggers:

    Error: Undefined array key "before_widget" (and similarly "after_widget")

    File: so-widgets-bundle/base/siteorigin-widget.class.php
    Lines: 250 and 258

    The code does:

    echo $args['before_widget'];
    // ...
    echo $args['after_widget'];

    If $args does not contain these keys (e.g. when the widget is used outside a classic sidebar or with a theme/block that omits them), the array access causes the notice.Steps to reproduce

    1. Use WordPress with PHP 8.x and SiteOrigin Widgets Bundle.
    2. Render a Widgets Bundle widget in a context where the caller does not pass $args['before_widget'] and $args['after_widget'] (e.g. custom widget area that omits these, or a block/template that calls the widget with a minimal $args array).
    3. Load the page or view that renders the widget.
    4. Observe the PHP notice (or enable error logging and check the log).

    Expected vs actual

    • Expected: Widget outputs without PHP notices; missing wrapper markup is handled safely.
    • Actual: PHP throws “Undefined array key ‘before_widget'” (and ‘after_widget’) when those keys are not present in $args.

    Suggested fix

    Use the null coalescing operator so missing keys do not trigger a notice:

    echo $args['before_widget'] ?? '';
    // ...
    echo $args['after_widget'] ?? '';

    This keeps backward compatibility: when the keys exist, behavior is unchanged; when they are missing, nothing is echoed.Version information

    • WordPress: [e.g. 6.4.x]
    • PHP: 8.x
    • SiteOrigin Widgets Bundle: 1.71.0 (or the version where the issue was seen)
    • Active theme: [theme name and version]

    Environment / notes

    • The plugin is otherwise working; the issue appears only when $args is passed without before_widget/after_widget.
    • No other plugins were disabled for this report; the fix was verified locally by adding ?? '' as above.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)

You must be logged in to reply to this topic.