ACF Support
If Advanced Custom Fields (ACF) is active on your WordPress site, the OC Magento Bridge plugin automatically detects it and injects ACF field data into the WordPress REST API responses for posts and pages.
How It Works
Section titled “How It Works”When ACF is active, the OC_Bridge_ACF_Support class hooks into the WordPress REST API response filter. For every post or page included in a REST response, it:
- Calls
get_fields($post_id)to retrieve all ACF fields for that post - Sanitizes the field values (strips script tags, removes event handlers)
- Injects the sanitized fields into the REST response under the
acfkey
REST Response Structure
Section titled “REST Response Structure”With ACF support active, post objects in REST responses include an acf property:
{ "id": 42, "title": { "rendered": "My Post Title" }, "content": { "rendered": "<p>Post content...</p>" }, "acf": { "hero_image_url": "https://blog.example.com/wp-content/uploads/hero.jpg", "promo_text": "Special offer this week", "show_banner": true, "related_product_sku": "WH01-XS-Gray" }}Accessing ACF Fields in Magento
Section titled “Accessing ACF Fields in Magento”ACF field data is available via the Post data model’s getAcfFields() method (or through the raw API response array). In templates:
$acfFields = $post->getAcfFields();$promoText = $acfFields['promo_text'] ?? '';Supported Field Types
Section titled “Supported Field Types”All standard ACF field types that return serializable values are supported, including text, textarea, number, email, URL, image (returns URL), select, checkbox, true/false, and relationship fields.
Complex nested fields (flexible content, repeater) are included as nested arrays.
Sanitization
Section titled “Sanitization”ACF field values pass through basic sanitization before being injected into the response:
<script>and<style>tags are removedon*event attributes are removedjavascript:protocol in URL fields is replaced with#