Skip to content

fix: guard downloads assets without WooCommerce#34

Open
superdav42 wants to merge 1 commit into
mainfrom
fix/woocommerce-guard
Open

fix: guard downloads assets without WooCommerce#34
superdav42 wants to merge 1 commit into
mainfrom
fix/woocommerce-guard

Conversation

@superdav42

@superdav42 superdav42 commented Jun 28, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Short-circuit downloads-page asset enqueueing when WooCommerce's is_account_page() helper is unavailable.
  • Call the WooCommerce helper explicitly as \is_account_page() after the availability guard.
  • Add a regression check that loads Downloads_Page without WooCommerce helpers and verifies enqueue_assets() returns without fataling.

Verification

  • composer test
  • php -l inc/class-downloads-page.php
  • php -l tests/downloads-page-woocommerce-guard-regression.php

aidevops.sh v3.29.11 plugin for OpenCode v1.17.11 with gpt-5.5

Summary by CodeRabbit

  • Bug Fixes

    • Improved the downloads page so assets are only loaded when the required account-page check is available, preventing errors in environments where that check is missing.
  • Tests

    • Added regression coverage for the downloads page guard behavior.
    • Updated the test command to run the new regression check alongside the existing one.

@coderabbitai

coderabbitai Bot commented Jun 28, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Downloads_Page::enqueue_assets() gains a function_exists('is_account_page') guard before calling \is_account_page(). A new regression test verifies this guard via ReflectionClass without WooCommerce loaded. The test is added to the composer.json test script array.

Changes

WooCommerce Guard Fix

Layer / File(s) Summary
Guard fix and regression test
inc/class-downloads-page.php, tests/downloads-page-woocommerce-guard-regression.php, composer.json
enqueue_assets() now returns early when is_account_page does not exist; the new regression test confirms this via reflection-based instantiation without WooCommerce; composer.json registers the test in the script array.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐇 A function might vanish, oh what a fright,
But now we check first before taking a bite.
No WooCommerce? No problem, we skip right along,
A guard and a test to ensure nothing goes wrong.
Hippity-hop, the regression won't stay! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: guarding downloads asset loading when WooCommerce helpers are unavailable.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/woocommerce-guard

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 PHPStan (2.2.2)

PHPStan was skipped because the config uses disallowed bootstrapFiles, bootstrapFile, or includes directives.


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.

@coderabbitai coderabbitai Bot 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.

🧹 Nitpick comments (1)
composer.json (1)

25-28: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Prefer @php in Composer scripts.

Using @php keeps these tests on the same interpreter Composer is using and is more portable than hardcoding php.

Proposed change
         "test": [
-            "php tests/downloads-page-woocommerce-guard-regression.php",
-            "php tests/product-versions-remote-download-regression.php"
+            "`@php` tests/downloads-page-woocommerce-guard-regression.php",
+            "`@php` tests/product-versions-remote-download-regression.php"
         ]
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@composer.json` around lines 25 - 28, The Composer test script currently
hardcodes php, which can use a different interpreter than Composer itself.
Update the test entries in the scripts section of composer.json to invoke the
regression scripts through `@php` so they run with the same PHP binary Composer is
using; keep the existing test commands and only swap the executable reference in
the test script list.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@composer.json`:
- Around line 25-28: The Composer test script currently hardcodes php, which can
use a different interpreter than Composer itself. Update the test entries in the
scripts section of composer.json to invoke the regression scripts through `@php`
so they run with the same PHP binary Composer is using; keep the existing test
commands and only swap the executable reference in the test script list.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fe0f2653-710d-480c-8960-1a8b032dd7d6

📥 Commits

Reviewing files that changed from the base of the PR and between c9364a3 and b274041.

📒 Files selected for processing (3)
  • composer.json
  • inc/class-downloads-page.php
  • tests/downloads-page-woocommerce-guard-regression.php

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.

1 participant