Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-undefined-context-key.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@headstartwp/headstartwp": patch
---

Fix: Add null coalescing check for context parameter in extend_post_content to prevent PHP 8+ "Undefined array key" warning. Fixes #940
2 changes: 1 addition & 1 deletion wp/headless-wp/includes/classes/Integrations/Gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function extend_post_content( \WP_REST_Response $data, \WP_Post $post, \W

$params = $request->get_params();

if ( 'view' !== $params['context'] ) {
if ( 'view' !== ( $params['context'] ?? '' ) ) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default fallback value mismatches WordPress context default

Medium Severity

When the context key is absent from $params, the fallback defaults to '' instead of 'view'. WordPress's standard default for context in REST API endpoints is 'view', so a missing key semantically means context=view. With ?? '', the check 'view' !== '' evaluates to true and the method returns early, skipping block styles — the opposite of what happens when context is explicitly 'view'. Using ?? 'view' as the fallback would correctly match WordPress's intended default and ensure block styles are added for requests that omit the context parameter.

Fix in Cursor Fix in Web

return $data;
}

Expand Down
Loading