Skip to content

Added a fix for the lightbox#762

Open
CrochetFeve0251 wants to merge 6 commits into
developfrom
bug/758-fix-lightbox
Open

Added a fix for the lightbox#762
CrochetFeve0251 wants to merge 6 commits into
developfrom
bug/758-fix-lightbox

Conversation

@CrochetFeve0251

Copy link
Copy Markdown
Contributor

Description

Added a fix for the lightbox by not passing the wp attributes to the picture tag.

Fixes #758

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality).
  • Bug fix (non-breaking change which fixes an issue).
  • Enhancement (non-breaking change which improves an existing functionality).
  • Breaking change (fix or feature that would cause existing functionality to not work as before).
  • This change requires a documentation update.

Is the solution different from the one proposed during the grooming?

No.

Checklists

Generic development checklist

  • My code follows the style guidelines of this project, with adapted comments and without new warnings.
  • I have added unit and integration tests that prove my fix is effective or that my feature works.
  • The CI passes locally with my changes (including unit tests, integration tests, linter).
  • Any dependent changes have been merged and published in downstream modules.
  • If applicable, I have made corresponding changes to the documentation. Provide a link to the documentation.

Test summary

  • I triggered all changed lines of code at least once without new errors/warnings/notices.
  • I validated all Acceptance Criteria of the related issues. (If applicable, provide proof).
  • I validated all test plan the QA Review asked me to.

If not, detail what you could not test.

Please describe any additional tests you performed.

@CrochetFeve0251 CrochetFeve0251 self-assigned this Nov 22, 2023
@CrochetFeve0251
CrochetFeve0251 requested a review from a team November 22, 2023 11:07
Comment thread classes/Picture/Display.php Outdated
@vmanthos
vmanthos self-requested a review November 23, 2023 10:03
@vmanthos

Copy link
Copy Markdown
Contributor

@CrochetFeve0251 Thank you for the PR.

The issue has been fixed but there is a console error that's not there with trunk:

Uncaught TypeError: Cannot read properties of null (reading 'focus')

image

This can be seen here:
https://vasilis.rocketlabsqa.ovh/wordpress-6-4-lightbox-implementation

  1. Click on the jellyfish picture.
  2. Close the lightbox using the x button or the picture itself.
  3. Check the console log.

Can you please check this? 🙏

@Mai-Saad

Mai-Saad commented Jan 6, 2026

Copy link
Copy Markdown
Contributor

@remyperona Thanks for the update.
is it expected to load both next-gen and normal image when click on the image? /cc @piotrbak
Screenshot from 2026-01-06 18-05-15

@remyperona

Copy link
Copy Markdown
Contributor

It's not expected, but this WP feature is also not planned to work with picture element I think. I would say it's an acceptable side effect compared to the current issue.

@Mai-Saad

Mai-Saad commented Jan 8, 2026

Copy link
Copy Markdown
Contributor

Items for exploratory

  • same issue is working fine with avif
  • same issue is working fine with normal optimized image served as picture
  • serve webp image is still good on both apache and nginx
  • serve webp image as picture is good with WPR (with /without webp option at wpr) and lightbox is still good
  • is there any other feature like lightbox to be explored?

@nicomollet
nicomollet requested review from Copilot and removed request for vmanthos January 8, 2026 16:14

@nicomollet nicomollet left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It looks good but needs proper QA

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

This pull request fixes a lightbox issue by preventing WordPress-specific data-wp attributes from being passed to the <picture> tag element. The fix filters out attributes with keys containing 'data-wp' before building the picture tag HTML, while still preserving these attributes on the inner <img> tag where they may be needed.

Key changes:

  • Added filtering logic using array_filter to remove data-wp* attributes from picture tag
  • Maintains backward compatibility by only affecting the picture tag, not the img tag

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

$picture_attributes = array_filter(
$attributes,
function ( $attribute ) {
return strpos( $attribute, 'data-wp' ) === false;

Copilot AI Jan 8, 2026

Copy link

Choose a reason for hiding this comment

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

The current check using strpos($attribute, 'data-wp') === false will filter out any attribute containing 'data-wp' anywhere in the key name, not just those starting with 'data-wp'. For more precise filtering of WordPress-specific attributes, consider using strpos($attribute, 'data-wp-') !== 0 or strncmp($attribute, 'data-wp-', 8) !== 0 to ensure only attributes that start with 'data-wp-' are filtered out. This prevents accidentally filtering attributes that may contain 'data-wp' in other positions.

Suggested change
return strpos( $attribute, 'data-wp' ) === false;
return strncmp( $attribute, 'data-wp-', 8 ) !== 0;

Copilot uses AI. Check for mistakes.
Comment on lines +221 to +227
$picture_attributes = array_filter(
$attributes,
function ( $attribute ) {
return strpos( $attribute, 'data-wp' ) === false;
},
ARRAY_FILTER_USE_KEY
);

Copilot AI Jan 8, 2026

Copy link

Choose a reason for hiding this comment

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

Consider adding an inline comment above the array_filter call to explain why data-wp attributes are being filtered out from the picture tag. This would help future maintainers understand the purpose of this filtering, especially in relation to the lightbox fix mentioned in issue #758.

Copilot uses AI. Check for mistakes.
@codacy-production

codacy-production Bot commented Jul 13, 2026

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 duplication

Metric Results
Duplication 0

View in Codacy

🟢 Coverage 100.00% diff coverage

Metric Results
Coverage variation Report missing for 3fb41021
Diff coverage 100.00% diff coverage (50.00%)

View coverage diff in Codacy

Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (3fb4102) Report Missing Report Missing Report Missing
Head commit (4ea5bf0) 19540 663 3.39%

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#762) 8 8 100.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

1 Codacy didn't receive coverage data for the commit, or there was an error processing the received data. Check your integration for errors and validate that your coverage setup is correct.

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

Covers the lightbox fix (#758): data-wp-* directive attributes must be
excluded from the <picture> tag while remaining on the inner <img> tag,
without breaking the existing Gutenberg cover-background exclusion logic.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compatibility issue after WordPress 6.4 with the new lightbox functionality

7 participants