Open
Bootstrap Advanced Custom Fields integration via the plugin integration pipeline#4
Conversation
Copilot
AI
changed the title
[WIP] Add proper bootstrapping for Advanced Custom Fields integration
Bootstrap Advanced Custom Fields integration via the plugin integration pipeline
May 21, 2026
huubl
marked this pull request as ready for review
May 21, 2026 15:07
huubl
force-pushed
the
copilot/add-advanced-custom-fields-integration
branch
from
May 21, 2026 18:25
a29432e to
dca4d74
Compare
nlemoine
force-pushed
the
copilot/add-advanced-custom-fields-integration
branch
from
May 21, 2026 19:37
dca4d74 to
c6b9451
Compare
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
force-pushed
the
copilot/add-advanced-custom-fields-integration
branch
from
May 22, 2026 09:47
ca54380 to
8691c2b
Compare
There was a problem hiding this comment.
Pull request overview
This PR fixes unreachable Advanced Custom Fields (ACF) hook registration by converting the ACF integration from a side-effect file into a first-class IntegrationInterface implementation and wiring it into the existing integration bootstrap pipeline (plugin.php → Plugin::getIntegrations() → container resolution → isSupported()/registerHooks()).
Changes:
- Refactors the ACF integration into
AdvancedCustomFieldsimplementingIntegrationInterface, registeringacf/include_location_rulesviaregisterHooks()with an ACF field API version guard. - Adds the ACF integration to
Plugin::getIntegrations()and registers it inContainerfor consistent resolution. - Updates tests to assert the integration is included in the plugin integrations list and is resolvable from the container.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
src/Integration/AdvancedCustomFields/AdvancedCustomFields.php |
Converts ACF integration into an IntegrationInterface implementation and registers the ACF hook through the integration lifecycle. |
src/Plugin.php |
Adds the ACF integration to the plugin’s integration bootstrap list. |
src/Container.php |
Registers a factory for the ACF integration so it can be resolved consistently like other integrations. |
tests/Integration/PluginTest.php |
Asserts ACF integration is included in Plugin::getIntegrations(). |
tests/Unit/ContainerTest.php |
Asserts the container can resolve the ACF integration and reports it via has(). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The ACF location rule registration lived in a side-effect file that was never loaded by plugin bootstrap, so
acf/include_location_rulesregistration was unreachable. This change moves ACF into the same integration lifecycle used by the other third‑party integrations.ACF integration converted to first-class integration
src/Integration/AdvancedCustomFields/AdvancedCustomFields.phpinto anIntegrationInterfaceimplementation.isSupported()gate for ACF availability.registerHooks()to registeracf/include_location_rules.5.require_onceand relies on PSR-4 autoload forLocationPageType.Wired into plugin bootstrap
AdvancedCustomFields\AdvancedCustomFields::classtoPlugin::getIntegrations()so it is resolved and bootstrapped with other integrations.Container registration
Container.phpfor consistent integration resolution.Focused bootstrap coverage updates
Plugin::getIntegrations().Container.Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
repo.wp-packages.org/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/XFktcZ /usr/bin/composer install --no-interaction(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
Create a pull request in repository
huubl/page-for-custom-post-typeto properly bootstrap the Advanced Custom Fields integration.Context:
src/Integration/AdvancedCustomFields/AdvancedCustomFields.phpcurrently contains top-level hook registration code foracf/include_location_rules, but that file is never loaded by the plugin bootstrap.plugin.php->Plugin::getInstance()->init()-> iteratingPlugin::getIntegrations()and resolving each integration from the container.Plugin::getIntegrations()currently includes Polylang, WordPressSeo, Wpml, and Autodescription, but not AdvancedCustomFields.composer.jsononly autoloads classes undersrc/via PSR-4 andsrc/functions.phpviaautoload.files, so a side-effect file with top-leveladd_action(...)is not automatically loaded.acf/include_location_rulesexists, ACF is already loaded at the time this should register, and the callback parameter is the ACF field API version, not the plugin version.Required changes:
src/Integration/AdvancedCustomFields/AdvancedCustomFields.phpfrom a side-effect file into a proper integration class consistent with the repository architecture.IntegrationInterfacepattern used by other integrations.acf/include_location_ruleshook registration into aregisterHooks()method.isSupported()method appropriate for ACF availability.LocationPageTypeclass via autoload rather than manually requiring its file unless the repo architecture truly requires otherwise.Plugin::getIntegrations().Container.phpif needed for service resolution consistency.Implementation guidance:
src/Integration/*.Please create the pull request with code changes.
The following is the prior conversation context from the user's chat exploration (may be truncated):
User: Waarom wordt dit niet geladen?
Assistant: Waarschijnlijk omdat dit bestand zelf nooit wordt geïncludeerd — of omdat de hook te laat / in de verkeerde ACF-versiecontext draait.
In jouw snippet gebeurt alleen dit:
Dat registreert alleen een callback als dit PHP-bestand al uitgevoerd is. Als
AdvancedCustomFields.phpnergens wordtrequired/autoloaded, dan wordt dieadd_action()nooit geregistreerd.Daarnaast zie ik nog 3 plausibele oorzaken:
ACF hook vuurt niet met waarde 5
Je code stopt expliciet als
$acfMajorVersion !== 5. Dus bij ACF 6 of een andere waarde gebeurt er niets.De hooknaam kan niet meer kloppen voor jouw ACF-versie/use-case
Je gebruikt
acf/include_location_rules. Als ACF op jouw installatie custom location types anders verwacht te registreren, dan loopt dit stil voorbij.ACF is nog niet geladen wanneer dit bestand wordt ingelezen
Dan wordt de callback wel geregistreerd, maar alleen nuttig als ACF later die hook echt afvuurt.
Wat ik wél kan bevestigen uit de repo:
add_action(...); er zit geen class of bootstrap omheen. Dus het hangt volledig af van elders in de plugin dat dit bestand geladen wordt.LocationPageType.phpdefinieert correct een classLocationPageType extends ACF_Location_Page_Type, maar die file wordt pas geladen binnen de callback. Dus als de callback niet loopt, gebeurt er niets.acf_get_store('location-types')en$store->set(...), dus ook dat werkt alleen als ACF volledig beschikbaar is.De kernvraag is dus: wordt
src/Integration/AdvancedCustomFields/AdvancedCustomFields.phpüberhaupt ingeladen?Ik zou als eerste dit checken: