Skip to content

fix(acf): bootstrap Advanced Custom Fields integration - #16

Merged
nlemoine merged 6 commits into
nlemoine:mainfrom
huubl:copilot/add-advanced-custom-fields-integration
Jun 3, 2026
Merged

fix(acf): bootstrap Advanced Custom Fields integration#16
nlemoine merged 6 commits into
nlemoine:mainfrom
huubl:copilot/add-advanced-custom-fields-integration

Conversation

@huubl

@huubl huubl commented May 21, 2026

Copy link
Copy Markdown
Contributor

AdvancedCustomFields.php was procedural top-level add_action code; the file was never loaded because Composer PSR-4 only autoloads class files and it is not listed in autoload.files. As a result the ACF location type was never registered.

@nlemoine
nlemoine self-requested a review May 21, 2026 19:14

@nlemoine nlemoine left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Good catch! thanks for that PR @huubl.

One thing I'd change, maybe use ACF direct API for this: acf_register_location_type, it includes some checks and also fires a acf/registered_location_type we're skipping when using the underlying logic.

@nlemoine
nlemoine force-pushed the copilot/add-advanced-custom-fields-integration branch from dca4d74 to c6b9451 Compare May 21, 2026 19:37
huubl added 3 commits May 22, 2026 11:47
AdvancedCustomFields.php was procedural top-level add_action code; the
file was never loaded because Composer PSR-4 only autoloads class files
and it is not listed in autoload.files. As a result the ACF location
type was never registered and `page_type == <cpt>_page` rules always
evaluated to false on ACF Pro 6.x.

Refactor the file into a class-based integration consistent with the
existing Polylang/WordPressSeo/Wpml/Autodescription composites:

- Implement IntegrationInterface with isSupported() + registerHooks().
- Guard isSupported() on class_exists('ACF_Location_Page_Type') so the
  hook is only registered when ACF Pro's parent class is loaded.
- Register the integration in Container as a service factory.
- Add it to Plugin::getIntegrations() so plugin.php bootstraps it.
- Extend PluginTest and ContainerTest to cover the new integration.
ACF_Location_Page_Type class is loaded later during ACF’s init flow. Since this plugin checks integrations on plugins_loaded, the ACF integration will never register its acf/include_location_rules hook
@huubl
huubl force-pushed the copilot/add-advanced-custom-fields-integration branch from ca54380 to 8691c2b Compare May 22, 2026 09:47
@huubl
huubl requested a review from nlemoine May 22, 2026 09:47
Comment thread src/Integration/AdvancedCustomFields/AdvancedCustomFields.php Outdated
Extend ACF's built-in page_type location rule with <cpt>_page values
using the documented acf/location/rule_values/type=page_type and
acf/location/match_rule/type=page_type filters, instead of removing and
re-registering ACF's native location type.

This augments core behavior without mutating ACF's location store or
subclassing internal ACF classes, so it stays compatible across ACF
updates. Api is injected via the container and the integration is wired
into Plugin::getIntegrations() so it bootstraps with the others.

Removes the LocationPageType subclass. Adds integration tests for both
filters plus PluginTest/ContainerTest coverage, registers ACF in the
test bootstrap, and adds a test:advanced-custom-fields composer script.
@codecov-commenter

codecov-commenter commented Jun 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.86%. Comparing base (38b984c) to head (2bbf6c7).

Additional details and impacted files
@@             Coverage Diff              @@
##               main      #16      +/-   ##
============================================
+ Coverage     76.47%   79.86%   +3.39%     
+ Complexity      500      494       -6     
============================================
  Files            32       31       -1     
  Lines          1356     1336      -20     
============================================
+ Hits           1037     1067      +30     
+ Misses          319      269      -50     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

nlemoine added 2 commits June 3, 2026 10:32
isSupported(), registerHooks() and the constructor otherwise run during the test bootstrap, before coverage collection starts, so they never register as covered. Instantiate the integration directly to exercise them, mirroring PolylangTest and WpmlTest.

Also cover the two remaining match_rule branches: a screen pointing at a non-existent post, and a rule value that matches no bound post type. This brings AdvancedCustomFields to full line coverage.
The coverage job ran a per-plugin step for Polylang, WPML, WordPress SEO and AutoDescription but not Advanced Custom Fields, so the ACF integration never appeared in coverage reports. The integration-tests matrix also omitted ACF and WPML, so neither suite gated pull requests.

Add the ACF coverage step and add test:advanced-custom-fields and test:wpml to the integration-tests matrix.

@nlemoine nlemoine left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

It's all good for me, thank you @huubl!

I just added a few more tests to cover more cases.

@nlemoine
nlemoine merged commit 4f35d8d into nlemoine:main Jun 3, 2026
33 checks passed
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.

3 participants