Skip to content

Bootstrap Advanced Custom Fields integration via the plugin integration pipeline - #4

Open
huubl with Copilot wants to merge 6 commits into
mainfrom
copilot/add-advanced-custom-fields-integration
Open

Bootstrap Advanced Custom Fields integration via the plugin integration pipeline#4
huubl with Copilot wants to merge 6 commits into
mainfrom
copilot/add-advanced-custom-fields-integration

Conversation

Copilot AI commented May 21, 2026

Copy link
Copy Markdown

The ACF location rule registration lived in a side-effect file that was never loaded by plugin bootstrap, so acf/include_location_rules registration 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

    • Refactored src/Integration/AdvancedCustomFields/AdvancedCustomFields.php into an IntegrationInterface implementation.
    • Added:
      • isSupported() gate for ACF availability.
      • registerHooks() to register acf/include_location_rules.
      • Version guard to execute registration only for ACF field API version 5.
    • Removed manual require_once and relies on PSR-4 autoload for LocationPageType.
  • Wired into plugin bootstrap

    • Added AdvancedCustomFields\AdvancedCustomFields::class to Plugin::getIntegrations() so it is resolved and bootstrapped with other integrations.
  • Container registration

    • Added ACF integration service factory in Container.php for consistent integration resolution.
  • Focused bootstrap coverage updates

    • Updated integration/container tests to assert:
      • ACF integration is included in Plugin::getIntegrations().
      • ACF integration is registered and resolvable from Container.
final class AdvancedCustomFields implements IntegrationInterface
{
    public function isSupported(): bool
    {
        return \function_exists('acf_get_store');
    }

    public function registerHooks(): void
    {
        add_action('acf/include_location_rules', [$this, 'registerLocationRules']);
    }

    public function registerLocationRules(int $acfFieldApiVersion): void
    {
        if ($acfFieldApiVersion !== 5) {
            return;
        }

        $store = acf_get_store('location-types');
        $locationType = new LocationPageType();
        $store->set($locationType->name, $locationType);
    }
}

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
    • Triggering command: /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-type to properly bootstrap the Advanced Custom Fields integration.

Context:

  • The file src/Integration/AdvancedCustomFields/AdvancedCustomFields.php currently contains top-level hook registration code for acf/include_location_rules, but that file is never loaded by the plugin bootstrap.
  • The plugin bootstraps integrations via plugin.php -> Plugin::getInstance()->init() -> iterating Plugin::getIntegrations() and resolving each integration from the container.
  • Plugin::getIntegrations() currently includes Polylang, WordPressSeo, Wpml, and Autodescription, but not AdvancedCustomFields.
  • composer.json only autoloads classes under src/ via PSR-4 and src/functions.php via autoload.files, so a side-effect file with top-level add_action(...) is not automatically loaded.
  • The hook acf/include_location_rules exists, 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:

  1. Refactor src/Integration/AdvancedCustomFields/AdvancedCustomFields.php from a side-effect file into a proper integration class consistent with the repository architecture.
  2. Make it implement the repo's IntegrationInterface pattern used by other integrations.
  3. Move the acf/include_location_rules hook registration into a registerHooks() method.
  4. Add an isSupported() method appropriate for ACF availability.
  5. Ensure the location rule registration still only runs for field API version 5.
  6. Use the existing LocationPageType class via autoload rather than manually requiring its file unless the repo architecture truly requires otherwise.
  7. Wire the integration into the plugin bootstrap by adding it to Plugin::getIntegrations().
  8. Register it in Container.php if needed for service resolution consistency.
  9. Update or add tests if appropriate to cover the integration bootstrap behavior.

Implementation guidance:

  • Follow the style and conventions already used by the other integrations in src/Integration/*.
  • Keep the change minimal and architecture-consistent.
  • Avoid unrelated refactors.
  • The PR should explain that the root cause was that the ACF integration file was never loaded, leaving the custom location rule registration unreachable.

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:

add_action('acf/include_location_rules', static function (int $acfMajorVersion): void {
    if ($acfMajorVersion !== 5) {
        return;
    }

    require_once __DIR__ . '/LocationPageType.php';

    $store = acf_get_store('location-types');
    $locationType = new LocationPageType();
    $store->set($locationType->name, $locationType);
});

Dat registreert alleen een callback als dit PHP-bestand al uitgevoerd is. Als AdvancedCustomFields.php nergens wordt required/autoloaded, dan wordt die add_action() nooit geregistreerd.

Daarnaast zie ik nog 3 plausibele oorzaken:

  1. 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.

  2. 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.

  3. 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:

  • Het bestand bevat alleen top-level 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.php definieert correct een class LocationPageType extends ACF_Location_Page_Type, maar die file wordt pas geladen binnen de callback. Dus als de callback niet loopt, gebeurt er niets.
  • De registratie gebeurt via 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:

error_log('AdvancedCustomFields.php loaded');
add_action('acf/include_location_rules', function ($v) {
    error_log('acf/include_location_...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

*This pull request was created from Copilot chat.*
>

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
Copilot finished work on behalf of huubl May 21, 2026 15:07
Copilot AI requested a review from huubl May 21, 2026 15:07
@huubl
huubl marked this pull request as ready for review May 21, 2026 15:07
@huubl
huubl force-pushed the copilot/add-advanced-custom-fields-integration branch from a29432e to dca4d74 Compare May 21, 2026 18:25
@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 Copilot May 22, 2026 09:48

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 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.phpPlugin::getIntegrations() → container resolution → isSupported()/registerHooks()).

Changes:

  • Refactors the ACF integration into AdvancedCustomFields implementing IntegrationInterface, registering acf/include_location_rules via registerHooks() with an ACF field API version guard.
  • Adds the ACF integration to Plugin::getIntegrations() and registers it in Container for 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.

huubl and others added 3 commits June 3, 2026 09:18
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.
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.

4 participants