Undefined array key “before_widget” / “after_widget” (PHP 8)
-
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
$argsis passed without the standard sidebar keysbefore_widgetandafter_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 258The code does:
echo $args['before_widget']; // ... echo $args['after_widget'];If
$argsdoes 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- Use WordPress with PHP 8.x and SiteOrigin Widgets Bundle.
- 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$argsarray). - Load the page or view that renders the widget.
- 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
$argsis passed withoutbefore_widget/after_widget. - No other plugins were disabled for this report; the fix was verified locally by adding
?? ''as above.
You must be logged in to reply to this topic.