Skip to content

Conversation

@helgatheviking
Copy link
Contributor

Submission Review Guidelines:

Changes proposed in this Pull Request:

Move the legacy filters to the block's initialize method so that they actually are fired during block render.

Closes #61012.

How to test the changes in this Pull Request:

Use the MVE snippet from #61012

add_filter( 'render_block_woocommerce/add-to-cart-form', function( $content ) {
	$test = apply_filters( 'woocommerce_single_product_photoswipe_enabled', get_theme_support( 'wc-product-gallery-lightbox' ) ) ? 'photoswipe enabled' : 'photoswipe disabled';
	return '<p>' . $test . '</p>' . $content;
} );

Without PR you should see photoswipe disabled and with PR you should see photoswipe enabled just prior to the single product's add to cart form block.

@github-actions github-actions bot added plugin: woocommerce Issues related to the WooCommerce Core plugin. type: community contribution labels Sep 18, 2025
@kmanijak kmanijak self-requested a review September 25, 2025 12:13
@github-actions
Copy link
Contributor

Testing Guidelines

Hi ,

Apart from reviewing the code changes, please make sure to review the testing instructions (Guide) and verify that relevant tests (E2E, Unit, Integration, etc.) have been added or updated as needed.

Reminder: PR reviewers are required to document testing performed. This includes:

  • 🖼️ Screenshots or screen recordings.
  • 📝 List of functionality tested / steps followed.
  • 🌐 Site details (environment attributes such as hosting type, plugins, theme, store size, store age, and relevant settings).
  • 🔍 Any analysis performed, such as assessing potential impacts on environment attributes and other plugins, conducting performance profiling, or using LLM/AI-based analysis.

⚠️ Within the testing details you provide, please ensure that no sensitive information (such as API keys, passwords, user data, etc.) is included in this public issue.

Copy link
Contributor

@kmanijak kmanijak left a comment

Choose a reason for hiding this comment

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

Hi @helgatheviking, thanks for contribution and fixing this issue!

Current place for filters is not good either as it returns false positives but I suggested an alternative 🙌

Comment on lines 23 to 33
protected function initialize() {
parent::initialize();
add_action(
'wp_footer',
function () {
wc_get_template( 'single-product/photoswipe.php' );
}
);
add_filter( 'woocommerce_single_product_zoom_enabled', '__return_true' );
add_filter( 'woocommerce_single_product_photoswipe_enabled', '__return_true' );
add_filter( 'woocommerce_single_product_flexslider_enabled', '__return_true' );
Copy link
Contributor

Choose a reason for hiding this comment

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

That's not a good place either since it block doesn't even have to rendered and filters would return true:

image

I believe they should be moved to render function after initial checks if block can be rendered here

With Product Image Gallery Without Product Image Gallery
image image

Do you see any downsides of moving it there?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kmanijak Hi Karol! :wave Specifically I am trying to piggy back in Mix and Match on whether photoswipe is enabled. your suggestion looks like it should work. I'll commit it.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 25, 2025

📝 Walkthrough

Walkthrough

Moves enabling of legacy gallery filters (zoom, PhotoSwipe, flexslider) from asset-enqueue time into block render time and adds a patch changelog entry documenting that legacy gallery filters are available during block rendering.

Changes

Cohort / File(s) Summary
Changelog entry
plugins/woocommerce/changelog/issues-61012-legacy-filters
Adds a patch-level changelog entry noting legacy gallery filters are available during block rendering.
ProductImageGallery block
plugins/woocommerce/src/Blocks/BlockTypes/ProductImageGallery.php
Removes registering legacy gallery filters/hooks from enqueue_legacy_assets(); moves add_filter calls (enable zoom, PhotoSwipe, flexslider) into render() and registers the PhotoSwipe footer template hook around render output generation.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant U as Frontend Request
  participant B as ProductImageGallery Block
  participant H as WP Hooks
  participant T as PhotoSwipe Template

  U->>B: render() called
  activate B
  B->>H: add_action('wp_footer', render PhotoSwipe template)
  B->>B: add_filter(enable zoom)
  B->>B: add_filter(enable photoswipe)
  B->>B: add_filter(enable flexslider)
  B-->>U: return sale badge + gallery markup
  deactivate B

  H-->>T: wp_footer triggers PhotoSwipe template
  T-->>U: PhotoSwipe markup output
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Title Check ✅ Passed The title clearly summarizes the primary change of moving filter registrations to block initialization and references the related issue without unnecessary noise, making it easy to understand the main purpose of the PR.
Linked Issues Check ✅ Passed The patch relocates the legacy gallery filter registrations into the block’s initialization/render phase ensuring that zoom, Photoswipe, and flexslider filters are active during block rendering as specified in issue #61012, fulfilling the coding requirement.
Out of Scope Changes Check ✅ Passed All changes are confined to moving the filter registration within the ProductImageGallery block and updating the changelog, which directly align with the core objective and introduce no unrelated modifications.
Description Check ✅ Passed The provided description clearly outlines the change to move legacy filters to the block’s initialize method, references the linked issue, and includes relevant testing instructions, making it directly related to the changeset.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@kmanijak kmanijak left a comment

Choose a reason for hiding this comment

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

It tests well now for me but let's just make a cleanup and remove unnecessary changes with action moved to initialize 🙌

Once done, I'm happy to approve!

Comment on lines 25 to 30
add_action(
'wp_footer',
function () {
wc_get_template( 'single-product/photoswipe.php' );
}
);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this can be moved to the previous place.

Copy link
Contributor Author

@helgatheviking helgatheviking Sep 26, 2025

Choose a reason for hiding this comment

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

You mean to the render callback? So we wouldn't need initialize() at all anymore

Copy link
Contributor

Choose a reason for hiding this comment

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

I meant enqueue_legacy_assets so we have all the enqueueing in a single function (as it was on trunk).

So we wouldn't need initialize() at all anymore

Yass!

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
plugins/woocommerce/src/Blocks/BlockTypes/ProductImageGallery.php (1)

95-97: Guard gallery filter registrations and confirm lifetime

  • ProductImageGallery.php (95–97) and ClassicTemplate.php (123–125) both unconditionally call add_filter for the same hooks. Wrap these in has_filter(…, '__return_true') checks or extract into a shared init so each filter is added only once per request.
  • Verify that these filters should persist for the remainder of the request; if not, pair each add_filter with a matching remove_filter immediately after the block’s output.
📜 Review details

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c48a2dc and dc1b403.

📒 Files selected for processing (1)
  • plugins/woocommerce/src/Blocks/BlockTypes/ProductImageGallery.php (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{php,js,jsx,ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/code-quality.mdc)

**/*.{php,js,jsx,ts,tsx}: Guard against unexpected inputs
Sanitize and validate any potentially dangerous inputs
Ensure code is backwards compatible
Write code that is readable and intuitive
Ensure code has unit or E2E tests where applicable

Files:

  • plugins/woocommerce/src/Blocks/BlockTypes/ProductImageGallery.php
**/*.{php,js,ts,jsx,tsx}

⚙️ CodeRabbit configuration file

**/*.{php,js,ts,jsx,tsx}: Don't trust that extension developers will follow the best practices, make sure the code:

  • Guards against unexpected inputs.
  • Sanitizes and validates any potentially dangerous inputs.
  • Is backwards compatible.
  • Is readable and intuitive.
  • Has unit or E2E tests where applicable.

Files:

  • plugins/woocommerce/src/Blocks/BlockTypes/ProductImageGallery.php

Copy link
Contributor

@kmanijak kmanijak left a comment

Choose a reason for hiding this comment

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

Thanks for addressing my feedback and for fixing the issue in the first place! 🙌

@kmanijak kmanijak enabled auto-merge (squash) September 26, 2025 17:38
@kmanijak kmanijak disabled auto-merge September 26, 2025 17:39
@kmanijak kmanijak merged commit e1434c7 into woocommerce:trunk Sep 26, 2025
37 checks passed
@github-actions github-actions bot added this to the 10.3.0 milestone Sep 26, 2025
@kmanijak
Copy link
Contributor

Setting the milestone to 10.2, as we would like to backport it to a patch release.

Incorrect filter placement causes issues with Product Image Gallery block image sizes #61138 and this PR fixes the issue.

@kmanijak kmanijak modified the milestones: 10.3.0, 10.2.0 Sep 29, 2025
github-actions bot pushed a commit that referenced this pull request Sep 29, 2025
* Move add_filter calls to block initialize(). Closes #61012.

* move legacy gallery filters into render()

* Finish moving add_action() to render() as well.

* Revert add_action() back to original place in enqueue_legacy_assets()

---------

Co-authored-by: Karol Manijak <20098064+kmanijak@users.noreply.github.com>
@woocommercebot
Copy link
Collaborator

IMPORTANT: Merging this PR to the appropriate branches is critical to the release process and ensures that the bug does not cause regressions in the future releases.

Cherry picking was successful for release/10.2. Please merge the following PR: [Backport to release/10.2] Move add_filter calls to block initialize(). Closes #61012.

kmanijak added a commit that referenced this pull request Sep 29, 2025
Closes #61012. (#61173)

Move add_filter calls to block initialize(). Closes #61012. (#61013)

* Move add_filter calls to block initialize(). Closes #61012.

* move legacy gallery filters into render()

* Finish moving add_action() to render() as well.

* Revert add_action() back to original place in enqueue_legacy_assets()

---------

Co-authored-by: Kathy <507025+helgatheviking@users.noreply.github.com>
Co-authored-by: Karol Manijak <20098064+kmanijak@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

plugin: woocommerce Issues related to the WooCommerce Core plugin. type: community contribution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ProductImageGallery block woocommerce_single_product_zoom_enabled filters not true inside blocks

3 participants