Fix undefined variable $cat_checked and $tags_checked#132
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes PHP warnings in the Sailthru WP admin metabox (and hardens meta tag generation) by ensuring variables and image URLs are only referenced when defined/available.
Changes:
- Initialize
$tags_checked/$cat_checkedtofalseinrender_metabox()to prevent undefined variable warnings when the relevant option is unset. - Guard access to
wp_get_attachment_image_src()return values ingenerate_meta_tags()to avoid undefined index warnings when image data is missing.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
classes/class-sailthru-meta-box.php |
Initializes checkbox state variables to avoid undefined-variable warnings in admin metabox rendering. |
classes/class-sailthru-content.php |
Adds defensive checks before reading [0] from attachment image source arrays during meta tag generation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
aabcd19 to
cd3ca74
Compare
Initialize both variables to false before the conditional block so they are always defined when referenced later in the method. Simplify redundant conditionals for $image and $thumb checks using !empty() instead of checking the variable and then isset on the index. Remove double-escaping of sailthru.image.full value, as esc_attr() is already applied in the output loop. Fixes sailthru#131
cd3ca74 to
2d93c5c
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' ); | ||
| $thumb = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'concierge-thumb' ); | ||
|
|
||
| $post_image = $image[0]; | ||
| $horizon_tags['sailthru.image.full'] = esc_attr( $post_image ); | ||
| $post_thumbnail = $thumb[0]; | ||
| $horizon_tags['sailthru.image.thumb'] = $post_thumbnail; | ||
| if ( ! empty( $image[0] ) ) { | ||
| $post_image = $image[0]; | ||
| $horizon_tags['sailthru.image.full'] = $post_image; | ||
| } | ||
|
|
||
| if ( ! empty( $thumb[0] ) ) { | ||
| $post_thumbnail = $thumb[0]; | ||
| $horizon_tags['sailthru.image.thumb'] = $post_thumbnail; | ||
| } |
There was a problem hiding this comment.
The PR title/description and linked issue focus on initializing $tags_checked/$cat_checked, but this PR also changes meta tag generation for featured images. Please update the PR description/test plan to cover this additional behavior change, or split it into a separate PR so the scope matches the issue being fixed.
Summary
$tags_checkedand$cat_checkedtofalsebefore the conditional block inrender_metabox()so they are always defined when referenced laterFixes #131
Test plan
sailthru_interest_tag_optionsconfigured