Skip to content

defensively checking for a missing widget_id#2923

Open
masteradhoc wants to merge 1 commit intoAutomattic:trunkfrom
masteradhoc:widget-id-array-key
Open

defensively checking for a missing widget_id#2923
masteradhoc wants to merge 1 commit intoAutomattic:trunkfrom
masteradhoc:widget-id-array-key

Conversation

@masteradhoc
Copy link
Contributor

Fixes #2910

Changes Proposed in this Pull Request

  • Added an empty() guard on $args['widget_id'] in WP_Job_Manager_Widget::get_cached_widget() and cache_widget() to prevent PHP 8+ undefined array key warnings.
  • When widget_id is absent, get_cached_widget() returns false (cache miss) and cache_widget() returns early — both fall back gracefully to normal widget rendering without caching.

Testing Instructions

  1. Ensure a PHP 8.0+ environment with error reporting set to E_ALL.
  2. Add a WP Job Manager widget (e.g. Recent Jobs or Featured Jobs) to a sidebar via Appearance → Widgets.
  3. Load a frontend page that displays the widget.
  4. Confirm no undefined array key "widget_id" PHP warnings appear in the error log or on screen.
  5. Confirm the widget renders correctly with caching intact under normal conditions (i.e. $args['widget_id'] is present as expected in a standard WordPress widget context).

Release Notes

  • Fixed PHP 8+ undefined array key warning in the widget caching methods.

New or Updated Hooks and Templates

None.

Deprecated Code

None.

Screenshot / Video

N/A — no visual change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PHP Warning: Undefined array key "widget_id"

1 participant