File tree Expand file tree Collapse file tree
Integration/AdvancedCustomFields Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1010use n5s \PageForCustomPostType \Core \RewriteManager ;
1111use n5s \PageForCustomPostType \Frontend \Handler ;
1212use n5s \PageForCustomPostType \Frontend \QueryFilter ;
13+ use n5s \PageForCustomPostType \Integration \AdvancedCustomFields ;
1314use n5s \PageForCustomPostType \Integration \Autodescription ;
1415use n5s \PageForCustomPostType \Integration \Polylang ;
1516use n5s \PageForCustomPostType \Integration \WordPressSeo ;
@@ -141,6 +142,7 @@ public function __construct()
141142 ),
142143
143144 // Integration composites
145+ AdvancedCustomFields \AdvancedCustomFields::class => static fn (): AdvancedCustomFields \AdvancedCustomFields => new AdvancedCustomFields \AdvancedCustomFields (),
144146 Polylang \Polylang::class => fn (): Polylang \Polylang => new Polylang \Polylang (
145147 $ this ->get (Polylang \UrlTranslation::class),
146148 $ this ->get (Polylang \Translation::class),
Original file line number Diff line number Diff line change 44
55namespace n5s \PageForCustomPostType \Integration \AdvancedCustomFields ;
66
7- add_action ('acf/include_location_rules ' , static function (int $ acfMajorVersion ): void {
8- if ($ acfMajorVersion !== 5 ) {
9- return ;
7+ use n5s \PageForCustomPostType \Integration \IntegrationInterface ;
8+
9+ /**
10+ * Advanced Custom Fields integration composite.
11+ *
12+ * Registers a custom location type that exposes `<cpt>_page` values on the
13+ * `page_type` rule, so field groups can target PFCPT-bound pages.
14+ */
15+ final class AdvancedCustomFields implements IntegrationInterface
16+ {
17+ public function isSupported (): bool
18+ {
19+ return \class_exists ('ACF_Location_Page_Type ' );
20+ }
21+
22+ public function registerHooks (): void
23+ {
24+ add_action ('acf/include_location_rules ' , [$ this , 'registerLocationRules ' ]);
1025 }
1126
12- require_once __DIR__ . '/LocationPageType.php ' ;
27+ public function registerLocationRules (int $ acfFieldApiVersion ): void
28+ {
29+ if ($ acfFieldApiVersion !== 5 ) {
30+ return ;
31+ }
1332
14- $ store = acf_get_store ('location-types ' );
15- $ locationType = new LocationPageType ();
16- $ store ->set ($ locationType ->name , $ locationType );
17- });
33+ $ store = acf_get_store ('location-types ' );
34+ $ locationType = new LocationPageType ();
35+ $ store ->set ($ locationType ->name , $ locationType );
36+ }
37+ }
Original file line number Diff line number Diff line change 99use n5s \PageForCustomPostType \Core \RewriteManager ;
1010use n5s \PageForCustomPostType \Frontend \Handler ;
1111use n5s \PageForCustomPostType \Frontend \QueryFilter ;
12+ use n5s \PageForCustomPostType \Integration \AdvancedCustomFields ;
1213use n5s \PageForCustomPostType \Integration \Autodescription ;
1314use n5s \PageForCustomPostType \Integration \IntegrationInterface ;
1415use n5s \PageForCustomPostType \Integration \Polylang ;
@@ -184,6 +185,7 @@ public function onTemplateRedirect(): void
184185 public function getIntegrations (): array
185186 {
186187 return [
188+ AdvancedCustomFields \AdvancedCustomFields::class,
187189 Polylang \Polylang::class,
188190 WordPressSeo \WordPressSeo::class,
189191 Wpml \Wpml::class,
Original file line number Diff line number Diff line change 77use n5s \PageForCustomPostType \Container ;
88use n5s \PageForCustomPostType \Core \Api ;
99use n5s \PageForCustomPostType \Core \RewriteManager ;
10+ use n5s \PageForCustomPostType \Integration \AdvancedCustomFields \AdvancedCustomFields ;
1011use n5s \PageForCustomPostType \Integration \IntegrationInterface ;
1112use n5s \PageForCustomPostType \Plugin ;
1213use n5s \PageForCustomPostType \Tests \Fixtures \TestCase ;
@@ -62,6 +63,7 @@ public function testGetIntegrationsReturnsArrayOfIntegrationClassStrings(): void
6263
6364 $ this ->assertIsArray ($ integrations );
6465 $ this ->assertNotEmpty ($ integrations );
66+ $ this ->assertContains (AdvancedCustomFields::class, $ integrations );
6567
6668 foreach ($ integrations as $ integration ) {
6769 $ this ->assertIsString ($ integration );
Original file line number Diff line number Diff line change 88use n5s \PageForCustomPostType \Container ;
99use n5s \PageForCustomPostType \Core \Api ;
1010use n5s \PageForCustomPostType \Core \RewriteManager ;
11+ use n5s \PageForCustomPostType \Integration \AdvancedCustomFields \AdvancedCustomFields ;
1112use n5s \PageForCustomPostType \Tests \Fixtures \TestCase ;
1213
1314class ContainerTest extends TestCase
@@ -27,6 +28,13 @@ public function testGetReturnsCorrectTypeForApi(): void
2728 $ this ->assertInstanceOf (Api::class, $ service );
2829 }
2930
31+ public function testGetReturnsCorrectTypeForAdvancedCustomFieldsIntegration (): void
32+ {
33+ $ service = $ this ->container ->get (AdvancedCustomFields::class);
34+
35+ $ this ->assertInstanceOf (AdvancedCustomFields::class, $ service );
36+ }
37+
3038 public function testGetReturnsSameInstanceOnRepeatedCalls (): void
3139 {
3240 $ first = $ this ->container ->get (Api::class);
@@ -39,6 +47,7 @@ public function testHasReturnsTrueForKnownServices(): void
3947 {
4048 $ this ->assertTrue ($ this ->container ->has (Api::class));
4149 $ this ->assertTrue ($ this ->container ->has (RewriteManager::class));
50+ $ this ->assertTrue ($ this ->container ->has (AdvancedCustomFields::class));
4251 }
4352
4453 public function testHasReturnsFalseForUnknownServices (): void
You can’t perform that action at this time.
0 commit comments