Skip to content

Fix undefined variable $cat_checked and $tags_checked#132

Open
enescala wants to merge 2 commits into
sailthru:masterfrom
enescala:fix/undefined-variable-cat-checked
Open

Fix undefined variable $cat_checked and $tags_checked#132
enescala wants to merge 2 commits into
sailthru:masterfrom
enescala:fix/undefined-variable-cat-checked

Conversation

@enescala

Copy link
Copy Markdown

Summary

  • Initialize $tags_checked and $cat_checked to false before the conditional block in render_metabox() so they are always defined when referenced later

Fixes #131

Test plan

  • Open a post in wp-admin without sailthru_interest_tag_options configured
  • Verify no PHP warning about undefined variables
  • Verify interest tag info still displays correctly when the option is configured

Copilot AI review requested due to automatic review settings March 11, 2026 08:25

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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_checked to false in render_metabox() to prevent undefined variable warnings when the relevant option is unset.
  • Guard access to wp_get_attachment_image_src() return values in generate_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.

Comment thread classes/class-sailthru-content.php Outdated
@enescala
enescala force-pushed the fix/undefined-variable-cat-checked branch from aabcd19 to cd3ca74 Compare March 11, 2026 08:28
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
Copilot AI review requested due to automatic review settings March 11, 2026 08:29
@enescala
enescala force-pushed the fix/undefined-variable-cat-checked branch from cd3ca74 to 2d93c5c Compare March 11, 2026 08:29

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Comment on lines 440 to +451
$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;
}

Copilot AI Mar 11, 2026

Copy link

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
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.

Undefined variable $cat_checked in class-sailthru-meta-box.php

2 participants